Bug 1443619 - Ignore items with older creation dates that are already flagged for explicit weak upload. r?eoger draft
authorKit Cambridge <kit@yakshaving.ninja>
Tue, 06 Mar 2018 12:20:41 -0800
changeset 763885 d3e6d83418fad5de59708b389306b0081e94cc7a
parent 763861 971db612fc1adf2799e33319bb61e56cbf2f4f10
push id101582
push userbmo:kit@mozilla.com
push dateTue, 06 Mar 2018 20:25:47 +0000
reviewerseoger
bugs1443619
milestone60.0a1
Bug 1443619 - Ignore items with older creation dates that are already flagged for explicit weak upload. r?eoger MozReview-Commit-ID: 5Sgn9WLebv2
toolkit/components/places/SyncedBookmarksMirror.jsm
toolkit/components/places/tests/sync/test_bookmark_explicit_weakupload.js
--- a/toolkit/components/places/SyncedBookmarksMirror.jsm
+++ b/toolkit/components/places/SyncedBookmarksMirror.jsm
@@ -1489,17 +1489,17 @@ class SyncedBookmarksMirror {
         WHERE b.guid IN (${new Array(chunk.length).fill("?").join(",")})`,
         chunk);
     }
 
     // Stage remotely changed items with older local creation dates. These are
     // tracked "weakly": if the upload is interrupted or fails, we won't
     // reupload the record on the next sync.
     await this.db.execute(`
-      INSERT INTO itemsToWeaklyReupload(id)
+      INSERT OR IGNORE INTO itemsToWeaklyReupload(id)
       SELECT b.id FROM moz_bookmarks b
       JOIN mergeStates r ON r.mergedGuid = b.guid
       JOIN items v ON v.guid = r.mergedGuid
       WHERE r.valueState = :valueState AND
             b.dateAdded < v.dateAdded`,
       { valueState: BookmarkMergeState.TYPE.REMOTE });
 
     // Stage remaining locally changed items for upload.
--- a/toolkit/components/places/tests/sync/test_bookmark_explicit_weakupload.js
+++ b/toolkit/components/places/tests/sync/test_bookmark_explicit_weakupload.js
@@ -32,8 +32,78 @@ add_task(async function test_explicit_we
 
   ok("mozBmk______" in changesToUpload);
   equal(changesToUpload.mozBmk______.counter, 0);
 
   await buf.finalize();
   await PlacesUtils.bookmarks.eraseEverything();
   await PlacesSyncUtils.bookmarks.reset();
 });
+
+add_task(async function test_explicit_weakupload_with_dateAdded() {
+  let buf = await openMirror("explicit_weakupload_with_dateAdded");
+
+  info("Set up mirror");
+  let dateAdded = new Date();
+  await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.menuGuid,
+    children: [{
+      guid: "mozBmk______",
+      url: "https://mozilla.org",
+      title: "Mozilla",
+      dateAdded,
+    }],
+  });
+  await buf.store(shuffle([{
+    id: "menu",
+    type: "folder",
+    children: ["mozBmk______"],
+  }, {
+    id: "mozBmk______",
+    type: "bookmark",
+    title: "Mozilla",
+    bmkUri: "https://mozilla.org",
+    dateAdded: dateAdded.getTime(),
+  }]), { needsMerge: false });
+  await PlacesTestUtils.markBookmarksAsSynced();
+
+  info("Make remote change with older date added");
+  await buf.store([{
+    id: "mozBmk______",
+    type: "bookmark",
+    title: "Firefox",
+    bmkUri: "http://getfirefox.com/",
+    dateAdded: dateAdded.getTime() + 5000,
+  }]);
+
+  info("Explicitly request changed item for weak upload");
+  let changesToUpload = await buf.apply({
+    weakUpload: ["mozBmk______"]
+  });
+  deepEqual(changesToUpload, {
+    mozBmk______: {
+      tombstone: false,
+      counter: 0,
+      synced: false,
+      cleartext: {
+        id: "mozBmk______",
+        type: "bookmark",
+        title: "Firefox",
+        bmkUri: "http://getfirefox.com/",
+        parentid: "menu",
+        hasDupe: true,
+        parentName: "menu",
+        dateAdded: dateAdded.getTime(),
+      },
+    },
+  });
+
+  let localInfo = await PlacesUtils.bookmarks.fetch("mozBmk______");
+  equal(localInfo.title, "Firefox", "Should take new title from mirror");
+  equal(localInfo.url.href, "http://getfirefox.com/",
+    "Should take new URL from mirror");
+  equal(localInfo.dateAdded.getTime(), dateAdded.getTime(),
+    "Should keep older local date added");
+
+  await buf.finalize();
+  await PlacesUtils.bookmarks.eraseEverything();
+  await PlacesSyncUtils.bookmarks.reset();
+});