services/sync/tests/unit/test_password_store.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/services/sync/tests/unit/test_password_store.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,61 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +Cu.import("resource://services-sync/engines/passwords.js");
     1.8 +Cu.import("resource://services-sync/service.js");
     1.9 +Cu.import("resource://services-sync/util.js");
    1.10 +
    1.11 +function run_test() {
    1.12 +  initTestLogging("Trace");
    1.13 +  Log.repository.getLogger("Sync.Engine.Passwords").level = Log.Level.Trace;
    1.14 +  Log.repository.getLogger("Sync.Store.Passwords").level = Log.Level.Trace;
    1.15 +
    1.16 +  const BOGUS_GUID_A = "zzzzzzzzzzzz";
    1.17 +  const BOGUS_GUID_B = "yyyyyyyyyyyy";
    1.18 +  let recordA = {id: BOGUS_GUID_A,
    1.19 +                  hostname: "http://foo.bar.com",
    1.20 +                  formSubmitURL: "http://foo.bar.com/baz",
    1.21 +                  httpRealm: "secure",
    1.22 +                  username: "john",
    1.23 +                  password: "smith",
    1.24 +                  usernameField: "username",
    1.25 +                  passwordField: "password"};
    1.26 +  let recordB = {id: BOGUS_GUID_B,
    1.27 +                  hostname: "http://foo.baz.com",
    1.28 +                  formSubmitURL: "http://foo.baz.com/baz",
    1.29 +                  username: "john",
    1.30 +                  password: "smith",
    1.31 +                  usernameField: "username",
    1.32 +                  passwordField: "password"};
    1.33 +
    1.34 +  let engine = Service.engineManager.get("passwords");
    1.35 +  let store = engine._store;
    1.36 +  function applyEnsureNoFailures(records) {
    1.37 +    do_check_eq(store.applyIncomingBatch(records).length, 0);
    1.38 +  }
    1.39 +
    1.40 +  try {
    1.41 +    applyEnsureNoFailures([recordA, recordB]);
    1.42 +
    1.43 +    // Only the good record makes it to Services.logins.
    1.44 +    let badCount = {};
    1.45 +    let goodCount = {};
    1.46 +    let badLogins = Services.logins.findLogins(badCount, recordA.hostname,
    1.47 +                                               recordA.formSubmitURL,
    1.48 +                                               recordA.httpRealm);
    1.49 +    let goodLogins = Services.logins.findLogins(goodCount, recordB.hostname,
    1.50 +                                                recordB.formSubmitURL, null);
    1.51 +
    1.52 +    _("Bad: " + JSON.stringify(badLogins));
    1.53 +    _("Good: " + JSON.stringify(goodLogins));
    1.54 +    _("Count: " + badCount.value + ", " + goodCount.value);
    1.55 +
    1.56 +    do_check_eq(goodCount.value, 1);
    1.57 +    do_check_eq(badCount.value, 0);
    1.58 +
    1.59 +    do_check_true(!!store.getAllIDs()[BOGUS_GUID_B]);
    1.60 +    do_check_true(!store.getAllIDs()[BOGUS_GUID_A]);
    1.61 +  } finally {
    1.62 +    store.wipe();
    1.63 +  }
    1.64 +}

mercurial