Bug 1366231 - Implement History.hasVisits as a wrapper of asyncHistory.isURIVisited; r=mak
☠☠ backed out by 525fb3e1314b ☠ ☠
authormeetshah <meet1995@gmail.com>
Mon, 29 May 2017 23:41:56 +0530
changeset 410941 aa3d11c78ac9a7ee493b595e91bf49f4c77e50bc
parent 410940 364a31932fe3f0be6d7c8e68aefe05f225fcdad9
child 410942 9b935696d41305da89c147173bca277db6f72dab
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1366231
milestone55.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 1366231 - Implement History.hasVisits as a wrapper of asyncHistory.isURIVisited; r=mak Tests for the wrapper implementation added in test_hasVisits.js in toolkit/components/places/tests/history. MozReview-Commit-ID: KEW2bDTSWVY
toolkit/components/places/History.jsm
toolkit/components/places/tests/history/test_hasVisits.js
--- a/toolkit/components/places/History.jsm
+++ b/toolkit/components/places/History.jsm
@@ -509,31 +509,34 @@ this.History = Object.freeze({
       "History.jsm: removeByFilter",
       db => removeByFilter(db, filter, onResult)
     );
   },
 
   /**
    * Determine if a page has been visited.
    *
-   * @param pages: (URL or nsIURI)
-   *      The full URI of the page.
-   *            or (string)
-   *      The full URI of the page or the GUID of the page.
-   *
+   * @param guidOrURI: (string) or (URL, nsIURI or href)
+   *      Either the full URI of the page or the GUID of the page.
    * @return (Promise)
    *      A promise resolved once the operation is complete.
    * @resolve (bool)
    *      `true` if the page has been visited, `false` otherwise.
    * @throws (Error)
-   *      If `pages` has an unexpected type or if a string provided
+   *      If `guidOrURI` has an unexpected type or if a string provided
    *      is neither not a valid GUID nor a valid URI.
    */
-  hasVisits(page, onResult) {
-    throw new Error("Method not implemented");
+  hasVisits(guidOrURI) {
+    guidOrURI = PlacesUtils.normalizeToURLOrGUID(guidOrURI);
+
+    return new Promise(resolve => {
+      PlacesUtils.asyncHistory.isURIVisited(guidOrURI, (aURI, aIsVisited) => {
+        resolve(aIsVisited);
+      });
+    });
   },
 
   /**
    * Clear all history.
    *
    * @return (Promise)
    *      A promise resolved once the operation is complete.
    */
@@ -1247,9 +1250,9 @@ var insertMany = async function(db, page
         if (updatedCount > 0) {
           resolve();
         } else {
           reject({message: "No items were added to history."})
         }
       }
     }, true);
   });
-};
+};
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/tests/history/test_hasVisits.js
@@ -0,0 +1,36 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Tests for `History.hasVisits` as implemented in History.jsm
+
+"use strict";
+
+add_task(async function test_has_visits_error_cases() {
+  Assert.throws(
+    () => PlacesUtils.history.hasVisits(),
+    /TypeError: Invalid url or guid: undefined/,
+    "passing a null into History.hasVisits should throw a TypeError"
+  );
+  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]/,
+    `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.");
+  await PlacesTestUtils.addVisits(TEST_URL);
+  Assert.equal(await PlacesUtils.history.hasVisits(TEST_URL), true,
+               "Test Url should be in history.");
+  await PlacesTestUtils.clearHistory();
+});
\ No newline at end of file