Bug 1031855 - Add test that sync password application does the right thing for duplicates. r?markh
MozReview-Commit-ID: HIrWdzAZmkC
--- 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);
+ }
+
+});