Bug 572790 - "ASSERTION: hasResult is false but the call succeeded?" during test_placesTitleNoUpdate.js. r=ehsan
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 17 Jun 2010 21:46:18 +0200
changeset 43729 022ee56081c13fb6632f03ec6f78c9c70dcd3889
parent 43728 70230bd69c0b1c37432aeffdf5391cd7c4722fec
child 43730 7657b6ee181ace3cf67da3c2613d32eaf9cc2c57
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersehsan
bugs572790
milestone1.9.3a6pre
Bug 572790 - "ASSERTION: hasResult is false but the call succeeded?" during test_placesTitleNoUpdate.js. r=ehsan
browser/components/privatebrowsing/test/unit/do_test_placesTitleNoUpdate.js
--- a/browser/components/privatebrowsing/test/unit/do_test_placesTitleNoUpdate.js
+++ b/browser/components/privatebrowsing/test/unit/do_test_placesTitleNoUpdate.js
@@ -32,50 +32,63 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 // 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();
-
-  bhist.addPageWithDetails(TEST_URI, TITLE_1, Date.now() * 1000);
-  do_check_eq(histsvc.getPageTitle(TEST_URI), TITLE_1);
+  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);
 
-  pb.privateBrowsingEnabled = true;
+    pb.privateBrowsingEnabled = true;
 
-  bhist.addPageWithDetails(TEST_URI, TITLE_2, Date.now() * 2000);
-  do_check_eq(histsvc.getPageTitle(TEST_URI), TITLE_1);
+    PlacesUtils.bhistory.addPageWithDetails(TEST_URI, TITLE_2, Date.now() * 2000);
+    do_check_eq(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_1);
 
-  pb.privateBrowsingEnabled = false;
+    pb.privateBrowsingEnabled = false;
 
-  do_check_eq(histsvc.getPageTitle(TEST_URI), TITLE_1);
+    do_check_eq(PlacesUtils.history.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();
+}