Bug 1113178 - Replace removeAllPages() in toolkit/components/jsdownloads/ r=mak

This commit is contained in:
Tim Taubert 2015-01-17 19:05:31 +01:00
parent e3390bc60c
commit 89e989abde
3 changed files with 7 additions and 42 deletions

View File

@ -2116,7 +2116,7 @@ add_task(function test_history()
mustInterruptResponses();
// We will wait for the visit to be notified during the download.
yield promiseClearHistory();
yield PlacesTestUtils.clearHistory();
let promiseVisit = promiseWaitForVisit(httpUrl("interruptible.txt"));
// Start a download that is not allowed to finish yet.
@ -2128,7 +2128,7 @@ add_task(function test_history()
do_check_eq(transitionType, Ci.nsINavHistoryService.TRANSITION_DOWNLOAD);
// Restart and complete the download after clearing history.
yield promiseClearHistory();
yield PlacesTestUtils.clearHistory();
download.cancel();
continueResponses();
yield download.start();
@ -2144,7 +2144,7 @@ add_task(function test_history()
add_task(function test_history_tryToKeepPartialData()
{
// We will wait for the visit to be notified during the download.
yield promiseClearHistory();
yield PlacesTestUtils.clearHistory();
let promiseVisit =
promiseWaitForVisit(httpUrl("interruptible_resumable.txt"));

View File

@ -31,6 +31,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "HttpServer",
"resource://testing-common/httpd.js");
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
"resource://gre/modules/NetUtil.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
"resource://testing-common/PlacesTestUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
@ -169,43 +171,6 @@ function promiseTimeout(aTime)
return deferred.promise;
}
/**
* Allows waiting for an observer notification once.
*
* @param aTopic
* Notification topic to observe.
*
* @return {Promise}
* @resolves The array [aSubject, aData] from the observed notification.
* @rejects Never.
*/
function promiseTopicObserved(aTopic)
{
let deferred = Promise.defer();
Services.obs.addObserver(
function PTO_observe(aSubject, aTopic, aData) {
Services.obs.removeObserver(PTO_observe, aTopic);
deferred.resolve([aSubject, aData]);
}, aTopic, false);
return deferred.promise;
}
/**
* Clears history asynchronously.
*
* @return {Promise}
* @resolves When history has been cleared.
* @rejects Never.
*/
function promiseClearHistory()
{
let promise = promiseTopicObserved(PlacesUtils.TOPIC_EXPIRATION_FINISHED);
do_execute_soon(function() PlacesUtils.bhistory.removeAllPages());
return promise;
}
/**
* Waits for a new history visit to be notified for the specified URI.
*

View File

@ -353,7 +353,7 @@ add_task(function test_history_expiration()
// We must replace the visits added while executing the downloads with visits
// that are older than 7 days, otherwise they will not be expired.
yield promiseClearHistory();
yield PlacesTestUtils.clearHistory();
yield promiseExpirableDownloadVisit();
yield promiseExpirableDownloadVisit(httpUrl("interruptible.txt"));
@ -396,7 +396,7 @@ add_task(function test_history_clear()
yield downloadOne.start();
yield downloadTwo.start();
yield promiseClearHistory();
yield PlacesTestUtils.clearHistory();
// Wait for the removal notifications that may still be pending.
yield deferred.promise;