Backed out changeset 9c339f571d35 (bug 1448081) for browser chrome failures on browser/components/places/tests/browser/browser_library_downloads.js. a=backout"
authorDorel Luca <dluca@mozilla.com>
Sat, 21 Apr 2018 04:49:45 +0300
changeset 414785 d36d2c2ab772
parent 414784 39ccabfd7d07
child 414817 434e9f18678c
child 414917 65f8a6ed6a18
push id33877
push userdluca@mozilla.com
push dateSat, 21 Apr 2018 01:50:02 +0000
treeherdermozilla-central@d36d2c2ab772 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1448081
milestone61.0a1
backs out9c339f571d35
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
Backed out changeset 9c339f571d35 (bug 1448081) for browser chrome failures on browser/components/places/tests/browser/browser_library_downloads.js. a=backout"
browser/base/content/test/sanitize/browser_sanitize-timespans.js
browser/components/places/tests/browser/browser_library_downloads.js
toolkit/components/places/tests/unit/test_454977.js
toolkit/components/places/tests/unit/test_download_history.js
toolkit/components/places/tests/unit/test_isURIVisited.js
--- a/browser/base/content/test/sanitize/browser_sanitize-timespans.js
+++ b/browser/base/content/test/sanitize/browser_sanitize-timespans.js
@@ -1,13 +1,10 @@
 requestLongerTimeout(2);
 
