/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

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