Places chrome tests should wait for clear history.

This commit is contained in:
Marco Bonardo 2010-06-22 14:44:40 +02:00
parent 26deafd4c5
commit c23d3d5740
3 changed files with 75 additions and 18 deletions

View File

@ -45,13 +45,15 @@
SimpleTest.waitForExplicitFinish();
function runTest() {
// The mochitest page is added to history.
waitForClearHistory(continue_test);
}
function continue_test() {
const Cc = Components.classes;
const Ci = Components.interfaces;
Components.utils.import("resource://gre/modules/Services.jsm");
// Cleanup.
PlacesUtils.bhistory.removeAllPages();
// Add some visits.
let vtime = Date.now() * 1000;
const ttype = PlacesUtils.history.TRANSITION_TYPED;
@ -76,8 +78,13 @@
// loop through the rows and check formatting
let treeView = tree.view;
for (let i = 0; i < rc; i++) {
selection.select(rc);
let node = tree.selectedNode;
ok(true, "found " + node.title);
}
let rc = treeView.rowCount;
ok(rc == 3, "Rows found.");
is(rc, 3, "Rows found.");
let selection = treeView.selection;
for (let i = 0; i < rc; i++) {
selection.select(0);
@ -89,10 +96,25 @@
}
// Cleanup.
PlacesUtils.bhistory.removeAllPages();
SimpleTest.finish();
waitForClearHistory(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>

View File

@ -48,11 +48,14 @@
SimpleTest.waitForExplicitFinish();
function runTest() {
// The mochitest page is added to history.
waitForClearHistory(continue_test);
}
function continue_test() {
const Cc = Components.classes;
const Ci = Components.interfaces;
Components.utils.import("resource://gre/modules/Services.jsm");
PlacesUtils.bhistory.removeAllPages();
PlacesUtils.history
.addVisit(Services.io.newURI("http://example.tld/", null, null),
Date.now() * 1000, null, PlacesUtils.history.TRANSITION_TYPED, false, 0);
@ -73,10 +76,25 @@
ok(true, "No exceptions thrown");
// Cleanup.
PlacesUtils.bhistory.removeAllPages();
SimpleTest.finish();
waitForClearHistory(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>

View File

@ -86,6 +86,11 @@
SimpleTest.waitForExplicitFinish();
function runTest() {
// The mochitest page is added to history.
waitForClearHistory(continue_test);
}
function continue_test() {
const Cc = Components.classes;
const Ci = Components.interfaces;
@ -109,9 +114,6 @@
midnight.setSeconds(0);
midnight.setMilliseconds(0);
// Cleanup.
bh.removeAllPages();
// Add a visit 1ms before midnight.
hs.addVisit(uri("http://before.midnight.com/"),
(midnight.getTime() - 1) * 1000,
@ -196,11 +198,26 @@
}
// Cleanup.
bs.removeItem(itemId);
bh.removeAllPages();
SimpleTest.finish();
waitForClearHistory(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>