diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /services/sync/tests/unit/test_prefs_tracker.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream/115.8.0esr.tar.xz firefox-esr-upstream/115.8.0esr.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'services/sync/tests/unit/test_prefs_tracker.js')
-rw-r--r-- | services/sync/tests/unit/test_prefs_tracker.js | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/services/sync/tests/unit/test_prefs_tracker.js b/services/sync/tests/unit/test_prefs_tracker.js new file mode 100644 index 0000000000..9840d287b9 --- /dev/null +++ b/services/sync/tests/unit/test_prefs_tracker.js @@ -0,0 +1,92 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { Preferences } = ChromeUtils.importESModule( + "resource://gre/modules/Preferences.sys.mjs" +); +const { Service } = ChromeUtils.importESModule( + "resource://services-sync/service.sys.mjs" +); + +add_task(async function run_test() { + let engine = Service.engineManager.get("prefs"); + let tracker = engine._tracker; + + let prefs = new Preferences(); + + try { + _("tracker.modified corresponds to preference."); + Assert.equal(Svc.Prefs.get("engine.prefs.modified"), undefined); + Assert.ok(!tracker.modified); + + tracker.modified = true; + Assert.equal(Svc.Prefs.get("engine.prefs.modified"), true); + Assert.ok(tracker.modified); + + _("Engine's getChangedID() just returns the one GUID we have."); + let changedIDs = await engine.getChangedIDs(); + let ids = Object.keys(changedIDs); + Assert.equal(ids.length, 1); + Assert.equal(ids[0], CommonUtils.encodeBase64URL(Services.appinfo.ID)); + + Svc.Prefs.set("engine.prefs.modified", false); + Assert.ok(!tracker.modified); + + _("No modified state, so no changed IDs."); + do_check_empty(await engine.getChangedIDs()); + + _("Initial score is 0"); + Assert.equal(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." + ); + Assert.equal(tracker.score, 0); + + _("Tell the tracker to start tracking changes."); + tracker.start(); + prefs.set("testing.int", 23); + await tracker.asyncObserver.promiseObserversComplete(); + Assert.equal(tracker.score, SCORE_INCREMENT_XLARGE); + Assert.equal(tracker.modified, true); + + _("Clearing changed IDs reset modified status."); + await tracker.clearChangedIDs(); + Assert.equal(tracker.modified, false); + + _("Resetting a pref ups the score, too."); + prefs.reset("testing.int"); + await tracker.asyncObserver.promiseObserversComplete(); + Assert.equal(tracker.score, SCORE_INCREMENT_XLARGE * 2); + Assert.equal(tracker.modified, true); + await tracker.clearChangedIDs(); + + _("So does changing a pref sync pref."); + Svc.Prefs.set("prefs.sync.testing.int", false); + await tracker.asyncObserver.promiseObserversComplete(); + Assert.equal(tracker.score, SCORE_INCREMENT_XLARGE * 3); + Assert.equal(tracker.modified, true); + await tracker.clearChangedIDs(); + + _( + "Now that the pref sync pref has been flipped, changes to it won't be picked up." + ); + prefs.set("testing.int", 42); + await tracker.asyncObserver.promiseObserversComplete(); + Assert.equal(tracker.score, SCORE_INCREMENT_XLARGE * 3); + Assert.equal(tracker.modified, false); + await tracker.clearChangedIDs(); + + _("Changing some other random pref won't do anything."); + prefs.set("testing.other", "blergh"); + await tracker.asyncObserver.promiseObserversComplete(); + Assert.equal(tracker.score, SCORE_INCREMENT_XLARGE * 3); + Assert.equal(tracker.modified, false); + } finally { + await tracker.stop(); + prefs.resetBranch(""); + } +}); |