Bug 1321571 - ensureKeysFor_posts_new_keys pushes keys too many times, r?markh draft
authorEthan Glasser-Camp <eglassercamp@mozilla.com>
Wed, 28 Dec 2016 15:38:01 -0500
changeset 454275 9b10d513ccf147042a5dd07ed7dbf465a87307ce
parent 454222 a6d29e9432f5f88a941c0ea5284cb082f34bd097
child 540670 a7e692780db669e6478b8010d6d23b4604af881e
push id39888
push usereglassercamp@mozilla.com
push dateWed, 28 Dec 2016 20:38:31 +0000
reviewersmarkh
bugs1321571
milestone53.0a1
Bug 1321571 - ensureKeysFor_posts_new_keys pushes keys too many times, r?markh The kinto.js library assumes that all records coming from the server will have a last_modified date, and copy it before checking for equality. That date was missing here because I mocked a fake Kinto server, so the code to check that the conflict was resolved successfully got confused. MozReview-Commit-ID: G4MAIAv1fJf
toolkit/components/extensions/test/xpcshell/test_ext_storage_sync.js
--- a/toolkit/components/extensions/test/xpcshell/test_ext_storage_sync.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_storage_sync.js
@@ -491,29 +491,26 @@ add_task(function* ensureKeysFor_posts_n
       assertPostedNewRecord(post);
       const body = yield assertPostedEncryptedKeys(post);
       ok(body.keys.collections[extensionId], `keys object should have a key for ${extensionId}`);
 
       // Try adding another key to make sure that the first post was
       // OK, even on a new profile.
       yield cryptoCollection._clear();
       server.clearPosts();
-      // Restore the first posted keyring
-      server.addRecordInPast("storage-sync-crypto", post.body.data);
+      // Restore the first posted keyring, but add a last_modified date
+      const firstPostedKeyring = Object.assign({}, post.body.data, {last_modified: server.etag});
+      server.addRecordInPast("storage-sync-crypto", firstPostedKeyring);
       const extensionId2 = uuid();
       newKeys = yield ExtensionStorageSync.ensureKeysFor([extensionId2]);
       ok(newKeys.hasKeysFor([extensionId]), `didn't forget key for ${extensionId}`);
       ok(newKeys.hasKeysFor([extensionId2]), `new key generated for ${extensionId2}`);
 
       posts = server.getPosts();
-      // FIXME: some kind of bug where we try to repush the
-      // server_wins version multiple times in a single sync. We
-      // actually push 5 times as of this writing.
-      // See bug 1321571.
-      // equal(posts.length, 1);
+      equal(posts.length, 1);
       const newPost = posts[posts.length - 1];
       const newBody = yield assertPostedEncryptedKeys(newPost);
       ok(newBody.keys.collections[extensionId], `keys object should have a key for ${extensionId}`);
       ok(newBody.keys.collections[extensionId2], `keys object should have a key for ${extensionId2}`);
 
     });
   });
 });