Bug 1031855 - Add test that sync password application does the right thing for duplicates. r?markh draft
authorThom Chiovoloni <tchiovoloni@mozilla.com>
Wed, 07 Mar 2018 13:01:12 -0800
changeset 764493 3640d9b0886eb2e6b45e29078b437279eb1ded54
parent 763903 c7543a3e938d5ec408a7d0c93dc71b40607e7d5b
push id101771
push userbmo:tchiovoloni@mozilla.com
push dateWed, 07 Mar 2018 21:01:31 +0000
reviewersmarkh
bugs1031855
milestone60.0a1
Bug 1031855 - Add test that sync password application does the right thing for duplicates. r?markh MozReview-Commit-ID: HIrWdzAZmkC
services/sync/tests/unit/test_password_engine.js
--- a/services/sync/tests/unit/test_password_engine.js
+++ b/services/sync/tests/unit/test_password_engine.js
@@ -166,8 +166,55 @@ add_task(async function test_password_en
 
     let logins = Services.logins.findLogins({}, "https://mozilla.com", "", "");
     equal(logins[0].password, "n3wpa55",
       "Should update local password for older login");
   } finally {
     await cleanup(engine, server);
   }
 });
+
+add_task(async function test_password_dupe() {
+  let engine = Service.engineManager.get("passwords");
+
+  let server = await serverForFoo(engine);
+  await SyncTestingInfrastructure(server);
+  let collection = server.user("foo").collection("passwords");
+
+  let guid1 = Utils.makeGUID();
+  let guid2 = Utils.makeGUID();
+  let details = {
+    formSubmitURL: "https://www.example.com",
+    hostname: "https://www.example.com",
+    httpRealm: null,
+    username: "foo",
+    password: "bar",
+    usernameField: "username-field",
+    passwordField: "password-field",
+    timeCreated: Date.now(),
+    timePasswordChanged: Date.now(),
+  };
+
+
+  _("Create remote record with same details and guid1");
+  collection.insertRecord(Object.assign({}, details, { id: guid1 }));
+
+  _("Create remote record with guid2");
+  collection.insertRecord(Object.assign({}, details, { id: guid2 }));
+
+  _("Create local record with same details and guid1");
+  await engine._store.create(Object.assign({}, details, { id: guid1 }));
+
+  try {
+    _("Perform sync");
+    await sync_engine_and_validate_telem(engine, false);
+
+    let logins = Services.logins.findLogins({}, "https://www.example.com", "", "");
+
+    equal(logins.length, 1);
+    equal(logins[0].QueryInterface(Ci.nsILoginMetaInfo).guid, guid2);
+    equal(null, collection.payload(guid1));
+
+  } finally {
+    await cleanup(engine, server);
+  }
+
+});