Bug 572790 - "ASSERTION: hasResult is false but the call succeeded?" during test_placesTitleNoUpdate.js. r=ehsan

This commit is contained in:
Marco Bonardo 2010-06-17 21:46:18 +02:00
parent 6cbb15516e
commit 456e8cff9c

View File

@ -37,45 +37,58 @@
// Test to make sure that the visited page titles do not get updated inside the
// private browsing mode.
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
function do_test()
{
let pb = Cc[PRIVATEBROWSING_CONTRACT_ID].
getService(Ci.nsIPrivateBrowsingService);
let histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
let bhist = histsvc.QueryInterface(Ci.nsIBrowserHistory);
const TEST_URI = uri("http://mozilla.com/privatebrowsing");
const TITLE_1 = "Title 1";
const TITLE_2 = "Title 2";
bhist.removeAllPages();
do_test_pending();
waitForClearHistory(function() {
PlacesUtils.bhistory.addPageWithDetails(TEST_URI, TITLE_1, Date.now() * 1000);
do_check_eq(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_1);
bhist.addPageWithDetails(TEST_URI, TITLE_1, Date.now() * 1000);
do_check_eq(histsvc.getPageTitle(TEST_URI), TITLE_1);
pb.privateBrowsingEnabled = true;
pb.privateBrowsingEnabled = true;
PlacesUtils.bhistory.addPageWithDetails(TEST_URI, TITLE_2, Date.now() * 2000);
do_check_eq(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_1);
bhist.addPageWithDetails(TEST_URI, TITLE_2, Date.now() * 2000);
do_check_eq(histsvc.getPageTitle(TEST_URI), TITLE_1);
pb.privateBrowsingEnabled = false;
pb.privateBrowsingEnabled = false;
do_check_eq(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_1);
do_check_eq(histsvc.getPageTitle(TEST_URI), TITLE_1);
pb.privateBrowsingEnabled = true;
pb.privateBrowsingEnabled = true;
PlacesUtils.bhistory.setPageTitle(TEST_URI, TITLE_2);
do_check_eq(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_1);
bhist.setPageTitle(TEST_URI, TITLE_2);
do_check_eq(histsvc.getPageTitle(TEST_URI), TITLE_1);
pb.privateBrowsingEnabled = false;
pb.privateBrowsingEnabled = false;
do_check_eq(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_1);
do_check_eq(histsvc.getPageTitle(TEST_URI), TITLE_1);
bhist.removeAllPages();
waitForClearHistory(do_test_finished);
});
}
// Support running tests on both the service itself and its wrapper
function run_test() {
run_test_on_all_services();
}
function waitForClearHistory(aCallback) {
let observer = {
observe: function(aSubject, aTopic, aData) {
Services.obs.removeObserver(this, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
aCallback();
}
};
Services.obs.addObserver(observer, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);
PlacesUtils.bhistory.removeAllPages();
}