Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
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");
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;
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"};
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 }
37 try {
38 applyEnsureNoFailures([recordA, recordB]);
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);
49 _("Bad: " + JSON.stringify(badLogins));
50 _("Good: " + JSON.stringify(goodLogins));
51 _("Count: " + badCount.value + ", " + goodCount.value);
53 do_check_eq(goodCount.value, 1);
54 do_check_eq(badCount.value, 0);
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 }