Bug 1309384 - fix override of default preference;r=tromey
MozReview-Commit-ID: 9z9lV6dpXHL
--- a/devtools/client/shared/shim/Services.js
+++ b/devtools/client/shared/shim/Services.js
@@ -241,17 +241,17 @@ PrefBranch.prototype = {
_saveAndNotify: function () {
let store = {
type: this._type,
defaultValue: this._defaultValue,
hasUserValue: this._hasUserValue,
userValue: this._userValue,
};
- localStorage.setItem(PREFIX + this.fullName, JSON.stringify(store));
+ localStorage.setItem(PREFIX + this._fullName, JSON.stringify(store));
this._parent._notify(this._name);
},
/**
* Change this preference's value without writing it back to local
* storage. This is used to handle changes to local storage that
* were made externally.
*
@@ -336,18 +336,19 @@ PrefBranch.prototype = {
* @param {Array} branchList an array of strings, one per component
* of the branch to be created
* @return {PrefBranch} the new branch
*/
_createBranch: function (branchList) {
let parent = this;
for (let branch of branchList) {
if (!parent._children[branch]) {
- parent._children[branch] = new PrefBranch(parent, branch,
- parent.root + "." + branch);
+ let isParentRoot = !parent.parent;
+ let branchName = (isParentRoot ? "" : parent.root + ".") + branch;
+ parent._children[branch] = new PrefBranch(parent, branch, branchName);
}
parent = parent._children[branch];
}
return parent;
},
/**
* Create a new preference. The new preference is assumed to be in
--- a/devtools/client/shared/shim/test/test_service_prefs_defaults.html
+++ b/devtools/client/shared/shim/test/test_service_prefs_defaults.html
@@ -51,13 +51,21 @@ localStorage.setItem("Services.prefs:pre
is(Services.prefs.getCharPref("pref1"), "pref1default", "pref1 value");
is(Services.prefs.getCharPref("pref2"), "pref2default", "pref2 value");
is(Services.prefs.getCharPref("pref3"), "glass winged butterfly", "pref3 value");
// Only pref3 should be in local storage at this point.
is(localStorage.length, 1, "local storage is correct");
+Services.prefs.setCharPref("pref2", "pref2override");
+
+// Check that a default pref can be overridden properly
+
+// Workaround to reset the prefs helper and force it to read defaults & overrides again.
+Services._prefs = null;
+is(Services.prefs.getCharPref("pref2"), "pref2override", "pref2 value overridden");
+
// Clean up.
localStorage.clear();
</script>
</body>