From 73634dc77420a7dfe18f7bef22eeeaaea2e4bdea Mon Sep 17 00:00:00 2001 From: Marco Bonardo Date: Thu, 17 Jun 2010 21:46:18 +0200 Subject: [PATCH] Bug 572790 - "ASSERTION: hasResult is false but the call succeeded?" during test_placesTitleNoUpdate.js. r=ehsan --- .../test/unit/do_test_placesTitleNoUpdate.js | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/browser/components/privatebrowsing/test/unit/do_test_placesTitleNoUpdate.js b/browser/components/privatebrowsing/test/unit/do_test_placesTitleNoUpdate.js index 6f503c1fce9..9ff334f0f46 100644 --- a/browser/components/privatebrowsing/test/unit/do_test_placesTitleNoUpdate.js +++ b/browser/components/privatebrowsing/test/unit/do_test_placesTitleNoUpdate.js @@ -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(); +}