Bug 1383639 - Fix and add missing Places tests to manifests. r=adw draft
authorMarco Bonardo <mbonardo@mozilla.com>
Mon, 24 Jul 2017 17:28:20 +0200
changeset 614487 b48ae45a22596bd9048da961a14cdcac526f1bb7
parent 614015 5928d905c0bc0b28f5488b236444c7d7991cf8d4
child 638870 3f4dec1b91eb5218768962bc62ce0e57c0ec04b3
push id70017
push usermak77@bonardo.net
push dateMon, 24 Jul 2017 15:35:15 +0000
reviewersadw
bugs1383639
milestone56.0a1
Bug 1383639 - Fix and add missing Places tests to manifests. r=adw MozReview-Commit-ID: ImH7ob2tLxh
toolkit/components/places/History.jsm
toolkit/components/places/tests/history/test_hasVisits.js
toolkit/components/places/tests/history/xpcshell.ini
toolkit/components/places/tests/unit/test_adaptive.js
toolkit/components/places/tests/unit/xpcshell.ini
--- a/toolkit/components/places/History.jsm
+++ b/toolkit/components/places/History.jsm
@@ -526,22 +526,36 @@ this.History = Object.freeze({
    *      A promise resolved once the operation is complete.
    * @resolve (bool)
    *      `true` if the page has been visited, `false` otherwise.
    * @throws (Error)
    *      If `guidOrURI` has an unexpected type or if a string provided
    *      is neither not a valid GUID nor a valid URI.
    */
   hasVisits(guidOrURI) {
-    guidOrURI = PlacesUtils.normalizeToURLOrGUID(guidOrURI);
+    // Quick fallback to the cpp version.
+    if (guidOrURI instanceof Ci.nsIURI) {
+      return new Promise(resolve => {
+        PlacesUtils.asyncHistory.isURIVisited(guidOrURI, (aURI, aIsVisited) => {
+          resolve(aIsVisited);
+        });
+      });
+    }
 
-    return new Promise(resolve => {
-      PlacesUtils.asyncHistory.isURIVisited(guidOrURI, (aURI, aIsVisited) => {
-        resolve(aIsVisited);
-      });
+    guidOrURI = PlacesUtils.normalizeToURLOrGUID(guidOrURI);
+    let isGuid = typeof guidOrURI == "string";
+    let sqlFragment = isGuid ? "guid = :val"
+                             : "url_hash = hash(:val) AND url = :val "
+
+    return PlacesUtils.promiseDBConnection().then(async db => {
+      let rows = await db.execute(`SELECT 1 FROM moz_places
+                                    WHERE ${sqlFragment}
+                                      AND last_visit_date NOTNULL`,
+                                  { val: isGuid ? guidOrURI : guidOrURI.href });
+      return !!rows.length;
     });
   },
 
   /**
    * Clear all history.
    *
    * @return (Promise)
    *      A promise resolved once the operation is complete.
--- a/toolkit/components/places/tests/history/test_hasVisits.js
+++ b/toolkit/components/places/tests/history/test_hasVisits.js
@@ -13,24 +13,31 @@ add_task(async function test_has_visits_
   );
   Assert.throws(
     () => PlacesUtils.history.hasVisits(1),
     /TypeError: Invalid url or guid: 1/,
     "passing an invalid url into History.hasVisits should throw a TypeError"
   );
   Assert.throws(
     () => PlacesUtils.history.hasVisits({}),
-    /TypeError: Invalid url or guid: [object Object]/,
+    /TypeError: Invalid url or guid: \[object Object\]/,
     `passing an invalid (not of type URI or nsIURI) object to History.hasVisits
      should throw a TypeError`
   );
 });
 
 add_task(async function test_history_has_visits() {
   const TEST_URL = "http://mozilla.com/";
   await PlacesTestUtils.clearHistory();
   Assert.equal(await PlacesUtils.history.hasVisits(TEST_URL), false,
                "Test Url should not be in history.");
+  Assert.equal(await PlacesUtils.history.hasVisits(Services.io.newURI(TEST_URL)),
+               false, "Test Url should not be in history.");
   await PlacesTestUtils.addVisits(TEST_URL);
   Assert.equal(await PlacesUtils.history.hasVisits(TEST_URL), true,
                "Test Url should be in history.");
+  Assert.equal(await PlacesUtils.history.hasVisits(Services.io.newURI(TEST_URL)),
+               true, "Test Url should be in history.");
+  let guid = await PlacesTestUtils.fieldInDB(TEST_URL, "guid");
+  Assert.equal(await PlacesUtils.history.hasVisits(guid),
+               true, "Test Url should be in history.");
   await PlacesTestUtils.clearHistory();
 });
--- a/toolkit/components/places/tests/history/xpcshell.ini
+++ b/toolkit/components/places/tests/history/xpcshell.ini
@@ -1,13 +1,14 @@
 [DEFAULT]
 head = head_history.js
 
 [test_async_history_api.js]
 [test_fetch.js]
+[test_hasVisits.js]
 [test_insert.js]
 [test_insertMany.js]
 [test_remove.js]
 [test_removeMany.js]
 [test_removeVisits.js]
 [test_removeByFilter.js]
 [test_removeVisitsByFilter.js]
 [test_sameUri_titleChanged.js]
--- a/toolkit/components/places/tests/unit/test_adaptive.js
+++ b/toolkit/components/places/tests/unit/test_adaptive.js
@@ -388,15 +388,15 @@ add_task(async function test_adaptive() 
 
     let types = ["history", "bookmark", "openpage"];
     for (let type of types) {
       Services.prefs.clearUserPref("browser.urlbar.suggest." + type);
     }
 
     await PlacesTestUtils.clearHistory();
 
-    deferEnsureResults = Promise.defer();
+    deferEnsureResults = PromiseUtils.defer();
     await test();
     await deferEnsureResults.promise;
   }
 
   Services.obs.removeObserver(observer, PlacesUtils.TOPIC_FEEDBACK_UPDATED);
 });
--- a/toolkit/components/places/tests/unit/xpcshell.ini
+++ b/toolkit/components/places/tests/unit/xpcshell.ini
@@ -50,16 +50,17 @@ skip-if = os == "linux"
 [test_454977.js]
 [test_463863.js]
 [test_485442_crash_bug_nsNavHistoryQuery_GetUri.js]
 [test_486978_sort_by_date_queries.js]
 [test_536081.js]
 [test_1085291.js]
 [test_1105208.js]
 [test_1105866.js]
+[test_adaptive.js]
 [test_adaptive_bug527311.js]
 [test_annotations.js]
 [test_asyncExecuteLegacyQueries.js]
 [test_async_in_batchmode.js]
 [test_async_transactions.js]
 skip-if = (os == "win" && os_version == "5.1") # Bug 1158887
 [test_autocomplete_stopSearch_no_throw.js]
 [test_bookmark_catobs.js]