michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Cu.import("resource://services-sync/engines/passwords.js"); michael@0: Cu.import("resource://services-sync/service.js"); michael@0: Cu.import("resource://services-sync/util.js"); michael@0: michael@0: function run_test() { michael@0: initTestLogging("Trace"); michael@0: Log.repository.getLogger("Sync.Engine.Passwords").level = Log.Level.Trace; michael@0: Log.repository.getLogger("Sync.Store.Passwords").level = Log.Level.Trace; michael@0: michael@0: const BOGUS_GUID_A = "zzzzzzzzzzzz"; michael@0: const BOGUS_GUID_B = "yyyyyyyyyyyy"; michael@0: let recordA = {id: BOGUS_GUID_A, michael@0: hostname: "http://foo.bar.com", michael@0: formSubmitURL: "http://foo.bar.com/baz", michael@0: httpRealm: "secure", michael@0: username: "john", michael@0: password: "smith", michael@0: usernameField: "username", michael@0: passwordField: "password"}; michael@0: let recordB = {id: BOGUS_GUID_B, michael@0: hostname: "http://foo.baz.com", michael@0: formSubmitURL: "http://foo.baz.com/baz", michael@0: username: "john", michael@0: password: "smith", michael@0: usernameField: "username", michael@0: passwordField: "password"}; michael@0: michael@0: let engine = Service.engineManager.get("passwords"); michael@0: let store = engine._store; michael@0: function applyEnsureNoFailures(records) { michael@0: do_check_eq(store.applyIncomingBatch(records).length, 0); michael@0: } michael@0: michael@0: try { michael@0: applyEnsureNoFailures([recordA, recordB]); michael@0: michael@0: // Only the good record makes it to Services.logins. michael@0: let badCount = {}; michael@0: let goodCount = {}; michael@0: let badLogins = Services.logins.findLogins(badCount, recordA.hostname, michael@0: recordA.formSubmitURL, michael@0: recordA.httpRealm); michael@0: let goodLogins = Services.logins.findLogins(goodCount, recordB.hostname, michael@0: recordB.formSubmitURL, null); michael@0: michael@0: _("Bad: " + JSON.stringify(badLogins)); michael@0: _("Good: " + JSON.stringify(goodLogins)); michael@0: _("Count: " + badCount.value + ", " + goodCount.value); michael@0: michael@0: do_check_eq(goodCount.value, 1); michael@0: do_check_eq(badCount.value, 0); michael@0: michael@0: do_check_true(!!store.getAllIDs()[BOGUS_GUID_B]); michael@0: do_check_true(!store.getAllIDs()[BOGUS_GUID_A]); michael@0: } finally { michael@0: store.wipe(); michael@0: } michael@0: }