PageRenderTime 12ms CodeModel.GetById 7ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/services/sync/tests/unit/test_password_store.js

http://github.com/zpao/v8monkey
JavaScript | 57 lines | 48 code | 8 blank | 1 comment | 0 complexity | 2533eda88f0027907541e3235d7121d4 MD5 | raw file
 1Cu.import("resource://services-sync/engines/passwords.js");
 2Cu.import("resource://services-sync/util.js");
 3
 4function run_test() {
 5  initTestLogging("Trace");
 6  Log4Moz.repository.getLogger("Sync.Engine.Passwords").level = Log4Moz.Level.Trace;
 7  Log4Moz.repository.getLogger("Sync.Store.Passwords").level = Log4Moz.Level.Trace;
 8
 9  const BOGUS_GUID_A = "zzzzzzzzzzzz";
10  const BOGUS_GUID_B = "yyyyyyyyyyyy";
11  let recordA = {id: BOGUS_GUID_A,
12                  hostname: "http://foo.bar.com",
13                  formSubmitURL: "http://foo.bar.com/baz",
14                  httpRealm: "secure",
15                  username: "john",
16                  password: "smith",
17                  usernameField: "username",
18                  passwordField: "password"};
19  let recordB = {id: BOGUS_GUID_B,
20                  hostname: "http://foo.baz.com",
21                  formSubmitURL: "http://foo.baz.com/baz",
22                  username: "john",
23                  password: "smith",
24                  usernameField: "username",
25                  passwordField: "password"};
26
27  let engine = new PasswordEngine();
28  let store = engine._store;
29  function applyEnsureNoFailures(records) {
30    do_check_eq(store.applyIncomingBatch(records).length, 0);
31  }
32
33  try {
34    applyEnsureNoFailures([recordA, recordB]);
35
36    // Only the good record makes it to Services.logins.
37    let badCount = {};
38    let goodCount = {};
39    let badLogins = Services.logins.findLogins(badCount, recordA.hostname,
40                                               recordA.formSubmitURL,
41                                               recordA.httpRealm);
42    let goodLogins = Services.logins.findLogins(goodCount, recordB.hostname,
43                                                recordB.formSubmitURL, null);
44    
45    _("Bad: " + JSON.stringify(badLogins));
46    _("Good: " + JSON.stringify(goodLogins));
47    _("Count: " + badCount.value + ", " + goodCount.value);
48    
49    do_check_eq(goodCount.value, 1);
50    do_check_eq(badCount.value, 0);
51    
52    do_check_true(!!store.getAllIDs()[BOGUS_GUID_B]);
53    do_check_true(!store.getAllIDs()[BOGUS_GUID_A]);
54  } finally {
55    store.wipe();
56  }
57}