Bug 1272686 - Change PlacesTestUtils.addVisits to use PlacesUtils.history.insertMany internally, r?mak draft
authorBob Silverberg <bsilverberg@mozilla.com>
Thu, 22 Sep 2016 13:00:55 -0400
changeset 418070 a63cee8b823c98041d0f7d98117ae290e3fb92be
parent 417649 c55bcb7c777ea09431b4d16903ed079ae5632648
child 532248 18925d6426b2e1579bef50dc61c6d8e06006faad
push id30576
push userbmo:bob.silverberg@gmail.com
push dateTue, 27 Sep 2016 16:49:01 +0000
reviewersmak
bugs1272686
milestone52.0a1
Bug 1272686 - Change PlacesTestUtils.addVisits to use PlacesUtils.history.insertMany internally, r?mak MozReview-Commit-ID: BarTJPc2Xfr
browser/components/places/tests/chrome/test_bug549192.xul
toolkit/components/places/History.jsm
toolkit/components/places/tests/PlacesTestUtils.jsm
toolkit/components/places/tests/expiration/test_notifications_onDeleteVisits.js
toolkit/components/places/tests/favicons/test_page-icon_protocol.js
toolkit/components/places/tests/queries/head_queries.js
toolkit/components/places/tests/queries/test_history_queries_tags_liveUpdate.js
toolkit/components/places/tests/queries/test_history_queries_titles_liveUpdate.js
toolkit/components/places/tests/queries/test_redirects.js
toolkit/components/places/tests/queries/test_results-as-visit.js
toolkit/components/places/tests/queries/test_searchterms-domain.js
toolkit/components/places/tests/queries/test_searchterms-uri.js
toolkit/components/places/tests/queries/test_sort-date-site-grouping.js
toolkit/components/places/tests/queries/test_sorting.js
toolkit/components/places/tests/unit/test_385397.js
toolkit/components/places/tests/unit/test_420331_wyciwyg.js
toolkit/components/places/tests/unit/test_browserhistory.js
toolkit/components/places/tests/unit/test_isvisited.js
toolkit/components/places/tests/unit/test_telemetry.js
toolkit/components/places/tests/unit/xpcshell.ini
--- a/browser/components/places/tests/chrome/test_bug549192.xul
+++ b/browser/components/places/tests/chrome/test_bug549192.xul
@@ -43,25 +43,32 @@
 
     function runTest() {
       SimpleTest.waitForExplicitFinish();
 
       Task.spawn(function* () {
         yield PlacesTestUtils.clearHistory();
 
         // Add some visits.
+        let timeInMicroseconds = PlacesUtils.toPRTime(Date.now() - 10000);
+
+        function newTimeInMicroseconds() {
+          timeInMicroseconds = timeInMicroseconds + 1000;
+          return timeInMicroseconds;
+        }
+
         let vtime = Date.now() * 1000;
         const ttype = PlacesUtils.history.TRANSITION_TYPED;
         let places =
           [{ uri: Services.io.newURI("http://example.tld/", null, null),
-             visitDate: ++vtime, transition: ttype },
+             visitDate: newTimeInMicroseconds(), transition: ttype },
            { uri: Services.io.newURI("http://example2.tld/", null, null),
-             visitDate: ++vtime, transition: ttype },
+             visitDate: newTimeInMicroseconds(), transition: ttype },
            { uri: Services.io.newURI("http://example3.tld/", null, null),
-             visitDate: ++vtime, transition: ttype }];
+             visitDate: newTimeInMicroseconds(), transition: ttype }];
 
         yield PlacesTestUtils.addVisits(places);
 
         // Make a history query.
         let query = PlacesUtils.history.getNewQuery();
         let opts = PlacesUtils.history.getNewQueryOptions();
         opts.sortingMode = opts.SORT_BY_DATE_DESCENDING;
         let queryURI = PlacesUtils.history.queriesToQueryString([query], 1, opts);
@@ -80,17 +87,17 @@
           let node = tree.selectedNode;
           is(node.uri, places[rc - i - 1].uri.spec,
              "Found expected node at position " + i + ".");
         }
 
         is(rc, 3, "Found expected number of rows.");
 
         // First check live-update of the view when adding visits.
-        places.forEach(place => place.visitDate = ++vtime);
+        places.forEach(place => place.visitDate = newTimeInMicroseconds());
         yield PlacesTestUtils.addVisits(places);
 
         for (let i = 0; i < rc; i++) {
           selection.select(i);
           let node = tree.selectedNode;
           is(node.uri, places[rc - i - 1].uri.spec,
              "Found expected node at position " + i + ".");
         }
