Bug 1113178 - Replace removeAllPages() in browser/base/content/test/general/ r=mak

This commit is contained in:
Tim Taubert
2015-01-16 20:44:30 +01:00
parent 66ac769ea6
commit 670c3f45c1
13 changed files with 30 additions and 113 deletions

View File

@@ -26,7 +26,7 @@ add_task(function* () {
gBrowser.removeTab(tab);
} catch(ex) { /* tab may have already been closed in case of failure */ }
return promiseClearHistory();
return PlacesTestUtils.clearHistory();
});
yield promiseAutocompleteResultPopup("open a search");

View File

@@ -26,7 +26,7 @@ add_task(function* () {
gBrowser.removeTab(tab);
} catch(ex) { /* tab may have already been closed in case of failure */ }
return promiseClearHistory();
return PlacesTestUtils.clearHistory();
});
yield promiseAutocompleteResultPopup("moz open a search");

View File

@@ -15,7 +15,7 @@ add_task(function*() {
return;
}
registerCleanupFunction(promiseClearHistory);
registerCleanupFunction(() => PlacesTestUtils.clearHistory());
let visits = [];
repeat(10, i => {

View File

@@ -15,7 +15,7 @@ add_task(function*() {
return;
}
registerCleanupFunction(promiseClearHistory);
registerCleanupFunction(() => PlacesTestUtils.clearHistory());
let visits = [];
repeat(10, i => {

View File

@@ -66,5 +66,5 @@ add_task(function* test_switchtab_override() {
EventUtils.synthesizeKey("VK_SHIFT" , { type: "keyup" });
yield deferred.promise;
yield promiseClearHistory();
yield PlacesTestUtils.clearHistory();
});

View File

@@ -18,7 +18,7 @@ add_task(function* test_switchtab_override_keynav() {
gBrowser.removeTab(tab);
gBrowser.removeTab(secondTab);
} catch(ex) { /* tabs may have already been closed in case of failure */ }
return promiseClearHistory();
return PlacesTestUtils.clearHistory();
});
gURLBar.focus();

View File

@@ -70,22 +70,6 @@ function onPanelShown(aEvent) {
}
}
/**
* Clears history invoking callback when done.
*/
function waitForClearHistory(aCallback)
{
let observer = {
observe: function(aSubject, aTopic, aData)
{
Services.obs.removeObserver(this, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
aCallback(aSubject, aTopic, aData);
}
};
Services.obs.addObserver(observer, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);
PlacesUtils.bhistory.removeAllPages();
}
function onPanelHidden(aEvent) {
if (aEvent.target == StarUI.panel) {
StarUI.panel.removeEventListener("popuphidden", arguments.callee, false);
@@ -96,7 +80,7 @@ function onPanelHidden(aEvent) {
is(BookmarkingUI.status, BookmarkingUI.STATUS_UNSTARRED,
"star button indicates that the bookmark has been removed");
gBrowser.removeCurrentTab();
waitForClearHistory(finish);
PlacesTestUtils.clearHistory().then(finish);
});
}
}

View File

@@ -976,40 +976,32 @@ function formNameExists(name)
* Removes all history visits, downloads, and form entries.
*/
function blankSlate() {
PlacesUtils.bhistory.removeAllPages();
// The promise is resolved only when removing both downloads and form history are done.
let deferred = Promise.defer();
let formHistoryDone = false, downloadsDone = false;
Task.spawn(function deleteAllDownloads() {
let deleteDownloads = Task.spawn(function* deleteAllDownloads() {
let publicList = yield Downloads.getList(Downloads.PUBLIC);
let downloads = yield publicList.getAll();
for (let download of downloads) {
yield publicList.remove(download);
yield download.finalize(true);
}
downloadsDone = true;
if (formHistoryDone) {
deferred.resolve();
}
}).then(null, Components.utils.reportError);
FormHistory.update({ op: "remove" },
{ handleError: function (error) {
do_throw("Error occurred updating form history: " + error);
deferred.reject(error);
},
handleCompletion: function (reason) {
if (!reason) {
formHistoryDone = true;
if (downloadsDone) {
deferred.resolve();
}
}
}
});
return deferred.promise;
let updateFormHistory = new Promise((resolve, reject) => {
FormHistory.update({op: "remove"}, {
handleCompletion(reason) {
if (!reason) {
resolve();
}
},
handleError(error) {
do_throw("Error occurred updating form history: " + error);
reject(error);
}
});
});
return Promise.all([
PlacesTestUtils.clearHistory(), deleteDownloads, updateFormHistory]);
}
/**

View File

@@ -72,7 +72,7 @@ registerCleanupFunction(() => {
Services.prefs.clearUserPref(gRestyleSearchesPref);
Services.search.currentEngine = gOriginalEngine;
Services.search.removeEngine(gEngine);
return promiseClearHistory();
return PlacesTestUtils.clearHistory();
});
add_task(function*() {

View File

@@ -150,8 +150,7 @@ function nextStep() {
gBrowser.removeCurrentTab();
}
waitForClearHistory(finish);
PlacesTestUtils.clearHistory().then(finish);
return;
}
@@ -184,22 +183,6 @@ function ensure_opentabs_match_db(aCallback) {
checkAutocompleteResults(tabs, aCallback);
}
/**
* Clears history invoking callback when done.
*/
function waitForClearHistory(aCallback) {
const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
let observer = {
observe: function(aSubject, aTopic, aData) {
Services.obs.removeObserver(this, TOPIC_EXPIRATION_FINISHED);
aCallback();
}
};
Services.obs.addObserver(observer, TOPIC_EXPIRATION_FINISHED, false);
PlacesUtils.bhistory.removeAllPages();
}
function checkAutocompleteResults(aExpected, aCallback)
{
gController.input = {

View File

@@ -61,20 +61,12 @@ function continue_test() {
EventUtils.synthesizeKey("VK_DOWN", {});
is(gURLBar.textValue, "www.autofilltrimurl.com/whatever", "trim was applied correctly");
gURLBar.closePopup();
waitForClearHistory(finish);
PlacesTestUtils.clearHistory().then(finish);
});
});
});
}
function waitForClearHistory(aCallback) {
Services.obs.addObserver(function observeCH(aSubject, aTopic, aData) {
Services.obs.removeObserver(observeCH, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
aCallback();
}, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);
PlacesUtils.bhistory.removeAllPages();
}
let gOnSearchComplete = null;
function waitForSearchComplete(aCallback) {
info("Waiting for onSearchComplete");

View File

@@ -16,9 +16,9 @@ function is_selected(index) {
}
add_task(function*() {
registerCleanupFunction(promiseClearHistory);
registerCleanupFunction(() => PlacesTestUtils.clearHistory());
yield promiseClearHistory();
yield PlacesTestUtils.clearHistory();
let tabCount = gBrowser.tabs.length;
let visits = [];

View File

@@ -383,40 +383,6 @@ function promiseHistoryClearedState(aURIs, aShouldBeCleared) {
return deferred.promise;
}
/**
* Allows waiting for an observer notification once.
*
* @param topic
* Notification topic to observe.
*
* @return {Promise}
* @resolves The array [subject, data] from the observed notification.
* @rejects Never.
*/
function promiseTopicObserved(topic)
{
let deferred = Promise.defer();
info("Waiting for observer topic " + topic);
Services.obs.addObserver(function PTO_observe(subject, topic, data) {
Services.obs.removeObserver(PTO_observe, topic);
deferred.resolve([subject, data]);
}, topic, 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);
PlacesUtils.bhistory.removeAllPages();
return promise;
}
/**
* Waits for the next top-level document load in the current browser. The URI
* of the document is compared against aExpectedURL. The load is then stopped