Bug 1337993 - Ensure we mark all current bookmarks for reupload when bookmark engine enabled state changes. r=kitcambridge, a=lizzard
authorThom Chiovoloni <tchiovoloni@mozilla.com>
Mon, 13 Feb 2017 14:28:06 -0500
changeset 379006 fc91a19ee809ffdfa7a7d65a22e0a7732ca5c6e0
parent 379005 d5f74115c95b1e3586e20333098e3050d7f9a641
child 379007 5094bc55377553ea338e993f3d24508440a6ea67
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskitcambridge, lizzard
bugs1337993
milestone53.0
Bug 1337993 - Ensure we mark all current bookmarks for reupload when bookmark engine enabled state changes. r=kitcambridge, a=lizzard MozReview-Commit-ID: 4gOmqrzUr77
services/sync/modules/engines/bookmarks.js
services/sync/tests/unit/test_bookmark_decline_undecline.js
services/sync/tests/unit/xpcshell.ini
--- a/services/sync/modules/engines/bookmarks.js
+++ b/services/sync/modules/engines/bookmarks.js
@@ -590,18 +590,18 @@ BookmarksEngine.prototype = {
     let changes = this._modified.changes;
     Async.promiseSpinningly(PlacesSyncUtils.bookmarks.pushChanges(changes));
   },
 
   _deleteId(id) {
     this._noteDeletedId(id);
   },
 
-  resetClient() {
-    SyncEngine.prototype.resetClient.call(this);
+  _resetClient() {
+    SyncEngine.prototype._resetClient.call(this);
     Async.promiseSpinningly(PlacesSyncUtils.bookmarks.reset());
   },
 
   // Called when _findDupe returns a dupe item and the engine has decided to
   // switch the existing item to the new incoming item.
   _switchItemToDupe(localDupeGUID, incomingItem) {
     let newChanges = Async.promiseSpinningly(PlacesSyncUtils.bookmarks.dedupe(
       localDupeGUID, incomingItem.id, incomingItem.parentid));
new file mode 100644
--- /dev/null
+++ b/services/sync/tests/unit/test_bookmark_decline_undecline.js
@@ -0,0 +1,104 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+Cu.import("resource://gre/modules/PlacesUtils.jsm");
+Cu.import("resource://gre/modules/PlacesSyncUtils.jsm");
+Cu.import("resource://gre/modules/BookmarkJSONUtils.jsm");
+Cu.import("resource://gre/modules/Log.jsm");
+Cu.import("resource://services-sync/constants.js");
+Cu.import("resource://services-sync/engines.js");
+Cu.import("resource://services-sync/engines/bookmarks.js");
+Cu.import("resource://services-sync/service.js");
+Cu.import("resource://services-sync/util.js");
+Cu.import("resource://testing-common/services/sync/utils.js");
+
+initTestLogging("Trace");
+
+Service.engineManager.register(BookmarksEngine);
+
+function serverForFoo(engine) {
+  // The bookmarks engine *always* tracks changes, meaning we might try
+  // and sync due to the bookmarks we ourselves create! Worse, because we
+  // do an engine sync only, there's no locking - so we end up with multiple
+  // syncs running. Neuter that by making the threshold very large.
+  Service.scheduler.syncThreshold = 10000000;
+  let clientsEngine = Service.clientsEngine;
+  return serverForUsers({"foo": "password"}, {
+    meta: {
+      global: {
+        syncID: Service.syncID,
+        storageVersion: STORAGE_VERSION,
+        engines: {
+          clients: {
+            version: clientsEngine.version,
+            syncID: clientsEngine.syncID,
+          },
+          bookmarks: {
+            version: engine.version,
+            syncID: engine.syncID,
+          },
+        },
+      },
+    },
+    crypto: {
+      keys: encryptPayload({
+        id: "keys",
+        // Generate a fake default key bundle to avoid resetting the client
+        // before the first sync.
+        default: [
+          Svc.Crypto.generateRandomKey(),
+          Svc.Crypto.generateRandomKey(),
+        ],
+      }),
+    },
+    bookmarks: {}
+  });
+}
+
+// A stored reference to the collection won't be valid after disabling.
+function getBookmarkWBO(server, guid) {
+  let coll = server.user("foo").collection("bookmarks");
+  if (!coll) {
+    return null;
+  }
+  return coll.wbo(guid);
+}
+
+add_task(async function test_decline_undecline() {
+  let engine = Service.engineManager.get("bookmarks");
+  let server = serverForFoo(engine);
+  await SyncTestingInfrastructure(server);
+
+  try {
+    let bzGuid = "999999999999";
+    await PlacesSyncUtils.bookmarks.insert({
+      kind: PlacesSyncUtils.bookmarks.KINDS.BOOKMARK,
+      syncId: bzGuid,
+      parentSyncId: "menu",
+      url: "https://bugzilla.mozilla.org",
+
+    });
+
+    ok(!getBookmarkWBO(server, bzGuid), "Shouldn't have been uploaded yet");
+    Service.sync();
+    ok(getBookmarkWBO(server, bzGuid), "Should be present on server");
+
+    engine.enabled = false;
+    Service.sync();
+    ok(!getBookmarkWBO(server, bzGuid), "Shouldn't be present on server anymore");
+
+    engine.enabled = true;
+    Service.sync();
+    ok(getBookmarkWBO(server, bzGuid), "Should be present on server again");
+
+  } finally {
+    await PlacesSyncUtils.bookmarks.reset();
+    await promiseStopServer(server);
+  }
+});
+
+function run_test() {
+  initTestLogging("Trace");
+  generateNewKeys(Service.collectionKeys);
+  run_next_test();
+}
--- a/services/sync/tests/unit/xpcshell.ini
+++ b/services/sync/tests/unit/xpcshell.ini
@@ -150,16 +150,17 @@ tags = addons
 [test_bookmark_invalid.js]
 [test_bookmark_legacy_microsummaries_support.js]
 [test_bookmark_livemarks.js]
 [test_bookmark_order.js]
 [test_bookmark_places_query_rewriting.js]
 [test_bookmark_record.js]
 [test_bookmark_smart_bookmarks.js]
 [test_bookmark_store.js]
+[test_bookmark_decline_undecline.js]
 # Too many intermittent "ASSERTION: thread pool wasn't shutdown: '!mPool'" (bug 804479)
 skip-if = debug
 [test_bookmark_tracker.js]
 requesttimeoutfactor = 4
 [test_bookmark_validator.js]
 [test_clients_engine.js]
 [test_clients_escape.js]
 [test_extension_storage_crypto.js]