Bug 1343182 - Add updatePlaces' ignoreErrors, ignoreResults and aGroupNotifications to insertMany API in History.jsm. r=mak
authorGanesh Chaitanya Kale <ganesh2583@gmail.com>
Sat, 01 Apr 2017 13:10:04 +0530
changeset 352626 f92e59ad3033
parent 352625 d99f00376b25
child 352627 941929d3841e
push id31642
push userkwierso@gmail.com
push dateWed, 12 Apr 2017 21:39:19 +0000
treeherdermozilla-central@fac2c174087f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1343182
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 1343182 - Add updatePlaces' ignoreErrors, ignoreResults and aGroupNotifications to insertMany API in History.jsm. r=mak MozReview-Commit-ID: 45VbtBu25cP
browser/components/migration/tests/unit/test_automigration.js
browser/components/newtab/tests/xpcshell/test_PlacesProvider.js
toolkit/components/places/History.jsm
toolkit/components/places/tests/history/test_insertMany.js
--- a/browser/components/migration/tests/unit/test_automigration.js
+++ b/browser/components/migration/tests/unit/test_automigration.js
@@ -571,21 +571,19 @@ add_task(function* checkUndoVisitsState(
       transitionType: Ci.nsINavHistoryService.TRANSITION_LINK,
     }],
   }]);
 
   // We have to wait until frecency updates have been handled in order
   // to accurately determine whether we're doing the right thing.
   let frecencyUpdatesHandled = new Promise(resolve => {
     PlacesUtils.history.addObserver({
-      onFrecencyChanged(aURI) {
-        if (aURI.spec == "http://www.unrelated.org/") {
-          PlacesUtils.history.removeObserver(this);
-          resolve();
-        }
+      onManyFrecenciesChanged() {
+        PlacesUtils.history.removeObserver(this);
+        resolve();
       }
     }, false);
   });
   yield PlacesUtils.history.insertMany([{
     url: "http://www.example.com/",
     title: "Example",
     visits: [{
       date: new Date("2015-08-16"),
--- a/browser/components/newtab/tests/xpcshell/test_PlacesProvider.js
+++ b/browser/components/newtab/tests/xpcshell/test_PlacesProvider.js
@@ -159,17 +159,20 @@ add_task(function* test_Links_onLinkChan
         }
       }
     };
     provider.on("linkChanged", handler);
   });
 
   // add a visit
   let testURI = NetUtil.newURI(url);
-  yield PlacesTestUtils.addVisits(testURI);
+  yield PlacesUtils.history.insert({
+    url: testURI,
+    visits: [{ transition: PlacesUtils.history.TRANSITIONS.LINK }]
+  });
   yield linkChangedPromise;
 
   yield PlacesTestUtils.clearHistory();
 });
 
 add_task(function* test_Links_onClearHistory() {
   let provider = PlacesProvider.links;
 
--- a/toolkit/components/places/History.jsm
+++ b/toolkit/components/places/History.jsm
@@ -1030,20 +1030,22 @@ var insertMany = Task.async(function*(db
       handleError: (resultCode, result) => {
         let pageInfo = mergeUpdateInfoIntoPageInfo(result);
         onErrorData.push(pageInfo);
       },
       handleResult: result => {
         let pageInfo = mergeUpdateInfoIntoPageInfo(result);
         onResultData.push(pageInfo);
       },
-      handleCompletion: () => {
+      ignoreErrors: !onError,
+      ignoreResults: !onResult,
+      handleCompletion: (updatedCount) => {
         notifyOnResult(onResultData, onResult);
         notifyOnResult(onErrorData, onError);
-        if (onResultData.length) {
+        if (updatedCount > 0) {
           resolve();
         } else {
           reject({message: "No items were added to history."})
         }
       }
-    });
+    }, true);
   });
 });
--- a/toolkit/components/places/tests/history/test_insertMany.js
+++ b/toolkit/components/places/tests/history/test_insertMany.js
@@ -48,16 +48,31 @@ add_task(function* test_insertMany() {
 
       pageInfo.url = yield filter(uri);
       pageInfos.push(pageInfo);
     }
     return pageInfos;
   });
 
   let inserter = Task.async(function*(name, filter, useCallbacks) {
+    function promiseManyFrecenciesChanged() {
+      return new Promise((resolve, reject) => {
+        let obs = new NavHistoryObserver();
+        obs.onManyFrecenciesChanged = () => {
+          PlacesUtils.history.removeObserver(obs);
+          resolve();
+        };
+        obs.onFrecencyChanged = () => {
+          PlacesUtils.history.removeObserver(obs);
+          reject();
+        };
+        PlacesUtils.history.addObserver(obs, false);
+      });
+    }
+
     do_print(name);
     do_print(`filter: ${filter}`);
     do_print(`useCallbacks: ${useCallbacks}`);
     yield PlacesTestUtils.clearHistory();
 
     let result;
     let allUrls = GOOD_URLS.concat(BAD_URLS);
     let pageInfos = yield makePageInfos(allUrls, filter);
@@ -76,17 +91,19 @@ add_task(function* test_insertMany() {
         Assert.ok(BAD_URLS.includes(url), "onError callback called for correct uri");
         onErrorUrls.push(url);
         Assert.equal(undefined, pageInfo.title, "onError callback provides the correct title");
         Assert.equal(undefined, pageInfo.guid, "onError callback provides the expected guid");
       });
       Assert.equal(GOOD_URLS.sort().toString(), onResultUrls.sort().toString(), "onResult callback was called for each good url");
       Assert.equal(BAD_URLS.sort().toString(), onErrorUrls.sort().toString(), "onError callback was called for each bad url");
     } else {
+      let promiseManyFrecencies = promiseManyFrecenciesChanged();
       result = yield PlacesUtils.history.insertMany(pageInfos);
+      yield promiseManyFrecencies;
     }
 
     Assert.equal(undefined, result, "insertMany returned undefined");
 
     for (let url of allUrls) {
       let expected = GOOD_URLS.includes(url);
       Assert.equal(expected, yield PlacesTestUtils.isPageInDB(url), `isPageInDB for ${url} is ${expected}`);
       Assert.equal(expected, yield PlacesTestUtils.visitsInDB(url), `visitsInDB for ${url} is ${expected}`);