services/sync/tests/unit/test_password_tracker.js

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 Cu.import("resource://services-sync/constants.js");
michael@0 5 Cu.import("resource://services-sync/engines/passwords.js");
michael@0 6 Cu.import("resource://services-sync/engines.js");
michael@0 7 Cu.import("resource://services-sync/service.js");
michael@0 8 Cu.import("resource://services-sync/util.js");
michael@0 9
michael@0 10 Service.engineManager.register(PasswordEngine);
michael@0 11 let engine = Service.engineManager.get("passwords");
michael@0 12 let store = engine._store;
michael@0 13 let tracker = engine._tracker;
michael@0 14
michael@0 15 // Don't do asynchronous writes.
michael@0 16 tracker.persistChangedIDs = false;
michael@0 17
michael@0 18 function run_test() {
michael@0 19 initTestLogging("Trace");
michael@0 20 run_next_test();
michael@0 21 }
michael@0 22
michael@0 23 add_test(function test_tracking() {
michael@0 24 let recordNum = 0;
michael@0 25
michael@0 26 _("Verify we've got an empty tracker to work with.");
michael@0 27 do_check_empty(tracker.changedIDs);
michael@0 28
michael@0 29 function createPassword() {
michael@0 30 _("RECORD NUM: " + recordNum);
michael@0 31 let record = {id: "GUID" + recordNum,
michael@0 32 hostname: "http://foo.bar.com",
michael@0 33 formSubmitURL: "http://foo.bar.com/baz",
michael@0 34 username: "john" + recordNum,
michael@0 35 password: "smith",
michael@0 36 usernameField: "username",
michael@0 37 passwordField: "password"};
michael@0 38 recordNum++;
michael@0 39 let login = store._nsLoginInfoFromRecord(record);
michael@0 40 Services.logins.addLogin(login);
michael@0 41 }
michael@0 42
michael@0 43 try {
michael@0 44 _("Create a password record. Won't show because we haven't started tracking yet");
michael@0 45 createPassword();
michael@0 46 do_check_empty(tracker.changedIDs);
michael@0 47 do_check_eq(tracker.score, 0);
michael@0 48
michael@0 49 _("Tell the tracker to start tracking changes.");
michael@0 50 Svc.Obs.notify("weave:engine:start-tracking");
michael@0 51 createPassword();
michael@0 52 do_check_attribute_count(tracker.changedIDs, 1);
michael@0 53 do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE);
michael@0 54
michael@0 55 _("Notifying twice won't do any harm.");
michael@0 56 Svc.Obs.notify("weave:engine:start-tracking");
michael@0 57 createPassword();
michael@0 58 do_check_attribute_count(tracker.changedIDs, 2);
michael@0 59 do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE * 2);
michael@0 60
michael@0 61 _("Let's stop tracking again.");
michael@0 62 tracker.clearChangedIDs();
michael@0 63 tracker.resetScore();
michael@0 64 Svc.Obs.notify("weave:engine:stop-tracking");
michael@0 65 createPassword();
michael@0 66 do_check_empty(tracker.changedIDs);
michael@0 67 do_check_eq(tracker.score, 0);
michael@0 68
michael@0 69 _("Notifying twice won't do any harm.");
michael@0 70 Svc.Obs.notify("weave:engine:stop-tracking");
michael@0 71 createPassword();
michael@0 72 do_check_empty(tracker.changedIDs);
michael@0 73 do_check_eq(tracker.score, 0);
michael@0 74
michael@0 75 } finally {
michael@0 76 _("Clean up.");
michael@0 77 store.wipe();
michael@0 78 tracker.clearChangedIDs();
michael@0 79 tracker.resetScore();
michael@0 80 Svc.Obs.notify("weave:engine:stop-tracking");
michael@0 81 run_next_test();
michael@0 82 }
michael@0 83 });
michael@0 84
michael@0 85 add_test(function test_onWipe() {
michael@0 86 _("Verify we've got an empty tracker to work with.");
michael@0 87 do_check_empty(tracker.changedIDs);
michael@0 88 do_check_eq(tracker.score, 0);
michael@0 89
michael@0 90 try {
michael@0 91 _("A store wipe should increment the score");
michael@0 92 Svc.Obs.notify("weave:engine:start-tracking");
michael@0 93 store.wipe();
michael@0 94
michael@0 95 do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE);
michael@0 96 } finally {
michael@0 97 tracker.resetScore();
michael@0 98 Svc.Obs.notify("weave:engine:stop-tracking");
michael@0 99 run_next_test();
michael@0 100 }
michael@0 101 });

mercurial