-const {PlacesTestUtils} =
-  ChromeUtils.import("resource://testing-common/PlacesTestUtils.jsm", {});
-
 // Bug 453440 - Test the timespan-based logic of the sanitizer code
 var now_mSec = Date.now();
 var now_uSec = now_mSec * 1000;
 
 const kMsecPerMin = 60 * 1000;
 const kUsecPerMin = 60 * 1000000;
 
 function promiseFormHistoryRemoved() {
@@ -424,47 +421,56 @@ async function onHistoryReady() {
   ok(!(await PlacesUtils.history.hasVisits("http://before-today.com")),
      "Pretend visit to before-today.com should now be deleted");
 
   await countEntries("b4today", "b4today form entry should be deleted", checkZero);
 
   ok(!(await downloadExists(publicList, "fakefile-old")), "Year old download should now be deleted");
 }
 
-async function setupHistory() {
+function setupHistory() {
+  return new Promise(resolve => {
 
-  let places = [];
+    let places = [];
 
-  function addPlace(aURI, aTitle, aVisitDate) {
-    places.push({
-      uri: aURI,
-      title: aTitle,
-      visitDate: aVisitDate,
-      transition: Ci.nsINavHistoryService.TRANSITION_LINK
-    });
-  }
+    function addPlace(aURI, aTitle, aVisitDate) {
+      places.push({
+        uri: aURI,
+        title: aTitle,
+        visits: [{
+          visitDate: aVisitDate,
+          transitionType: Ci.nsINavHistoryService.TRANSITION_LINK
+        }]
+      });
+    }
 
-  addPlace("http://10minutes.com/", "10 minutes ago", now_uSec - 10 * kUsecPerMin);
-  addPlace("http://1hour.com/", "Less than 1 hour ago", now_uSec - 45 * kUsecPerMin);
-  addPlace("http://1hour10minutes.com/", "1 hour 10 minutes ago", now_uSec - 70 * kUsecPerMin);
-  addPlace("http://2hour.com/", "Less than 2 hours ago", now_uSec - 90 * kUsecPerMin);
-  addPlace("http://2hour10minutes.com/", "2 hours 10 minutes ago", now_uSec - 130 * kUsecPerMin);
-  addPlace("http://4hour.com/", "Less than 4 hours ago", now_uSec - 180 * kUsecPerMin);
-  addPlace("http://4hour10minutes.com/", "4 hours 10 minutesago", now_uSec - 250 * kUsecPerMin);
+    addPlace(makeURI("http://10minutes.com/"), "10 minutes ago", now_uSec - 10 * kUsecPerMin);
+    addPlace(makeURI("http://1hour.com/"), "Less than 1 hour ago", now_uSec - 45 * kUsecPerMin);
+    addPlace(makeURI("http://1hour10minutes.com/"), "1 hour 10 minutes ago", now_uSec - 70 * kUsecPerMin);
+    addPlace(makeURI("http://2hour.com/"), "Less than 2 hours ago", now_uSec - 90 * kUsecPerMin);
+    addPlace(makeURI("http://2hour10minutes.com/"), "2 hours 10 minutes ago", now_uSec - 130 * kUsecPerMin);
+    addPlace(makeURI("http://4hour.com/"), "Less than 4 hours ago", now_uSec - 180 * kUsecPerMin);
+    addPlace(makeURI("http://4hour10minutes.com/"), "4 hours 10 minutesago", now_uSec - 250 * kUsecPerMin);
 
-  let today = new Date();
-  today.setHours(0);
-  today.setMinutes(0);
-  today.setSeconds(1);
-  addPlace("http://today.com/", "Today", today.getTime() * 1000);
+    let today = new Date();
+    today.setHours(0);
+    today.setMinutes(0);
+    today.setSeconds(1);
+    addPlace(makeURI("http://today.com/"), "Today", today.getTime() * 1000);
 
-  let lastYear = new Date();
-  lastYear.setFullYear(lastYear.getFullYear() - 1);
-  addPlace("http://before-today.com/", "Before Today", lastYear.getTime() * 1000);
-  await PlacesTestUtils.addVisits(places);
+    let lastYear = new Date();
+    lastYear.setFullYear(lastYear.getFullYear() - 1);
+    addPlace(makeURI("http://before-today.com/"), "Before Today", lastYear.getTime() * 1000);
+    PlacesUtils.asyncHistory.updatePlaces(places, {
+      handleError: () => ok(false, "Unexpected error in adding visit."),
+      handleResult: () => { },
+      handleCompletion: () => resolve()
+    });
+
+  });
 }
 
 async function setupFormHistory() {
 
   function searchEntries(terms, params) {
     return new Promise((resolve, reject) => {
 
       let results = [];
--- a/browser/components/places/tests/browser/browser_library_downloads.js
+++ b/browser/components/places/tests/browser/browser_library_downloads.js
@@ -5,47 +5,64 @@
 /*
  * Tests bug 564900: Add folder specifically for downloads to Library left pane.
  * https://bugzilla.mozilla.org/show_bug.cgi?id=564900
  * This test visits various pages then opens the Library and ensures
  * that both the Downloads folder shows up and that the correct visits
  * are shown in it.
  */
 
-add_task(async function test() {
-  // Add visits.
-  await PlacesTestUtils.addVisits([{
-    uri: "http://mozilla.org",
-    transition: PlacesUtils.history.TRANSITION_TYPED
-  }, {
-    uri: "http://google.com",
-    transition: PlacesUtils.history.TRANSITION_DOWNLOAD
-  }, {
-    uri: "http://en.wikipedia.org",
-    transition: PlacesUtils.history.TRANSITION_TYPED
-  }, {
-    uri: "http://ubuntu.org",
-    transition: PlacesUtils.history.TRANSITION_DOWNLOAD
-  }]);
+var now = Date.now();
 
-  let library = await promiseLibrary("Downloads");
+function test() {
+  waitForExplicitFinish();
 
-  registerCleanupFunction(async () => {
-    await library.close();
-    await PlacesUtils.history.clear();
-  });
-
-  // Make sure Downloads is present.
-  Assert.notEqual(library.PlacesOrganizer._places.selectedNode, null,
-    "Downloads is present and selected");
+  let onLibraryReady = function(win) {
+    // Add visits to compare contents with.
+    let places = [
+      { uri: NetUtil.newURI("http://mozilla.com"),
+        visits: [ new VisitInfo(PlacesUtils.history.TRANSITION_TYPED) ]
+      },
+      { uri: NetUtil.newURI("http://google.com"),
+        visits: [ new VisitInfo(PlacesUtils.history.TRANSITION_DOWNLOAD) ]
+      },
+      { uri: NetUtil.newURI("http://en.wikipedia.org"),
+        visits: [ new VisitInfo(PlacesUtils.history.TRANSITION_TYPED) ]
+      },
+      { uri: NetUtil.newURI("http://ubuntu.org"),
+        visits: [ new VisitInfo(PlacesUtils.history.TRANSITION_DOWNLOAD) ]
+      },
+    ];
+    PlacesUtils.asyncHistory.updatePlaces(places, {
+      handleResult() {},
+      handleError() {
+        ok(false, "gHistory.updatePlaces() failed");
+      },
+      handleCompletion() {
+        // Make sure Downloads is present.
+        isnot(win.PlacesOrganizer._places.selectedNode, null,
+              "Downloads is present and selected");
 
-  // Check results.
-  let testURIs = ["http://ubuntu.org/", "http://google.com/"];
 
-  await BrowserTestUtils.waitForCondition(() =>
-    library.ContentArea.currentView.associatedElement.children.length == testURIs.length);
+        // Check results.
+        let testURIs = ["http://ubuntu.org/", "http://google.com/"];
+        for (let element of win.ContentArea.currentView
+                                           .associatedElement.children) {
+          is(element._shell.download.source.url, testURIs.shift(),
+             "URI matches");
+        }
 
-  for (let element of library.ContentArea.currentView
-                                          .associatedElement.children) {
-    Assert.equal(element._shell.download.source.url, testURIs.shift(),
-      "URI matches");
-  }
-});
+        win.close();
+        PlacesUtils.history.clear().then(finish);
+      }
+    });
+  };
+
+  openLibrary(onLibraryReady, "Downloads");
+}
+
+function VisitInfo(aTransitionType) {
+  this.transitionType =
+    aTransitionType === undefined ?
+      PlacesUtils.history.TRANSITION_LINK : aTransitionType;
+  this.visitDate = now++ * 1000;
+}
+VisitInfo.prototype = {};
--- a/toolkit/components/places/tests/unit/test_454977.js
+++ b/toolkit/components/places/tests/unit/test_454977.js
@@ -4,33 +4,35 @@
  * 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/. */
 
 // Cache actual visit_count value, filled by add_visit, used by check_results
 var visit_count = 0;
 
 // Returns the Place ID corresponding to an added visit.
 async function task_add_visit(aURI, aVisitType) {
-  // Wait for a visits notification and get the visitId.
-  let visitId;
-  let visitsPromise = PlacesTestUtils.waitForNotification("onVisits", visits => {
-    visitId = visits[0].visitId;
-    let {uri} = visits[0];
-    return uri.equals(aURI);
-  }, "history");
+  // Add the visit asynchronously, and save its visit ID.
+  let deferUpdatePlaces = new Promise((resolve, reject) => {
+    PlacesUtils.asyncHistory.updatePlaces({
+      uri: aURI,
+      visits: [{ transitionType: aVisitType, visitDate: Date.now() * 1000 }]
+    }, {
+      handleError: function TAV_handleError() {
+        reject(new Error("Unexpected error in adding visit."));
+      },
+      handleResult(aPlaceInfo) {
+        this.visitId = aPlaceInfo.visits[0].visitId;
+      },
+      handleCompletion: function TAV_handleCompletion() {
+        resolve(this.visitId);
+      }
+    });
+  });
 
-  // Add visits.
-  await PlacesTestUtils.addVisits([{
-    uri: aURI,
-    transition: aVisitType
-  }]);
-
-  if (aVisitType != TRANSITION_EMBED) {
-    await visitsPromise;
-  }
+  let visitId = await deferUpdatePlaces;
 
   // Increase visit_count if applicable
   if (aVisitType != 0 &&
       aVisitType != TRANSITION_EMBED &&
       aVisitType != TRANSITION_FRAMED_LINK &&
       aVisitType != TRANSITION_DOWNLOAD &&
       aVisitType != TRANSITION_RELOAD) {
     visit_count++;
--- a/toolkit/components/places/tests/unit/test_download_history.js
+++ b/toolkit/components/places/tests/unit/test_download_history.js
@@ -149,51 +149,44 @@ add_task(async function test_dh_addBookm
       });
       gDownloadHistory.removeAllDownloads();
     });
 
     gDownloadHistory.addDownload(DOWNLOAD_URI, null, Date.now() * 1000);
   });
 });
 
-add_task(async function test_dh_addDownload_referrer() {
-  // Wait for visits notification and get the visit id.
-  let visitId;
-  let referrerPromise = PlacesTestUtils.waitForNotification("onVisits", visits => {
-    visitId = visits[0].visitId;
-    let {uri} = visits[0];
-    return uri.equals(REFERRER_URI);
-  }, "history");
+add_test(function test_dh_addDownload_referrer() {
+  waitForOnVisit(function DHAD_prepareReferrer(aURI, aVisitID) {
+    Assert.ok(aURI.equals(REFERRER_URI));
+    let referrerVisitId = aVisitID;
 
-  await PlacesTestUtils.addVisits([{
-    uri: REFERRER_URI,
-    transition: Ci.nsINavHistoryService.TRANSITION_TYPED
-  }]);
-  await referrerPromise;
+    waitForOnVisit(function DHAD_onVisit(aVisitedURI, unused, unused2, unused3,
+                                         aReferringID) {
+      Assert.ok(aVisitedURI.equals(DOWNLOAD_URI));
+      Assert.equal(aReferringID, referrerVisitId);
+
+      // Verify that the URI is already available in results at this time.
+      Assert.ok(!!page_in_database(DOWNLOAD_URI));
 
-  // Verify results for referrer uri.
-  Assert.ok(!!PlacesTestUtils.isPageInDB(REFERRER_URI));
-  Assert.equal(visitId, 1);
+      PlacesUtils.history.clear().then(run_next_test);
+    });
+
+    gDownloadHistory.addDownload(DOWNLOAD_URI, REFERRER_URI, Date.now() * 1000);
+  });
 
-  // Wait for visits notification and get the referrer Id.
-  let referrerId;
-  let downloadPromise = PlacesTestUtils.waitForNotification("onVisits", visits => {
-    referrerId = visits[0].referrerId;
-    let {uri} = visits[0];
-    return uri.equals(DOWNLOAD_URI);
-  }, "history");
-
-  gDownloadHistory.addDownload(DOWNLOAD_URI, REFERRER_URI, Date.now() * 1000);
-  await downloadPromise;
-
-  // Verify results for download uri.
-  Assert.ok(!!PlacesTestUtils.isPageInDB(DOWNLOAD_URI));
-  Assert.equal(visitId, referrerId);
-
-  await PlacesUtils.history.clear();
+  // Note that we don't pass the optional callback argument here because we must
+  // ensure that we receive the onVisits notification before we call addDownload.
+  PlacesUtils.asyncHistory.updatePlaces({
+    uri: REFERRER_URI,
+    visits: [{
+      transitionType: Ci.nsINavHistoryService.TRANSITION_TYPED,
+      visitDate: Date.now() * 1000
+    }]
+  });
 });
 
 add_test(function test_dh_addDownload_disabledHistory() {
   waitForOnVisit(function DHAD_onVisit(aURI) {
     // We should only receive the notification for the non-private URI.  This
     // test is based on the assumption that visit notifications are received in
     // the same order of the addDownload calls, which is currently true because
     // database access is serialized on the same worker thread.
--- a/toolkit/components/places/tests/unit/test_isURIVisited.js
+++ b/toolkit/components/places/tests/unit/test_isURIVisited.js
@@ -18,51 +18,64 @@ const SCHEMES = {
   "view-source:http://": false,
   "chrome://browser/content/browser.xul?": false,
   "resource://": false,
   "data:,": false,
   "wyciwyg:/0/http://": false,
   "javascript:": false,
 };
 
-add_task(async function test_isURIVisited() {
+var gRunner;
+function run_test() {
+  do_test_pending();
+  gRunner = step();
+  gRunner.next();
+}
+
+function* step() {
   let history = Cc["@mozilla.org/browser/history;1"]
                   .getService(Ci.mozIAsyncHistory);
 
-  function visitsPromise(uri) {
-    return new Promise(resolve => {
-      history.isURIVisited(uri, (receivedURI, visited) => {
-        resolve([receivedURI, visited]);
-      });
-    });
-  }
-
   for (let scheme in SCHEMES) {
     info("Testing scheme " + scheme);
     for (let t in PlacesUtils.history.TRANSITIONS) {
       info("With transition " + t);
-      let aTransition = PlacesUtils.history.TRANSITIONS[t];
+      let transition = PlacesUtils.history.TRANSITIONS[t];
+
+      let uri = NetUtil.newURI(scheme + "mozilla.org/");
 
-      let aURI = Services.io.newURI(scheme + "mozilla.org/");
+      history.isURIVisited(uri, function(aURI, aIsVisited) {
+        Assert.ok(uri.equals(aURI));
+        Assert.ok(!aIsVisited);
 
-      let [receivedURI1, visited1] = await visitsPromise(aURI);
-      Assert.ok(aURI.equals(receivedURI1));
-      Assert.ok(!visited1);
+        let callback = {
+          handleError() {},
+          handleResult() {},
+          handleCompletion() {
+            info("Added visit to " + uri.spec);
+
+            history.isURIVisited(uri, function(aURI2, aIsVisited2) {
+              Assert.ok(uri.equals(aURI2));
+              Assert.ok(SCHEMES[scheme] ? aIsVisited2 : !aIsVisited2);
 
-      if (PlacesUtils.history.canAddURI(aURI)) {
-        await PlacesTestUtils.addVisits([{
-          uri: aURI,
-          transition: aTransition
-        }]);
-        info("Added visit for " + aURI.spec);
-      }
+              PlacesUtils.history.clear().then(function() {
+                history.isURIVisited(uri, function(aURI3, aIsVisited3) {
+                  Assert.ok(uri.equals(aURI3));
+                  Assert.ok(!aIsVisited3);
+                  gRunner.next();
+                });
+              });
+            });
+          },
+        };
 
-      let [receivedURI2, visited2] = await visitsPromise(aURI);
-      Assert.ok(aURI.equals(receivedURI2));
-      Assert.equal(SCHEMES[scheme], visited2);
-
-      await PlacesUtils.history.clear();
-      let [receivedURI3, visited3] = await visitsPromise(aURI);
-      Assert.ok(aURI.equals(receivedURI3));
-      Assert.ok(!visited3);
+        history.updatePlaces({ uri,
+                               visits: [ { transitionType: transition,
+                                           visitDate:      Date.now() * 1000
+                                         } ]
+                             }, callback);
+      });
+      yield undefined;
     }
   }
-});
+
+  do_test_finished();
+}