Bug 752218 - Replace usage of AddURI with updatePlaces. r=mak
authorRaymond Lee <raymond@raysquare.com>
Thu, 17 Jan 2013 10:28:26 +0800
changeset 119227 93794651309a89b0bb8ec6f7a9cfb72c970c4b14
parent 119226 75d9c44ed26750c62aec5d68656077458d60bac1
child 119228 49cfb1e213e65a24da6d121a9e9759bba4c58046
push id24195
push userMs2ger@gmail.com
push dateSat, 19 Jan 2013 16:10:11 +0000
treeherdermozilla-central@02e12a80aef9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs752218
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 752218 - Replace usage of AddURI with updatePlaces. r=mak
toolkit/components/places/tests/head_common.js
toolkit/components/places/tests/unit/test_420331_wyciwyg.js
toolkit/components/places/tests/unit/test_history.js
toolkit/components/places/tests/unit/test_isvisited.js
toolkit/components/places/tests/unit/test_markpageas.js
--- a/toolkit/components/places/tests/head_common.js
+++ b/toolkit/components/places/tests/head_common.js
@@ -948,8 +948,31 @@ function addVisits(aPlaceInfo, aCallback
   let stack = aStack || Components.stack.caller;
   promiseAddVisits(aPlaceInfo).then(
     aCallback,
     function addVisits_onFailure(ex) {
       do_throw(ex, stack);
     }
   );
 }
+
+/**
+ * Asynchronously check a url is visited.
+ *
+ * @param aURI
+ *        The URI.
+ *
+ * @return {Promise}
+ * @resolves When the check has been added successfully.
+ * @rejects JavaScript exception.
+ */
+function promiseIsURIVisited(aURI)
+{
+  let deferred = Promise.defer();
+  let history = Cc["@mozilla.org/browser/history;1"]
+                  .getService(Ci.mozIAsyncHistory);
+  history.isURIVisited(aURI, function(aURI, aIsVisited) {
+    deferred.resolve(aIsVisited);
+  });
+
+  return deferred.promise;
+}
+
--- a/toolkit/components/places/tests/unit/test_420331_wyciwyg.js
+++ b/toolkit/components/places/tests/unit/test_420331_wyciwyg.js
@@ -6,25 +6,18 @@
 
 function run_test()
 {
   run_next_test();
 }
 
 add_task(function test_execute()
 {
-  var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
-                getService(Ci.nsINavHistoryService);
   var testURI = uri("wyciwyg://nodontjudgeabookbyitscover");
 
   try
   {
     yield promiseAddVisits(testURI);
     do_throw("Should have generated an exception.");
   } catch (ex if ex && ex.result == Cr.NS_ERROR_ILLEGAL_VALUE) {
     // Adding wyciwyg URIs should raise NS_ERROR_ILLEGAL_VALUE.
   }
-
-  // test codepath of docshell caller
-  histsvc.QueryInterface(Ci.nsIGlobalHistory2);
-  placeID = histsvc.addURI(testURI, false, false, null);
-  do_check_false(placeID > 0);
 });
--- a/toolkit/components/places/tests/unit/test_history.js
+++ b/toolkit/components/places/tests/unit/test_history.js
@@ -2,18 +2,16 @@
 /* vim:set ts=2 sw=2 sts=2 et: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Get history services
 var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
               getService(Ci.nsINavHistoryService);
-var gh = histsvc.QueryInterface(Ci.nsIGlobalHistory2);
-var bh = histsvc.QueryInterface(Ci.nsIBrowserHistory);
 
 /**
  * Checks to see that a URI is in the database.
  *
  * @param aURI
  *        The URI to check.
  * @returns true if the URI is in the DB, false otherwise.
  */
