services/sync/tests/unit/test_password_store.js

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

mercurial