--- a/toolkit/components/places/History.jsm
+++ b/toolkit/components/places/History.jsm
@@ -474,17 +474,17 @@ function validatePageInfo(pageInfo) {
   };
 
   if (!pageInfo.url) {
     throw new TypeError("PageInfo object must have a url property");
   }
 
   info.url = normalizeToURLOrGUID(pageInfo.url);
 
-  if (typeof pageInfo.title === "string" && pageInfo.title.length) {
+  if (typeof pageInfo.title === "string") {
     info.title = pageInfo.title;
   } else if (pageInfo.title != null && pageInfo.title != undefined) {
     throw new TypeError(`title property of PageInfo object: ${pageInfo.title} must be a string if provided`);
   }
 
   if (!pageInfo.visits || !Array.isArray(pageInfo.visits) || !pageInfo.visits.length) {
     throw new TypeError("PageInfo object must have an array of visits");
   }
--- a/toolkit/components/places/tests/PlacesTestUtils.jsm
+++ b/toolkit/components/places/tests/PlacesTestUtils.jsm
@@ -23,79 +23,66 @@ this.PlacesTestUtils = Object.freeze({
    *
    * @param aPlaceInfo
    *        Can be an nsIURI, in such a case a single LINK visit will be added.
    *        Otherwise can be an object describing the visit to add, or an array
    *        of these objects:
    *          { uri: nsIURI of the page,
    *            [optional] transition: one of the TRANSITION_* from nsINavHistoryService,
    *            [optional] title: title of the page,
-   *            [optional] visitDate: visit date in microseconds from the epoch
+   *            [optional] visitDate: visit date, either in microseconds from the epoch or as a date object
    *            [optional] referrer: nsIURI of the referrer for this visit
    *          }
    *
    * @return {Promise}
    * @resolves When all visits have been added successfully.
    * @rejects JavaScript exception.
    */
   addVisits: Task.async(function* (placeInfo) {
     let places = [];
+    let infos = [];
+
     if (placeInfo instanceof Ci.nsIURI ||
         placeInfo instanceof URL ||
         typeof placeInfo == "string") {
       places.push({ uri: placeInfo });
     }
     else if (Array.isArray(placeInfo)) {
       places = places.concat(placeInfo);
     } else if (typeof placeInfo == "object" && placeInfo.uri) {
       places.push(placeInfo)
     } else {
       throw new Error("Unsupported type passed to addVisits");
     }
 
-    // Create mozIVisitInfo for each entry.
-    let now = Date.now();
+    // Create a PageInfo for each entry.
     for (let place of places) {
-      if (typeof place.uri == "string") {
-        place.uri = NetUtil.newURI(place.uri);
-      } else if (place.uri instanceof URL) {
-        place.uri = NetUtil.newURI(place.uri.href);
-      }
-      if (typeof place.title != "string") {
-        place.title = "test visit for " + place.uri.spec;
-      }
+      let info = {url: place.uri};
+      info.title = (typeof place.title === "string") ? place.title : "test visit for " + info.url.spec ;
       if (typeof place.referrer == "string") {
         place.referrer = NetUtil.newURI(place.referrer);
       } else if (place.referrer && place.referrer instanceof URL) {
         place.referrer = NetUtil.newURI(place.referrer.href);
       }
-      place.visits = [{
-        transitionType: place.transition === undefined ? Ci.nsINavHistoryService.TRANSITION_LINK
-                                                       : place.transition,
-        visitDate: place.visitDate || (now++) * 1000,
-        referrerURI: place.referrer
+      let visitDate = place.visitDate;
+      if (visitDate) {
+        if (!(visitDate instanceof Date)) {
+          visitDate = PlacesUtils.toDate(visitDate);
+        }
+      } else {
+        visitDate = new Date();
+      }
+      info.visits = [{
+        transition: place.transition,
+        date: visitDate,
+        referrer: place.referrer
       }];
+      infos.push(info);
     }
-
-    yield new Promise((resolve, reject) => {
-      PlacesUtils.asyncHistory.updatePlaces(
-        places,
-        {
-          handleError(resultCode, placeInfo) {
-            let ex = new Components.Exception("Unexpected error in adding visits.",
-                                              resultCode);
-            reject(ex);
-          },
-          handleResult: function () {},
-          handleCompletion() {
-            resolve();
-          }
-        }
-      );
-    });
+    return PlacesUtils.history.insertMany(infos);
   }),
 
   /**
    * Clear all history.
    *
    * @return {Promise}
    * @resolves When history was cleared successfully.
    * @rejects JavaScript exception.
--- a/toolkit/components/places/tests/expiration/test_notifications_onDeleteVisits.js
+++ b/toolkit/components/places/tests/expiration/test_notifications_onDeleteVisits.js
@@ -70,21 +70,27 @@ add_task(function* test_notifications_on
   setMaxPages(0);
 
   for (let testIndex = 1; testIndex <= tests.length; testIndex++) {
     let currentTest = tests[testIndex -1];
     print("\nTEST " + testIndex + ": " + currentTest.desc);
     currentTest.receivedNotifications = 0;
 
     // Setup visits.
-    let now = getExpirablePRTime();
+    let timeInMicroseconds = getExpirablePRTime(8);
+
+    function newTimeInMicroseconds() {
+      timeInMicroseconds = timeInMicroseconds + 1000;
+      return timeInMicroseconds;
+    }
+
     for (let j = 0; j < currentTest.visitsPerPage; j++) {
       for (let i = 0; i < currentTest.addPages; i++) {
         let page = "http://" + testIndex + "." + i + ".mozilla.org/";
-        yield PlacesTestUtils.addVisits({ uri: uri(page), visitDate: now++ });
+        yield PlacesTestUtils.addVisits({ uri: uri(page), visitDate: newTimeInMicroseconds() });
       }
     }
 
     // Setup bookmarks.
     currentTest.bookmarks = [];
     for (let i = 0; i < currentTest.addBookmarks; i++) {
       let page = "http://" + testIndex + "." + i + ".mozilla.org/";
       yield PlacesUtils.bookmarks.insert({
--- a/toolkit/components/places/tests/favicons/test_page-icon_protocol.js
+++ b/toolkit/components/places/tests/favicons/test_page-icon_protocol.js
@@ -25,17 +25,17 @@ function fetchIconForSpec(spec) {
     });
   });
 }
 
 var gDefaultFavicon;
 var gFavicon;
 
 add_task(function* setup() {
-  PlacesTestUtils.addVisits({ uri: TEST_URI });
+  yield PlacesTestUtils.addVisits({ uri: TEST_URI });
 
   PlacesUtils.favicons.replaceFaviconDataFromDataURL(
     ICON_URI, ICON_DATA, (Date.now() + 8640000) * 1000,
     Services.scriptSecurityManager.getSystemPrincipal());
 
   yield new Promise(resolve => {
     PlacesUtils.favicons.setAndFetchFaviconForPage(
       TEST_URI, ICON_URI, false,
--- a/toolkit/components/places/tests/queries/head_queries.js
+++ b/toolkit/components/places/tests/queries/head_queries.js
@@ -18,21 +18,20 @@ Cu.import("resource://gre/modules/Servic
   Services.scriptloader.loadSubScript(uri.spec, this);
 }
 
 // Put any other stuff relative to this test folder below.
 
 
 // Some Useful Date constants - PRTime uses microseconds, so convert
 const DAY_MICROSEC = 86400000000;
-const today = Date.now() * 1000;
+const today = PlacesUtils.toPRTime(Date.now());
 const yesterday = today - DAY_MICROSEC;
 const lastweek = today - (DAY_MICROSEC * 7);
 const daybefore = today - (DAY_MICROSEC * 2);
-const tomorrow = today + DAY_MICROSEC;
 const old = today - (DAY_MICROSEC * 3);
 const futureday = today + (DAY_MICROSEC * 3);
 const olderthansixmonths = today - (DAY_MICROSEC * 31 * 7);
 
 
 /**
  * Generalized function to pull in an array of objects of data and push it into
  * the database.  It does NOT do any checking to see that the input is
--- a/toolkit/components/places/tests/queries/test_history_queries_tags_liveUpdate.js
+++ b/toolkit/components/places/tests/queries/test_history_queries_tags_liveUpdate.js
@@ -1,40 +1,46 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // This test ensures that tags changes are correctly live-updated in a history
 // query.
 
-var gNow = Date.now();
+let timeInMicroseconds = PlacesUtils.toPRTime(Date.now() - 10000);
+
+function newTimeInMicroseconds() {
+  timeInMicroseconds = timeInMicroseconds + 1000;
+  return timeInMicroseconds;
+}
+
 var gTestData = [
   {
     isVisit: true,
     uri: "http://example.com/1/",
-    lastVisit: gNow,
+    lastVisit: newTimeInMicroseconds(),
     isInQuery: true,
     isBookmark: true,
     parentGuid: PlacesUtils.bookmarks.unfiledGuid,
     index: PlacesUtils.bookmarks.DEFAULT_INDEX,
     title: "example1",
   },
   {
     isVisit: true,
     uri: "http://example.com/2/",
-    lastVisit: gNow++,
+    lastVisit: newTimeInMicroseconds(),
     isInQuery: true,
     isBookmark: true,
     parentGuid: PlacesUtils.bookmarks.unfiledGuid,
     index: PlacesUtils.bookmarks.DEFAULT_INDEX,
     title: "example2",
   },
   {
     isVisit: true,
     uri: "http://example.com/3/",
-    lastVisit: gNow++,
+    lastVisit: newTimeInMicroseconds(),
     isInQuery: true,
     isBookmark: true,
     parentGuid: PlacesUtils.bookmarks.unfiledGuid,
     index: PlacesUtils.bookmarks.DEFAULT_INDEX,
     title: "example3",
   },
 ];
 
--- a/toolkit/components/places/tests/queries/test_history_queries_titles_liveUpdate.js
+++ b/toolkit/components/places/tests/queries/test_history_queries_titles_liveUpdate.js
@@ -1,34 +1,40 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // This test ensures that tags changes are correctly live-updated in a history
 // query.
 
-var gNow = Date.now();
+let timeInMicroseconds = PlacesUtils.toPRTime(Date.now() - 10000);
+
+function newTimeInMicroseconds() {
+  timeInMicroseconds = timeInMicroseconds + 1000;
+  return timeInMicroseconds;
+}
+
 var gTestData = [
   {
     isVisit: true,
     uri: "http://example.com/1/",
-    lastVisit: gNow,
+    lastVisit: newTimeInMicroseconds(),
     isInQuery: true,
     title: "title1",
   },
   {
     isVisit: true,
     uri: "http://example.com/2/",
-    lastVisit: gNow++,
+    lastVisit: newTimeInMicroseconds(),
     isInQuery: true,
     title: "title2",
   },
   {
     isVisit: true,
     uri: "http://example.com/3/",
-    lastVisit: gNow++,
+    lastVisit: newTimeInMicroseconds(),
     isInQuery: true,
     title: "title3",
   },
 ];
 
 function searchNodeHavingUrl(aRoot, aUrl) {
   for (let i = 0; i < aRoot.childCount; i++) {
     if (aRoot.getChild(i).uri == aUrl) {
--- a/toolkit/components/places/tests/queries/test_redirects.js
+++ b/toolkit/components/places/tests/queries/test_redirects.js
@@ -206,47 +206,52 @@ add_task(function* test_add_visits_to_da
     Ci.nsINavHistoryService.TRANSITION_FRAMED_LINK,
     // Would make hard sorting by visit date because last_visit_date is actually
     // calculated excluding download transitions, but the query includes
     // downloads.
     // TODO: Bug 488966 could fix this behavior.
     //Ci.nsINavHistoryService.TRANSITION_DOWNLOAD,
   ];
 
+  function newTimeInMicroseconds() {
+    timeInMicroseconds = timeInMicroseconds - 1000;
+    return timeInMicroseconds;
+  }
+
   // we add a visit for each of the above transition types.
   t.forEach(transition => visits.push(
     { isVisit: true,
       transType: transition,
       uri: "http://" + transition + ".example.com/",
       title: transition + "-example",
       isRedirect: true,
-      lastVisit: timeInMicroseconds--,
+      lastVisit: newTimeInMicroseconds(),
       visitCount: (transition == Ci.nsINavHistoryService.TRANSITION_EMBED ||
                    transition == Ci.nsINavHistoryService.TRANSITION_FRAMED_LINK) ? 0 : visitCount++,
       isInQuery: true }));
 
   // Add a REDIRECT_TEMPORARY layer of visits for each of the above visits.
   t.forEach(transition => visits.push(
     { isVisit: true,
       transType: Ci.nsINavHistoryService.TRANSITION_REDIRECT_TEMPORARY,
       uri: "http://" + transition + ".redirect.temp.example.com/",
       title: transition + "-redirect-temp-example",
-      lastVisit: timeInMicroseconds--,
+      lastVisit: newTimeInMicroseconds(),
       isRedirect: true,
       referrer: "http://" + transition + ".example.com/",
       visitCount: visitCount++,
       isInQuery: true }));
 
   // Add a REDIRECT_PERMANENT layer of visits for each of the above redirects.
   t.forEach(transition => visits.push(
     { isVisit: true,
       transType: Ci.nsINavHistoryService.TRANSITION_REDIRECT_PERMANENT,
       uri: "http://" + transition + ".redirect.perm.example.com/",
       title: transition + "-redirect-perm-example",
-      lastVisit: timeInMicroseconds--,
+      lastVisit: newTimeInMicroseconds(),
       isRedirect: true,
       referrer: "http://" + transition + ".redirect.temp.example.com/",
       visitCount: visitCount++,
       isInQuery: true }));
 
   // Add a REDIRECT_PERMANENT layer of visits that loop to the first visit.
   // These entries should not change visitCount or lastVisit, otherwise
   // guessing an order would be a nightmare.
--- a/toolkit/components/places/tests/queries/test_results-as-visit.js
+++ b/toolkit/components/places/tests/queries/test_results-as-visit.js
@@ -1,23 +1,29 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
 var testData = [];
-var now = Date.now() * 1000;
+var timeInMicroseconds = PlacesUtils.toPRTime(Date.now() - 10000);
+
+function newTimeInMicroseconds() {
+  timeInMicroseconds = timeInMicroseconds + 1000;
+  return timeInMicroseconds;
+}
+
 function createTestData() {
   function generateVisits(aPage) {
     for (var i = 0; i < aPage.visitCount; i++) {
       testData.push({ isInQuery: aPage.inQuery,
                       isVisit: true,
                       title: aPage.title,
                       uri: aPage.uri,
-                      lastVisit: now++,
+                      lastVisit: newTimeInMicroseconds(),
                       isTag: aPage.tags && aPage.tags.length > 0,
                       tagArray: aPage.tags });
     }
   }
 
   var pages = [
     { uri: "http://foo.com/", title: "amo", tags: ["moz"], visitCount: 3, inQuery: true },
     { uri: "http://moilla.com/", title: "bMoz", tags: ["bugzilla"], visitCount: 5, inQuery: true },
@@ -82,32 +88,32 @@ add_task(function* test_results_as_visit
                     uri: "http://foo.mail.com/changeme2.html" }];
    yield task_populateDB(change2);
    do_check_true(isInResult(change2, root));
 
    // Update some visits - add one and take one out of query set, and simply
    // change one so that it still applies to the query.
    do_print("Updating More Items");
    var change3 = [{ isVisit: true,
-                    lastVisit: now++,
+                    lastVisit: newTimeInMicroseconds(),
                     uri: "http://foo.mail.com/changeme1.html",
                     title: "foo"},
                   { isVisit: true,
-                    lastVisit: now++,
+                    lastVisit: newTimeInMicroseconds(),
                     uri: "http://foo.mail.com/changeme3.html",
                     title: "moz",
                     isTag: true,
                     tagArray: ["foo", "moz"] }];
    yield task_populateDB(change3);
    do_check_false(isInResult({uri: "http://foo.mail.com/changeme1.html"}, root));
    do_check_true(isInResult({uri: "http://foo.mail.com/changeme3.html"}, root));
 
    // And now, delete one
    do_print("Delete item outside of batch");
    var change4 = [{ isVisit: true,
-                    lastVisit: now++,
+                    lastVisit: newTimeInMicroseconds(),
                     uri: "http://moilla.com/",
                     title: "mo,z" }];
    yield task_populateDB(change4);
    do_check_false(isInResult(change4, root));
 
    root.containerOpen = false;
 });
--- a/toolkit/components/places/tests/queries/test_searchterms-domain.js
+++ b/toolkit/components/places/tests/queries/test_searchterms-domain.js
@@ -37,25 +37,25 @@
     uri: "https://foo.com/", lastVisit: today},
 
    // Begin the invalid queries: wrong search term
    {isInQuery: false, isVisit:true, isDetails: true, title: "m o z",
     uri: "http://foo.com/tooearly.php", lastVisit: today},
 
    // Test bad URI
    {isInQuery: false, isVisit:true, isDetails: true, title: "moz",
-    uri: "http://sffoo.com/justwrong.htm", lastVisit: tomorrow},
+    uri: "http://sffoo.com/justwrong.htm", lastVisit: yesterday},
 
    // Test what we do with escaping in titles
    {isInQuery: false, isVisit:true, isDetails: true, title: "m%0o%0z",
     uri: "http://foo.com/changeme1.htm", lastVisit: yesterday},
 
    // Test another invalid title - for updating later
    {isInQuery: false, isVisit:true, isDetails: true, title: "m,oz",
-    uri: "http://foo.com/changeme2.htm", lastVisit: tomorrow}];
+    uri: "http://foo.com/changeme2.htm", lastVisit: yesterday}];
 
 /**
  * This test will test Queries that use relative search terms and domain options
  */
 function run_test()
 {
   run_next_test();
 }
--- a/toolkit/components/places/tests/queries/test_searchterms-uri.js
+++ b/toolkit/components/places/tests/queries/test_searchterms-uri.js
@@ -31,17 +31,17 @@
       title: "hugelongconfmozlagurationofwordswithasearchtermsinit whoo-hoo"},
 
     // Test what we do with escaping in titles
     {isInQuery: false, isVisit:true, isDetails: true, title: "m%0o%0z",
      uri: "http://foo.com/changeme1.htm", lastVisit: yesterday},
 
     // Test another invalid title - for updating later
     {isInQuery: false, isVisit:true, isDetails: true, title: "m,oz",
-     uri: "http://foo.com/changeme2.htm", lastVisit: tomorrow}];
+     uri: "http://foo.com/changeme2.htm", lastVisit: yesterday}];
 
 /**
  * This test will test Queries that use relative search terms and URI options
  */
 function run_test()
 {
   run_next_test();
 }
--- a/toolkit/components/places/tests/queries/test_sort-date-site-grouping.js
+++ b/toolkit/components/places/tests/queries/test_sort-date-site-grouping.js
@@ -55,17 +55,17 @@ var testData = [
     uri: "http://example.com/4",
     lastVisit: olderthansixmonths,
     title: "test visit",
     isInQuery: true
   },
   {
     isVisit: true,
     uri: "http://example.net/1",
-    lastVisit: olderthansixmonths + 1,
+    lastVisit: olderthansixmonths + 1000,
     title: "test visit",
     isInQuery: true
   }
 ];
 var domainsInRange = [2, 3];
 var leveledTestData = [// Today
                        [[0],    // Today, local files
                         [1, 2]], // Today, example.com
--- a/toolkit/components/places/tests/queries/test_sorting.js
+++ b/toolkit/components/places/tests/queries/test_sorting.js
@@ -155,59 +155,59 @@ tests.push({
     var timeInMicroseconds = Date.now() * 1000;
     this._unsortedData = [
       { isVisit: true,
         isDetails: true,
         isBookmark: true,
         parentGuid: PlacesUtils.bookmarks.toolbarGuid,
         index: 0,
         uri: "http://example.com/c1",
-        lastVisit: timeInMicroseconds - 2,
+        lastVisit: timeInMicroseconds - 2000,
         title: "x1",
         isInQuery: true },
 
       { isVisit: true,
         isDetails: true,
         isBookmark: true,
         parentGuid: PlacesUtils.bookmarks.toolbarGuid,
         index: 1,
         uri: "http://example.com/a",
-        lastVisit: timeInMicroseconds - 1,
+        lastVisit: timeInMicroseconds - 1000,
         title: "z",
         isInQuery: true },
 
       { isVisit: true,
         isDetails: true,
         isBookmark: true,
         parentGuid: PlacesUtils.bookmarks.toolbarGuid,
         index: 2,
         uri: "http://example.com/b",
-        lastVisit: timeInMicroseconds - 3,
+        lastVisit: timeInMicroseconds - 3000,
         title: "y",
         isInQuery: true },
 
       // if dates are equal, should fall back to title
       { isVisit: true,
         isDetails: true,
         isBookmark: true,
         parentGuid: PlacesUtils.bookmarks.toolbarGuid,
         index: 3,
         uri: "http://example.com/c2",
-        lastVisit: timeInMicroseconds - 2,
+        lastVisit: timeInMicroseconds - 2000,
         title: "x2",
         isInQuery: true },
 
       // if dates and title are equal, should fall back to bookmark index
       { isVisit: true,
         isDetails: true,
         isBookmark: true,
         parentGuid: PlacesUtils.bookmarks.toolbarGuid,
         index: 4,
         uri: "http://example.com/c2",
-        lastVisit: timeInMicroseconds - 2,
+        lastVisit: timeInMicroseconds - 2000,
         title: "x2",
         isInQuery: true },
     ];
 
     this._sortedData = [
       this._unsortedData[2],
       this._unsortedData[0],
       this._unsortedData[3],
@@ -1184,57 +1184,63 @@ tests.push({
 // SORT_BY_FRECENCY_*
 
 tests.push({
   _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_FRECENCY_ASCENDING,
 
   *setup() {
     do_print("Sorting test 13: SORT BY FRECENCY ");
 
-    var timeInMicroseconds = Date.now() * 1000;
+    let timeInMicroseconds = PlacesUtils.toPRTime(Date.now() - 10000);
+
+    function newTimeInMicroseconds() {
+      timeInMicroseconds = timeInMicroseconds + 1000;
+      return timeInMicroseconds;
+    }
+
     this._unsortedData = [
       { isVisit: true,
         isDetails: true,
         uri: "http://moz.com/",
-        lastVisit: timeInMicroseconds++,
-        title: "I",
-        isInQuery: true },
-
-      { isVisit: true,
-        isDetails: true,
-        uri: "http://moz.com/",
-        lastVisit: timeInMicroseconds++,
+        lastVisit: newTimeInMicroseconds(),
         title: "I",
         isInQuery: true },
 
       { isVisit: true,
         isDetails: true,
         uri: "http://moz.com/",
-        lastVisit: timeInMicroseconds++,
+        lastVisit: newTimeInMicroseconds(),
+        title: "I",
+        isInQuery: true },
+
+      { isVisit: true,
+        isDetails: true,
+        uri: "http://moz.com/",
+        lastVisit: newTimeInMicroseconds(),
         title: "I",
         isInQuery: true },
 
       { isVisit: true,
         isDetails: true,
         uri: "http://is.com/",
-        lastVisit: timeInMicroseconds++,
+        lastVisit: newTimeInMicroseconds(),
         title: "love",
         isInQuery: true },
 
       { isVisit: true,
         isDetails: true,
         uri: "http://best.com/",
-        lastVisit: timeInMicroseconds++,
+        lastVisit: newTimeInMicroseconds(),
         title: "moz",
         isInQuery: true },
 
       { isVisit: true,
         isDetails: true,
         uri: "http://best.com/",
-        lastVisit: timeInMicroseconds++,
+        lastVisit: newTimeInMicroseconds(),
         title: "moz",
         isInQuery: true },
     ];
 
     this._sortedData = [
       this._unsortedData[3],
       this._unsortedData[5],
       this._unsortedData[2],
--- a/toolkit/components/places/tests/unit/test_385397.js
+++ b/toolkit/components/places/tests/unit/test_385397.js
@@ -8,28 +8,28 @@ const TOTAL_SITES = 20;
 
 function run_test()
 {
   run_next_test();
 }
 
 add_task(function* test_execute()
 {
-  let now = Date.now() * 1000;
+  let now = (Date.now() - 10000) * 1000;
 
   for (let i = 0; i < TOTAL_SITES; i++) {
     let site = "http://www.test-" + i + ".com/";
     let testURI = uri(site);
     let testImageURI = uri(site + "blank.gif");
-    let when = now + (i * TOTAL_SITES);
+    let when = now + (i * TOTAL_SITES * 1000);
     yield PlacesTestUtils.addVisits([
       { uri: testURI, visitDate: when, transition: TRANSITION_TYPED },
-      { uri: testImageURI, visitDate: ++when, transition: TRANSITION_EMBED },
-      { uri: testImageURI, visitDate: ++when, transition: TRANSITION_FRAMED_LINK },
-      { uri: testURI, visitDate: ++when, transition: TRANSITION_LINK },
+      { uri: testImageURI, visitDate: when + 1000, transition: TRANSITION_EMBED },
+      { uri: testImageURI, visitDate: when + 2000, transition: TRANSITION_FRAMED_LINK },
+      { uri: testURI, visitDate: when + 3000, transition: TRANSITION_LINK },
     ]);
   }
 
   // verify our visits AS_VISIT, ordered by date descending
   // including hidden
   // we should get 80 visits:
   // http://www.test-19.com/
   // http://www.test-19.com/blank.gif
deleted file mode 100644
--- a/toolkit/components/places/tests/unit/test_420331_wyciwyg.js
+++ /dev/null
@@ -1,26 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
-
-function run_test()
-{
-  run_next_test();
-}
-
-add_task(function* test_execute()
-{
-  var testURI = uri("wyciwyg://nodontjudgeabookbyitscover");
-
-  try
-  {
-    yield PlacesTestUtils.addVisits(testURI);
-    do_throw("Should have generated an exception.");
-  } catch (ex) {
-    if (ex.result != Cr.NS_ERROR_ILLEGAL_VALUE) {
-      throw ex;
-    }
-    // Adding wyciwyg URIs should raise NS_ERROR_ILLEGAL_VALUE.
-  }
-});
--- a/toolkit/components/places/tests/unit/test_browserhistory.js
+++ b/toolkit/components/places/tests/unit/test_browserhistory.js
@@ -56,37 +56,37 @@ add_task(function* test_removePages() {
 
   // Cleanup.
   PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
   yield PlacesTestUtils.clearHistory();
 });
 
 add_task(function* test_removePagesByTimeframe() {
   let visits = [];
-  let startDate = Date.now() * 1000;
+  let startDate = (Date.now() - 10000) * 1000;
   for (let i = 0; i < 10; i++) {
     visits.push({
       uri: NetUtil.newURI(TEST_URI.spec + i),
-      visitDate: startDate + i
+      visitDate: startDate + i * 1000
     });
   }
 
   yield PlacesTestUtils.addVisits(visits);
 
   // Delete all pages except the first and the last.
-  PlacesUtils.bhistory.removePagesByTimeframe(startDate + 1, startDate + 8);
+  PlacesUtils.bhistory.removePagesByTimeframe(startDate + 1000, startDate + 8000);
 
   // Check that we have removed the correct pages.
   for (let i = 0; i < 10; i++) {
     do_check_eq(page_in_database(NetUtil.newURI(TEST_URI.spec + i)) == 0,
                 i > 0 && i < 9);
   }
 
   // Clear remaining items and check that all pages have been removed.
-  PlacesUtils.bhistory.removePagesByTimeframe(startDate, startDate + 9);
+  PlacesUtils.bhistory.removePagesByTimeframe(startDate, startDate + 9000);
   do_check_eq(0, PlacesUtils.history.hasHistoryEntries);
 });
 
 add_task(function* test_removePagesFromHost() {
   yield PlacesTestUtils.addVisits(TEST_URI);
   PlacesUtils.bhistory.removePagesFromHost("mozilla.com", true);
   do_check_eq(0, PlacesUtils.history.hasHistoryEntries);
 });
--- a/toolkit/components/places/tests/unit/test_isvisited.js
+++ b/toolkit/components/places/tests/unit/test_isvisited.js
@@ -58,21 +58,18 @@ add_task(function* test_execute()
     }
     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_print("Could not construct URI for '" + currentURL + "'; ignoring");
     }
     if (cantAddUri) {
-      try {
-        yield PlacesTestUtils.addVisits({uri: cantAddUri, referrer: referrer});
-        do_throw("Should have generated an exception.");
-      } catch (ex) {
-        if (ex.result != Cr.NS_ERROR_ILLEGAL_VALUE) {
-          throw ex;
-        }
-      }
+      PlacesTestUtils.addVisits({uri: cantAddUri, referrer: referrer}).then(() => {
+        do_throw("Should not have added history for invalid URI.");
+      }, error => {
+        do_check_true(error.message.includes("No items were added to history"));
+      });
       do_check_false(yield promiseIsURIVisited(cantAddUri));
     }
   }
 });
 
--- a/toolkit/components/places/tests/unit/test_telemetry.js
+++ b/toolkit/components/places/tests/unit/test_telemetry.js
@@ -89,21 +89,27 @@ add_task(function* test_execute()
   // Request to gather telemetry data.
   Cc["@mozilla.org/places/categoriesStarter;1"]
     .getService(Ci.nsIObserver)
     .observe(null, "gather-telemetry", null);
 
   yield PlacesTestUtils.promiseAsyncUpdates();
 
   // Test expiration probes.
-  let now =  getExpirablePRTime();
+  let timeInMicroseconds = getExpirablePRTime(8);
+
+  function newTimeInMicroseconds() {
+    timeInMicroseconds = timeInMicroseconds + 1000;
+    return timeInMicroseconds;
+  }
+
   for (let i = 0; i < 3; i++) {
     yield PlacesTestUtils.addVisits({
       uri: NetUtil.newURI("http://" +  i + ".moz.org/"),
-      visitDate: now++
+      visitDate: newTimeInMicroseconds()
     });
   }
   Services.prefs.setIntPref("places.history.expiration.max_pages", 0);
   yield promiseForceExpirationStep(2);
   yield promiseForceExpirationStep(2);
 
   // Test autocomplete probes.
   /*
--- a/toolkit/components/places/tests/unit/xpcshell.ini
+++ b/toolkit/components/places/tests/unit/xpcshell.ini
@@ -38,17 +38,16 @@ skip-if = os == "linux"
 # Bug 676989: test hangs consistently on Android
 skip-if = os == "android"
 [test_413784.js]
 [test_415460.js]
 [test_415757.js]
 [test_418643_removeFolderChildren.js]
 [test_419731.js]
 [test_419792_node_tags_property.js]
-[test_420331_wyciwyg.js]
 [test_425563.js]
 [test_429505_remove_shortcuts.js]
 [test_433317_query_title_update.js]
 [test_433525_hasChildren_crash.js]
 [test_452777.js]
 [test_454977.js]
 [test_463863.js]
 [test_485442_crash_bug_nsNavHistoryQuery_GetUri.js]