summaryrefslogtreecommitdiffstats
path: root/services/sync/tests/unit/test_prefs_store.js
diff options
context:
space:
mode:
Diffstat (limited to 'services/sync/tests/unit/test_prefs_store.js')
-rw-r--r--services/sync/tests/unit/test_prefs_store.js85
1 files changed, 26 insertions, 59 deletions
diff --git a/services/sync/tests/unit/test_prefs_store.js b/services/sync/tests/unit/test_prefs_store.js
index 9c321bceb..51b220d53 100644
--- a/services/sync/tests/unit/test_prefs_store.js
+++ b/services/sync/tests/unit/test_prefs_store.js
@@ -23,22 +23,25 @@ function makePersona(id) {
}
function run_test() {
- _("Test fixtures.");
- // read our custom prefs file before doing anything.
- Services.prefs.readUserPrefs(do_get_file("prefs_test_prefs_store.js"));
- // Now we've read from this file, any writes the pref service makes will be
- // back to this prefs_test_prefs_store.js directly in the obj dir. This
- // upsets things in confusing ways :) We avoid this by explicitly telling the
- // pref service to use a file in our profile dir.
- let prefFile = do_get_profile();
- prefFile.append("prefs.js");
- Services.prefs.savePrefFile(prefFile);
- Services.prefs.readUserPrefs(prefFile);
-
let store = Service.engineManager.get("prefs")._store;
let prefs = new Preferences();
try {
+ _("Test fixtures.");
+ Svc.Prefs.set("prefs.sync.testing.int", true);
+ Svc.Prefs.set("prefs.sync.testing.string", true);
+ Svc.Prefs.set("prefs.sync.testing.bool", true);
+ Svc.Prefs.set("prefs.sync.testing.dont.change", true);
+ Svc.Prefs.set("prefs.sync.testing.turned.off", false);
+ Svc.Prefs.set("prefs.sync.testing.nonexistent", true);
+
+ prefs.set("testing.int", 123);
+ prefs.set("testing.string", "ohai");
+ prefs.set("testing.bool", true);
+ prefs.set("testing.dont.change", "Please don't change me.");
+ prefs.set("testing.turned.off", "I won't get synced.");
+ prefs.set("testing.not.turned.on", "I won't get synced either!");
+
_("The GUID corresponds to XUL App ID.");
let allIDs = store.getAllIDs();
let ids = Object.keys(allIDs);
@@ -58,22 +61,17 @@ function run_test() {
do_check_eq(record.value["testing.int"], 123);
do_check_eq(record.value["testing.string"], "ohai");
do_check_eq(record.value["testing.bool"], true);
- // non-existing prefs get null as the value
do_check_eq(record.value["testing.nonexistent"], null);
- // as do prefs that have a default value.
- do_check_eq(record.value["testing.default"], null);
do_check_false("testing.turned.off" in record.value);
do_check_false("testing.not.turned.on" in record.value);
- _("Prefs record contains non-default pref sync prefs too.");
- do_check_eq(record.value["services.sync.prefs.sync.testing.int"], null);
- do_check_eq(record.value["services.sync.prefs.sync.testing.string"], null);
- do_check_eq(record.value["services.sync.prefs.sync.testing.bool"], null);
- do_check_eq(record.value["services.sync.prefs.sync.testing.dont.change"], null);
- // but this one is a user_pref so *will* be synced.
+ _("Prefs record contains pref sync prefs too.");
+ do_check_eq(record.value["services.sync.prefs.sync.testing.int"], true);
+ do_check_eq(record.value["services.sync.prefs.sync.testing.string"], true);
+ do_check_eq(record.value["services.sync.prefs.sync.testing.bool"], true);
+ do_check_eq(record.value["services.sync.prefs.sync.testing.dont.change"], true);
do_check_eq(record.value["services.sync.prefs.sync.testing.turned.off"], false);
- do_check_eq(record.value["services.sync.prefs.sync.testing.nonexistent"], null);
- do_check_eq(record.value["services.sync.prefs.sync.testing.default"], null);
+ do_check_eq(record.value["services.sync.prefs.sync.testing.nonexistent"], true);
_("Update some prefs, including one that's to be reset/deleted.");
Svc.Prefs.set("testing.deleteme", "I'm going to be deleted!");
@@ -99,28 +97,28 @@ function run_test() {
// Ensure we don't go to the network to fetch personas and end up leaking
// stuff.
Services.io.offline = true;
- do_check_false(!!prefs.get("lightweightThemes.selectedThemeID"));
+ do_check_false(!!prefs.get("lightweightThemes.isThemeSelected"));
do_check_eq(LightweightThemeManager.currentTheme, null);
let persona1 = makePersona();
let persona2 = makePersona();
let usedThemes = JSON.stringify([persona1, persona2]);
record.value = {
- "lightweightThemes.selectedThemeID": persona1.id,
+ "lightweightThemes.isThemeSelected": true,
"lightweightThemes.usedThemes": usedThemes
};
store.update(record);
- do_check_eq(prefs.get("lightweightThemes.selectedThemeID"), persona1.id);
+ do_check_true(prefs.get("lightweightThemes.isThemeSelected"));
do_check_true(Utils.deepEquals(LightweightThemeManager.currentTheme,
persona1));
_("Disable persona");
record.value = {
- "lightweightThemes.selectedThemeID": null,
+ "lightweightThemes.isThemeSelected": false,
"lightweightThemes.usedThemes": usedThemes
};
store.update(record);
- do_check_false(!!prefs.get("lightweightThemes.selectedThemeID"));
+ do_check_false(prefs.get("lightweightThemes.isThemeSelected"));
do_check_eq(LightweightThemeManager.currentTheme, null);
_("Only the current app's preferences are applied.");
@@ -131,37 +129,6 @@ function run_test() {
store.update(record);
do_check_eq(prefs.get("testing.int"), 42);
- _("The light-weight theme preference is handled correctly.");
- let lastThemeID = undefined;
- let orig_updateLightWeightTheme = store._updateLightWeightTheme;
- store._updateLightWeightTheme = function(themeID) {
- lastThemeID = themeID;
- }
- try {
- record = new PrefRec("prefs", PREFS_GUID);
- record.value = {
- "testing.int": 42,
- };
- store.update(record);
- do_check_true(lastThemeID === undefined,
- "should not have tried to change the theme with an unrelated pref.");
- Services.prefs.setCharPref("lightweightThemes.selectedThemeID", "foo");
- record.value = {
- "lightweightThemes.selectedThemeID": "foo",
- };
- store.update(record);
- do_check_true(lastThemeID === undefined,
- "should not have tried to change the theme when the incoming pref matches current value.");
-
- record.value = {
- "lightweightThemes.selectedThemeID": "bar",
- };
- store.update(record);
- do_check_eq(lastThemeID, "bar",
- "should have tried to change the theme when the incoming pref was different.");
- } finally {
- store._updateLightWeightTheme = orig_updateLightWeightTheme;
- }
} finally {
prefs.resetBranch("");
}