Bug 1388149 - Make PlacesUtils.history.insertMany respect provided GUIDs r?markh draft
authorThom Chiovoloni <tchiovoloni@mozilla.com>
Mon, 07 Aug 2017 16:01:10 -0400
changeset 643400 3e9783a0e10f9a964e2e6ece1f9ef7052960e537
parent 642171 06c9ca99d4618e2d3316218249cc5672dbf70119
child 725295 71106c77721868f64ddc73f320806907b8eb780d
push id73089
push userbmo:tchiovoloni@mozilla.com
push dateWed, 09 Aug 2017 18:26:41 +0000
reviewersmarkh
bugs1388149
milestone57.0a1
Bug 1388149 - Make PlacesUtils.history.insertMany respect provided GUIDs r?markh MozReview-Commit-ID: 7g6uABtHKg2
services/sync/tests/unit/test_history_store.js
toolkit/components/places/History.jsm
toolkit/components/places/tests/history/test_insertMany.js
--- a/services/sync/tests/unit/test_history_store.js
+++ b/services/sync/tests/unit/test_history_store.js
@@ -132,16 +132,17 @@ add_task(async function test_store_creat
     {id: tbguid,
      histUri: tburi.spec,
      title: "The bird is the word!",
      visits: [{date: TIMESTAMP3,
                type: Ci.nsINavHistoryService.TRANSITION_TYPED}]}
   ]);
   await onVisitObserved;
   try {
+    do_check_true((await store.itemExists(tbguid)));
     do_check_attribute_count(await store.getAllIDs(), 2);
     let queryres = queryHistoryVisits(tburi);
     do_check_eq(queryres.length, 1);
     do_check_eq(queryres[0].time, TIMESTAMP3);
     do_check_eq(queryres[0].title, "The bird is the word!");
   } catch (ex) {
     PlacesTestUtils.clearHistory();
     do_throw(ex);
--- a/toolkit/components/places/History.jsm
+++ b/toolkit/components/places/History.jsm
@@ -705,16 +705,17 @@ this.History = Object.freeze({
  * Note: this assumes that the PageInfo object has already been validated
  * via PlacesUtils.validatePageInfo.
  *
  * @param pageInfo: (PageInfo)
  * @return (info)
  */
 function convertForUpdatePlaces(pageInfo) {
   let info = {
+    guid: pageInfo.guid,
     uri: PlacesUtils.toURI(pageInfo.url),
     title: pageInfo.title,
     visits: [],
   };
 
   for (let inVisit of pageInfo.visits) {
     let visit = {
       visitDate: PlacesUtils.toPRTime(inVisit.date),
--- a/toolkit/components/places/tests/history/test_insertMany.js
+++ b/toolkit/components/places/tests/history/test_insertMany.js
@@ -140,8 +140,56 @@ add_task(async function test_transitions
   await PlacesUtils.history.insertMany(places);
   // Check callbacks.
   let count = 0;
   await PlacesUtils.history.insertMany(places, pageInfo => {
     ++count;
   });
   Assert.equal(count, Object.keys(PlacesUtils.history.TRANSITIONS).length);
 });
+
+add_task(async function test_guid() {
+  const guidA = "aaaaaaaaaaaa";
+  const guidB = "bbbbbbbbbbbb";
+  const guidC = "cccccccccccc";
+
+  await PlacesUtils.history.insertMany([
+    {
+      title: "foo",
+      url: "http://example.com/foo",
+      guid: guidA,
+      visits: [
+        { transition: TRANSITION_LINK, date: new Date() }
+      ]
+    }
+  ]);
+
+  Assert.ok(await PlacesUtils.history.fetch(guidA),
+            "Record is inserted with correct GUID");
+
+  let expectedGuids = new Set([guidB, guidC]);
+  await PlacesUtils.history.insertMany([
+    {
+      title: "bar",
+      url: "http://example.com/bar",
+      guid: guidB,
+      visits: [
+        { transition: TRANSITION_LINK, date: new Date() }
+      ]
+    },
+    {
+      title: "baz",
+      url: "http://example.com/baz",
+      guid: guidC,
+      visits: [
+        { transition: TRANSITION_LINK, date: new Date() }
+      ]
+    }
+  ], pageInfo => {
+    Assert.ok(expectedGuids.has(pageInfo.guid));
+    expectedGuids.delete(pageInfo.guid);
+  });
+  Assert.equal(expectedGuids.size, 0);
+
+
+  Assert.ok(await PlacesUtils.history.fetch(guidB), "Record B is fetchable after insertMany");
+  Assert.ok(await PlacesUtils.history.fetch(guidC), "Record C is fetchable after insertMany");
+});