--- a/toolkit/components/places/tests/unit/test_isvisited.js
+++ b/toolkit/components/places/tests/unit/test_isvisited.js
@@ -1,53 +1,44 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-// Get history service
-try {
-  var gh = Cc["@mozilla.org/browser/global-history;2"].
-           getService(Ci.nsIGlobalHistory2);
-} catch(ex) {
-  do_throw("Could not get the global history service\n");
-} 
-
-function add_uri_to_history(aURI, aCheckForGuid) {
-  var referrer = uri("about:blank");
-  gh.addURI(aURI,
-            false, // not redirect
-            true, // top level 
-            referrer);
-  if (aCheckForGuid === undefined) {
-    do_check_guid_for_uri(aURI);
-  }
+function run_test()
+{
+  run_next_test();
 }
 
-// main
-function run_test() {
+add_task(function test_execute()
+{
+  var referrer = uri("about:blank");
+
   // add a http:// uri 
   var uri1 = uri("http://mozilla.com");
-  add_uri_to_history(uri1);
-  do_check_true(gh.isVisited(uri1));
+  yield promiseAddVisits({uri: uri1, referrer: referrer});
+  do_check_guid_for_uri(uri1);
+  do_check_true(yield promiseIsURIVisited(uri1));
  
   // add a https:// uri
   var uri2 = uri("https://etrade.com");
-  add_uri_to_history(uri2);
-  do_check_true(gh.isVisited(uri2));
+  yield promiseAddVisits({uri: uri2, referrer: referrer});
+  do_check_guid_for_uri(uri2);
+  do_check_true(yield promiseIsURIVisited(uri2));
 
   // add a ftp:// uri
   var uri3 = uri("ftp://ftp.mozilla.org");
-  add_uri_to_history(uri3);
-  do_check_true(gh.isVisited(uri3));
+  yield promiseAddVisits({uri: uri3, referrer: referrer});
+  do_check_guid_for_uri(uri3);
+  do_check_true(yield promiseIsURIVisited(uri3));
 
   // check if a nonexistent uri is visited
   var uri4 = uri("http://foobarcheese.com");
-  do_check_false(gh.isVisited(uri4));
+  do_check_false(yield promiseIsURIVisited(uri4));
 
   // check that certain schemes never show up as visited
   // even if we attempt to add them to history
   // see CanAddURI() in nsNavHistory.cpp
   const URLS = [
     "about:config",
     "imap://cyrus.andrew.cmu.edu/archive.imap",
     "news://new.mozilla.org/mozilla.dev.apps.firefox",
@@ -55,24 +46,29 @@ function run_test() {
     "moz-anno:favicon:http://mozilla.org/made-up-favicon",
     "view-source:http://mozilla.org",
     "chrome://browser/content/browser.xul",
     "resource://gre-resources/hiddenWindow.html",
     "data:,Hello%2C%20World!",
     "wyciwyg:/0/http://mozilla.org",
     "javascript:alert('hello wolrd!');",
   ];
-  URLS.forEach(function(currentURL) {
+  for (let currentURL of URLS) {
     try {
       var cantAddUri = uri(currentURL);
     }
     catch(e) {
       // nsIIOService.newURI() can throw if e.g. our app knows about imap://
       // but the account is not set up and so the URL is invalid for us.
       // Note this in the log but ignore as it's not the subject of this test.
       do_log_info("Could not construct URI for '" + currentURL + "'; ignoring");
     }
     if (cantAddUri) {
-      add_uri_to_history(cantAddUri, false);
-      do_check_false(gh.isVisited(cantAddUri));
+      try {
+        yield promiseAddVisits({uri: cantAddUri, referrer: referrer});
+        do_throw("Should have generated an exception.");
+      } catch(ex if ex && ex.result == Cr.NS_ERROR_ILLEGAL_VALUE) {
+      }
+      do_check_false(yield promiseIsURIVisited(cantAddUri));
     }
-  });
-}
+  }
+});
+
--- a/toolkit/components/places/tests/unit/test_markpageas.js
+++ b/toolkit/components/places/tests/unit/test_markpageas.js
@@ -1,58 +1,50 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-// Get global history service
-try {
-  var gh = Cc["@mozilla.org/browser/global-history;2"].getService(Ci.nsIBrowserHistory);
-} catch(ex) {
-  do_throw("Could not get global history service\n");
-} 
-
 // Get history service
 try {
   var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
 } catch(ex) {
   do_throw("Could not get history service\n");
 } 
 
-function add_uri_to_history(aURI) {
-  gh.addURI(aURI,
-            false, // not redirect
-            true, // top level
-            null); // no referrer, so that we'll use the markPageAs hint
-}
-
 var gVisits = [{url: "http://www.mozilla.com/",
                 transition: histsvc.TRANSITION_TYPED},
                {url: "http://www.google.com/", 
                 transition: histsvc.TRANSITION_BOOKMARK},
                {url: "http://www.espn.com/",
                 transition: histsvc.TRANSITION_LINK}];
 
-// main
-function run_test() {
+function run_test()
+{
+  run_next_test();
+}
+
+add_task(function test_execute()
+{
   for each (var visit in gVisits) {
     if (visit.transition == histsvc.TRANSITION_TYPED)
-      gh.markPageAsTyped(uri(visit.url));
+      histsvc.markPageAsTyped(uri(visit.url));
     else if (visit.transition == histsvc.TRANSITION_BOOKMARK)
-      gh.markPageAsFollowedBookmark(uri(visit.url))
+      histsvc.markPageAsFollowedBookmark(uri(visit.url))
     else {
      // because it is a top level visit with no referrer,
      // it will result in TRANSITION_LINK
     }
-    add_uri_to_history(uri(visit.url));
+    yield promiseAddVisits({uri: uri(visit.url),
+                            transition: visit.transition});
   }
 
   do_test_pending();
-}
+});
 
 // create and add history observer
 var observer = {
   _visitCount: 0,
   onBeginUpdateBatch: function() {
   },
   onEndUpdateBatch: function() {
   },