2010-11-23 21:21:37 -08:00
|
|
|
Cu.import("resource://services-sync/engines/prefs.js");
|
|
|
|
Cu.import("resource://services-sync/util.js");
|
2011-06-16 12:12:48 -07:00
|
|
|
Cu.import("resource://services-sync/constants.js");
|
2012-04-17 16:45:32 -07:00
|
|
|
Cu.import("resource://services-common/utils.js");
|
2012-04-05 23:26:06 -07:00
|
|
|
Cu.import("resource://services-common/preferences.js");
|
2010-11-23 21:21:37 -08:00
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
let engine = new PrefsEngine();
|
|
|
|
let tracker = engine._tracker;
|
|
|
|
let prefs = new Preferences();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
_("tracker.modified corresponds to preference.");
|
|
|
|
do_check_eq(Svc.Prefs.get("engine.prefs.modified"), undefined);
|
|
|
|
do_check_false(tracker.modified);
|
|
|
|
|
|
|
|
tracker.modified = true;
|
|
|
|
do_check_eq(Svc.Prefs.get("engine.prefs.modified"), true);
|
|
|
|
do_check_true(tracker.modified);
|
|
|
|
|
|
|
|
_("Engine's getChangedID() just returns the one GUID we have.");
|
|
|
|
let changedIDs = engine.getChangedIDs();
|
2011-08-19 17:17:58 -07:00
|
|
|
let ids = Object.keys(changedIDs);
|
2010-11-23 21:21:37 -08:00
|
|
|
do_check_eq(ids.length, 1);
|
2012-04-17 15:42:33 -07:00
|
|
|
do_check_eq(ids[0], CommonUtils.encodeBase64URL(Services.appinfo.ID));
|
2010-11-23 21:21:37 -08:00
|
|
|
|
|
|
|
Svc.Prefs.set("engine.prefs.modified", false);
|
|
|
|
do_check_false(tracker.modified);
|
|
|
|
|
|
|
|
_("No modified state, so no changed IDs.");
|
2011-08-19 17:17:58 -07:00
|
|
|
do_check_empty(engine.getChangedIDs());
|
2010-11-23 21:21:37 -08:00
|
|
|
|
|
|
|
_("Initial score is 0");
|
|
|
|
do_check_eq(tracker.score, 0);
|
|
|
|
|
|
|
|
_("Test fixtures.");
|
|
|
|
Svc.Prefs.set("prefs.sync.testing.int", true);
|
|
|
|
|
|
|
|
_("Test fixtures haven't upped the tracker score yet because it hasn't started tracking yet.");
|
|
|
|
do_check_eq(tracker.score, 0);
|
|
|
|
|
|
|
|
_("Tell the tracker to start tracking changes.");
|
|
|
|
Svc.Obs.notify("weave:engine:start-tracking");
|
|
|
|
prefs.set("testing.int", 23);
|
2011-06-16 12:12:48 -07:00
|
|
|
do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE);
|
2010-11-23 21:21:37 -08:00
|
|
|
do_check_eq(tracker.modified, true);
|
|
|
|
|
|
|
|
_("Clearing changed IDs reset modified status.");
|
|
|
|
tracker.clearChangedIDs();
|
|
|
|
do_check_eq(tracker.modified, false);
|
|
|
|
|
|
|
|
_("Resetting a pref ups the score, too.");
|
|
|
|
prefs.reset("testing.int");
|
2011-06-16 12:12:48 -07:00
|
|
|
do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE * 2);
|
2010-11-23 21:21:37 -08:00
|
|
|
do_check_eq(tracker.modified, true);
|
|
|
|
tracker.clearChangedIDs();
|
|
|
|
|
|
|
|
_("So does changing a pref sync pref.");
|
|
|
|
Svc.Prefs.set("prefs.sync.testing.int", false);
|
2011-06-16 12:12:48 -07:00
|
|
|
do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE * 3);
|
2010-11-23 21:21:37 -08:00
|
|
|
do_check_eq(tracker.modified, true);
|
|
|
|
tracker.clearChangedIDs();
|
|
|
|
|
|
|
|
_("Now that the pref sync pref has been flipped, changes to it won't be picked up.");
|
|
|
|
prefs.set("testing.int", 42);
|
2011-06-16 12:12:48 -07:00
|
|
|
do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE * 3);
|
2010-11-23 21:21:37 -08:00
|
|
|
do_check_eq(tracker.modified, false);
|
|
|
|
tracker.clearChangedIDs();
|
|
|
|
|
|
|
|
_("Changing some other random pref won't do anything.");
|
|
|
|
prefs.set("testing.other", "blergh");
|
2011-06-16 12:12:48 -07:00
|
|
|
do_check_eq(tracker.score, SCORE_INCREMENT_XLARGE * 3);
|
2010-11-23 21:21:37 -08:00
|
|
|
do_check_eq(tracker.modified, false);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
Svc.Obs.notify("weave:engine:stop-tracking");
|
|
|
|
prefs.resetBranch("");
|
2012-07-12 16:28:53 -07:00
|
|
|
if (tracker._lazySave) {
|
|
|
|
tracker._lazySave.clear();
|
|
|
|
}
|
2010-11-23 21:21:37 -08:00
|
|
|
}
|
|
|
|
}
|