services/sync/tests/unit/test_prefs_tracker.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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://gre/modules/Preferences.jsm");
michael@0 5 Cu.import("resource://services-common/utils.js");
michael@0 6 Cu.import("resource://services-sync/constants.js");
michael@0 7 Cu.import("resource://services-sync/engines/prefs.js");
michael@0 8 Cu.import("resource://services-sync/service.js");
michael@0 9 Cu.import("resource://services-sync/util.js");
michael@0 10
michael@0 11 function run_test() {
michael@0 12 let engine = Service.engineManager.get("prefs");
michael@0 13 let tracker = engine._tracker;
michael@0 14
michael@0 15 // Don't write out by default.
michael@0 16 tracker.persistChangedIDs = false;
michael@0 17
michael@0 18 let prefs = new Preferences();
michael@0 19
michael@0 20 try {
michael@0 21
michael@0 22 _("tracker.modified corresponds to preference.");
michael@0 23 do_check_eq(Svc.Prefs.get("engine.prefs.modified"), undefined);
michael@0 24 do_check_false(tracker.modified);
michael@0 25
michael@0 26 tracker.modified = true;
michael@0 27 do_check_eq(Svc.Prefs.get("engine.prefs.modified"), true);
michael@0 28 do_check_true(tracker.modified);
michael@0 29
michael@0 30 _("Engine's getChangedID() just returns the one GUID we have.");
michael@0 31 let changedIDs = engine.getChangedIDs();
michael@0 32 let ids = Object.keys(changedIDs);
michael@0 33 do_check_eq(ids.length, 1);
michael@0 34 do_check_eq(ids[0], CommonUtils.encodeBase64URL(Services.appinfo.ID));
michael@0 35
michael@0 36 Svc.Prefs.set("engine.prefs.modified", false);
michael@0 37 do_check_false(tracker.modified);
michael@0 38
michael@0 39 _("No modified state, so no changed IDs.");
michael@0 40 do_check_empty(engine.getChangedIDs());
michael@0 41
michael@0 42 _("Initial score is 0");
michael@0 43 do_check_eq(tracker.score, 0);
michael@0 44
michael@0 45 _("Test fixtures.");
michael@0 46 Svc.Prefs.set("prefs.sync.testing.int", true);
michael@0 47
michael@0 48 _("Test fixtures haven't upped the tracker score yet because it hasn't started tracking yet.");
michael@0 49 do_check_eq(tracker.score, 0);
michael@0 50
michael@0 51 _("Tell the tracker to start tracking changes.");
michael@0 52 Svc.Obs.notify("weave:engine:start-tracking");
michael@0 53 prefs.set("testing.int", 23);
michael@0 54 do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE);
michael@0 55 do_check_eq(tracker.modified, true);
michael@0 56
michael@0 57 _("Clearing changed IDs reset modified status.");
michael@0 58 tracker.clearChangedIDs();
michael@0 59 do_check_eq(tracker.modified, false);
michael@0 60
michael@0 61 _("Resetting a pref ups the score, too.");
michael@0 62 prefs.reset("testing.int");
michael@0 63 do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE * 2);
michael@0 64 do_check_eq(tracker.modified, true);
michael@0 65 tracker.clearChangedIDs();
michael@0 66
michael@0 67 _("So does changing a pref sync pref.");
michael@0 68 Svc.Prefs.set("prefs.sync.testing.int", false);
michael@0 69 do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE * 3);
michael@0 70 do_check_eq(tracker.modified, true);
michael@0 71 tracker.clearChangedIDs();
michael@0 72
michael@0 73 _("Now that the pref sync pref has been flipped, changes to it won't be picked up.");
michael@0 74 prefs.set("testing.int", 42);
michael@0 75 do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE * 3);
michael@0 76 do_check_eq(tracker.modified, false);
michael@0 77 tracker.clearChangedIDs();
michael@0 78
michael@0 79 _("Changing some other random pref won't do anything.");
michael@0 80 prefs.set("testing.other", "blergh");
michael@0 81 do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE * 3);
michael@0 82 do_check_eq(tracker.modified, false);
michael@0 83
michael@0 84 } finally {
michael@0 85 Svc.Obs.notify("weave:engine:stop-tracking");
michael@0 86 prefs.resetBranch("");
michael@0 87 }
michael@0 88 }

mercurial