Bug 1113178 - Replace removeAllPages() in browser/components/places/tests/ r=mak

This commit is contained in:
Tim Taubert 2015-01-17 19:14:42 +01:00
Родитель 12b50e7601
Коммит 12e53991fb
15 изменённых файлов: 33 добавлений и 120 удалений

Просмотреть файл

@ -57,7 +57,7 @@ function onClipboardReady() {
is(tags.length, 0, "tags are gone");
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
waitForClearHistory(finish);
PlacesTestUtils.clearHistory().then(finish);
}
let tests = {

Просмотреть файл

@ -474,8 +474,7 @@ gTests.push({
},
cleanup: function() {
var bh = PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory);
bh.removeAllPages();
return PlacesTestUtils.clearHistory();
}
});
@ -498,10 +497,11 @@ function test() {
function runNextTest() {
// Cleanup from previous test.
if (gCurrentTest) {
gCurrentTest.cleanup();
info("End of test: " + gCurrentTest.desc);
gCurrentTest = null;
waitForAsyncUpdates(runNextTest);
Promise.resolve(gCurrentTest.cleanup()).then(() => {
info("End of test: " + gCurrentTest.desc);
gCurrentTest = null;
waitForAsyncUpdates(runNextTest);
});
return;
}

Просмотреть файл

@ -20,7 +20,7 @@ function test() {
testForgetThisSiteVisibility(1, function() {
testForgetThisSiteVisibility(2, function() {
// Cleanup
waitForClearHistory(finish);
PlacesTestUtils.clearHistory().then(finish);
});
});
});

Просмотреть файл

@ -31,7 +31,7 @@ function test() {
waitForExplicitFinish();
// Cleanup.
waitForClearHistory(continue_test);
PlacesTestUtils.clearHistory().then(continue_test);
}
function continue_test() {
@ -64,7 +64,7 @@ function continue_test() {
// Cleanup.
toggleSidebar("viewHistorySidebar", false);
waitForClearHistory(finish);
PlacesTestUtils.clearHistory().then(finish);
});
}, true);
}

Просмотреть файл

@ -12,7 +12,7 @@ const TEST_URI = NetUtil.newURI("http://www.mozilla.org/");
registerCleanupFunction(function* () {
yield PlacesUtils.bookmarks.eraseEverything();
yield promiseClearHistory();
yield PlacesTestUtils.clearHistory();
});
add_task(function* test_date_container() {

Просмотреть файл

@ -52,7 +52,7 @@ function test() {
}
win.close();
waitForClearHistory(finish);
PlacesTestUtils.clearHistory().then(finish);
}
})
}

Просмотреть файл

@ -108,7 +108,7 @@ gTests.push({
menuNode.containerOpen = false;
waitForClearHistory(nextTest);
PlacesTestUtils.clearHistory().then(nextTest);
}
// add a visit to browser history
addVisits(

Просмотреть файл

@ -39,7 +39,7 @@ function test() {
// Close Library window.
organizer.close();
// Clean up history.
waitForClearHistory(finish);
PlacesTestUtils.clearHistory().then(finish);
}
waitForExplicitFinish();

Просмотреть файл

@ -157,7 +157,7 @@ function onLibraryAvailable() {
// Cleanup.
PlacesUtils.tagging.untagURI(PlacesUtils._uri(TEST_URL), ["dummyTag"]);
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
waitForClearHistory(finish);
PlacesTestUtils.clearHistory().then(finish);
}
///////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -68,7 +68,7 @@ function test() {
is(tree.selectedNode.itemId, -1, "The selected node is not bookmarked");
},
cleanup: function(aCallback) {
waitForClearHistory(aCallback);
PlacesTestUtils.clearHistory().then(aCallback);
},
sidebarName: HISTORY_SIDEBAR_ID,
treeName: HISTORY_SIDEBAR_TREE_ID,
@ -154,5 +154,5 @@ function test() {
}
// Ensure history is clean before starting the test.
waitForClearHistory(runNextTest);
PlacesTestUtils.clearHistory().then(runNextTest);
}

Просмотреть файл

@ -6,6 +6,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
"resource://gre/modules/NetUtil.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/Promise.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
"resource://testing-common/PlacesTestUtils.jsm");
// We need to cache this before test runs...
let cachedLeftPaneFolderIdGetter;
@ -73,21 +75,6 @@ function promiseClipboard(aPopulateClipboardFn, aFlavor) {
return deferred.promise;
}
/**
* Waits for completion of a clear history operation, before
* proceeding with aCallback.
*
* @param aCallback
* Function to be called when done.
*/
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();
}
/**
* Waits for all pending async statements on the default connection, before
* proceeding with aCallback.
@ -372,37 +359,3 @@ function promiseHistoryNotification(notification, conditionFn) {
}, 2000);
});
}
/**
* 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;
}
/**
* 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;
}

Просмотреть файл

@ -1,3 +1,11 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
"resource://testing-common/PlacesTestUtils.jsm");
/**
* Asynchronously adds visits to a page, invoking a callback function when done.
*
@ -53,17 +61,3 @@ function addVisits(aPlaceInfo, aCallback) {
}
);
}
/**
* Clears history invoking callback when done.
*/
function waitForClearHistory(aCallback) {
const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
Services.obs.addObserver(function observer(aSubject, aTopic, aData) {
Services.obs.removeObserver(observer, TOPIC_EXPIRATION_FINISHED);
aCallback();
}, TOPIC_EXPIRATION_FINISHED, false);
Cc["@mozilla.org/browser/nav-history-service;1"]
.getService(Ci.nsINavHistoryService)
.QueryInterface(Ci.nsIBrowserHistory).removeAllPages();
}

Просмотреть файл

@ -45,7 +45,7 @@
function runTest() {
// The mochitest page is added to history.
waitForClearHistory(continue_test);
PlacesTestUtils.clearHistory().then(continue_test);
}
function continue_test() {
@ -106,7 +106,7 @@
}
// Cleanup.
waitForClearHistory(SimpleTest.finish);
PlacesTestUtils.clearHistory().then(SimpleTest.finish);
});
});
}

Просмотреть файл

@ -48,7 +48,7 @@
function runTest() {
// The mochitest page is added to history.
waitForClearHistory(continue_test);
PlacesTestUtils.clearHistory().then(continue_test);
}
function continue_test() {
@ -72,26 +72,9 @@
ok(true, "No exceptions thrown");
// Cleanup.
waitForClearHistory(SimpleTest.finish);
PlacesTestUtils.clearHistory().then(SimpleTest.finish);
});
}
/**
* 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);
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
hs.QueryInterface(Ci.nsIBrowserHistory).removeAllPages();
}
]]></script>
</window>

Просмотреть файл

@ -54,7 +54,7 @@
function runTest() {
// The mochitest page is added to history.
waitForClearHistory(continue_test);
PlacesTestUtils.clearHistory().then(continue_test);
}
function continue_test() {
@ -148,7 +148,7 @@
}
// Cleanup.
bs.removeItem(itemId);
waitForClearHistory(SimpleTest.finish);
PlacesTestUtils.clearHistory().then(SimpleTest.finish);
}
// Add a visit 1ms before midnight, a visit at midnight, and
@ -166,23 +166,6 @@
addVisitsCallback);
}
/**
* 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);
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
hs.QueryInterface(Ci.nsIBrowserHistory).removeAllPages();
}
]]>
</script>
</window>