services/sync/tests/unit/test_password_store.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 Cu.import("resource://services-sync/engines/passwords.js");
michael@0 5 Cu.import("resource://services-sync/service.js");
michael@0 6 Cu.import("resource://services-sync/util.js");
michael@0 7
michael@0 8 function run_test() {
michael@0 9 initTestLogging("Trace");
michael@0 10 Log.repository.getLogger("Sync.Engine.Passwords").level = Log.Level.Trace;
michael@0 11 Log.repository.getLogger("Sync.Store.Passwords").level = Log.Level.Trace;
michael@0 12
michael@0 13 const BOGUS_GUID_A = "zzzzzzzzzzzz";
michael@0 14 const BOGUS_GUID_B = "yyyyyyyyyyyy";
michael@0 15 let recordA = {id: BOGUS_GUID_A,
michael@0 16 hostname: "http://foo.bar.com",
michael@0 17 formSubmitURL: "http://foo.bar.com/baz",
michael@0 18 httpRealm: "secure",
michael@0 19 username: "john",
michael@0 20 password: "smith",
michael@0 21 usernameField: "username",
michael@0 22 passwordField: "password"};
michael@0 23 let recordB = {id: BOGUS_GUID_B,
michael@0 24 hostname: "http://foo.baz.com",
michael@0 25 formSubmitURL: "http://foo.baz.com/baz",
michael@0 26 username: "john",
michael@0 27 password: "smith",
michael@0 28 usernameField: "username",
michael@0 29 passwordField: "password"};
michael@0 30
michael@0 31 let engine = Service.engineManager.get("passwords");
michael@0 32 let store = engine._store;
michael@0 33 function applyEnsureNoFailures(records) {
michael@0 34 do_check_eq(store.applyIncomingBatch(records).length, 0);
michael@0 35 }
michael@0 36
michael@0 37 try {
michael@0 38 applyEnsureNoFailures([recordA, recordB]);
michael@0 39
michael@0 40 // Only the good record makes it to Services.logins.
michael@0 41 let badCount = {};
michael@0 42 let goodCount = {};
michael@0 43 let badLogins = Services.logins.findLogins(badCount, recordA.hostname,
michael@0 44 recordA.formSubmitURL,
michael@0 45 recordA.httpRealm);
michael@0 46 let goodLogins = Services.logins.findLogins(goodCount, recordB.hostname,
michael@0 47 recordB.formSubmitURL, null);
michael@0 48
michael@0 49 _("Bad: " + JSON.stringify(badLogins));
michael@0 50 _("Good: " + JSON.stringify(goodLogins));
michael@0 51 _("Count: " + badCount.value + ", " + goodCount.value);
michael@0 52
michael@0 53 do_check_eq(goodCount.value, 1);
michael@0 54 do_check_eq(badCount.value, 0);
michael@0 55
michael@0 56 do_check_true(!!store.getAllIDs()[BOGUS_GUID_B]);
michael@0 57 do_check_true(!store.getAllIDs()[BOGUS_GUID_A]);
michael@0 58 } finally {
michael@0 59 store.wipe();
michael@0 60 }
michael@0 61 }

mercurial