diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /services/sync/tests/unit/test_password_tracker.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'services/sync/tests/unit/test_password_tracker.js')
-rw-r--r-- | services/sync/tests/unit/test_password_tracker.js | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/services/sync/tests/unit/test_password_tracker.js b/services/sync/tests/unit/test_password_tracker.js new file mode 100644 index 000000000..09ca141a6 --- /dev/null +++ b/services/sync/tests/unit/test_password_tracker.js @@ -0,0 +1,101 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +Cu.import("resource://services-sync/constants.js"); +Cu.import("resource://services-sync/engines/passwords.js"); +Cu.import("resource://services-sync/engines.js"); +Cu.import("resource://services-sync/service.js"); +Cu.import("resource://services-sync/util.js"); + +Service.engineManager.register(PasswordEngine); +var engine = Service.engineManager.get("passwords"); +var store = engine._store; +var tracker = engine._tracker; + +// Don't do asynchronous writes. +tracker.persistChangedIDs = false; + +function run_test() { + initTestLogging("Trace"); + run_next_test(); +} + +add_test(function test_tracking() { + let recordNum = 0; + + _("Verify we've got an empty tracker to work with."); + do_check_empty(tracker.changedIDs); + + function createPassword() { + _("RECORD NUM: " + recordNum); + let record = {id: "GUID" + recordNum, + hostname: "http://foo.bar.com", + formSubmitURL: "http://foo.bar.com/baz", + username: "john" + recordNum, + password: "smith", + usernameField: "username", + passwordField: "password"}; + recordNum++; + let login = store._nsLoginInfoFromRecord(record); + Services.logins.addLogin(login); + } + + try { + _("Create a password record. Won't show because we haven't started tracking yet"); + createPassword(); + do_check_empty(tracker.changedIDs); + do_check_eq(tracker.score, 0); + + _("Tell the tracker to start tracking changes."); + Svc.Obs.notify("weave:engine:start-tracking"); + createPassword(); + do_check_attribute_count(tracker.changedIDs, 1); + do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE); + + _("Notifying twice won't do any harm."); + Svc.Obs.notify("weave:engine:start-tracking"); + createPassword(); + do_check_attribute_count(tracker.changedIDs, 2); + do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE * 2); + + _("Let's stop tracking again."); + tracker.clearChangedIDs(); + tracker.resetScore(); + Svc.Obs.notify("weave:engine:stop-tracking"); + createPassword(); + do_check_empty(tracker.changedIDs); + do_check_eq(tracker.score, 0); + + _("Notifying twice won't do any harm."); + Svc.Obs.notify("weave:engine:stop-tracking"); + createPassword(); + do_check_empty(tracker.changedIDs); + do_check_eq(tracker.score, 0); + + } finally { + _("Clean up."); + store.wipe(); + tracker.clearChangedIDs(); + tracker.resetScore(); + Svc.Obs.notify("weave:engine:stop-tracking"); + run_next_test(); + } +}); + +add_test(function test_onWipe() { + _("Verify we've got an empty tracker to work with."); + do_check_empty(tracker.changedIDs); + do_check_eq(tracker.score, 0); + + try { + _("A store wipe should increment the score"); + Svc.Obs.notify("weave:engine:start-tracking"); + store.wipe(); + + do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE); + } finally { + tracker.resetScore(); + Svc.Obs.notify("weave:engine:stop-tracking"); + run_next_test(); + } +}); |