Bug 1034724 - Fixed Unicode values of prefs in about:support. r=adw

This commit is contained in:
Jarda Snajdr 2015-05-20 13:10:30 +02:00
parent 3185d9342b
commit 1ab3ef5b3e
2 changed files with 46 additions and 36 deletions

View File

@ -100,6 +100,34 @@ const PREFS_BLACKLIST = [
/^print[.]macosx[.]pagesetup/,
];
// Table of getters for various preference types.
// It's important to use getComplexValue for strings: it returns Unicode (wchars), getCharPref returns UTF-8 encoded chars.
const PREFS_GETTERS = {};
PREFS_GETTERS[Ci.nsIPrefBranch.PREF_STRING] = (prefs, name) => prefs.getComplexValue(name, Ci.nsISupportsString).data;
PREFS_GETTERS[Ci.nsIPrefBranch.PREF_INT] = (prefs, name) => prefs.getIntPref(name);
PREFS_GETTERS[Ci.nsIPrefBranch.PREF_BOOL] = (prefs, name) => prefs.getBoolPref(name);
// Return the preferences filtered by PREFS_BLACKLIST and PREFS_WHITELIST lists
// and also by the custom 'filter'-ing function.
function getPrefList(filter) {
filter = filter || (name => true);
function getPref(name) {
let type = Services.prefs.getPrefType(name);
if (!(type in PREFS_GETTERS))
throw new Error("Unknown preference type " + type + " for " + name);
return PREFS_GETTERS[type](Services.prefs, name);
}
return PREFS_WHITELIST.reduce(function(prefs, branch) {
Services.prefs.getChildList(branch).forEach(function(name) {
if (filter(name) && !PREFS_BLACKLIST.some(re => re.test(name)))
prefs[name] = getPref(name);
});
return prefs;
}, {});
}
this.Troubleshoot = {
/**
@ -220,45 +248,11 @@ let dataProviders = {
},
modifiedPreferences: function modifiedPreferences(done) {
function getPref(name) {
let table = {};
table[Ci.nsIPrefBranch.PREF_STRING] = "getCharPref";
table[Ci.nsIPrefBranch.PREF_INT] = "getIntPref";
table[Ci.nsIPrefBranch.PREF_BOOL] = "getBoolPref";
let type = Services.prefs.getPrefType(name);
if (!(type in table))
throw new Error("Unknown preference type " + type + " for " + name);
return Services.prefs[table[type]](name);
}
done(PREFS_WHITELIST.reduce(function (prefs, branch) {
Services.prefs.getChildList(branch).forEach(function (name) {
if (Services.prefs.prefHasUserValue(name) &&
!PREFS_BLACKLIST.some(function (re) re.test(name)))
prefs[name] = getPref(name);
});
return prefs;
}, {}));
done(getPrefList(name => Services.prefs.prefHasUserValue(name)));
},
lockedPreferences: function lockedPreferences(done) {
function getPref(name) {
let table = {};
table[Ci.nsIPrefBranch.PREF_STRING] = "getCharPref";
table[Ci.nsIPrefBranch.PREF_INT] = "getIntPref";
table[Ci.nsIPrefBranch.PREF_BOOL] = "getBoolPref";
let type = Services.prefs.getPrefType(name);
if (!(type in table))
throw new Error("Unknown preference type " + type + " for " + name);
return Services.prefs[table[type]](name);
}
done(PREFS_WHITELIST.reduce(function (prefs, branch) {
Services.prefs.getChildList(branch).forEach(function (name) {
if (Services.prefs.prefIsLocked(name) &&
!PREFS_BLACKLIST.some(function (re) re.test(name)))
prefs[name] = getPref(name);
});
return prefs;
}, {}));
done(getPrefList(name => Services.prefs.prefIsLocked(name)));
},
graphics: function graphics(done) {

View File

@ -68,6 +68,22 @@ let tests = [
done();
});
},
function unicodePreferences(done) {
let name = "font.name.sans-serif.x-western";
let utf8Value = "\xc4\x8capk\xc5\xafv Krasopis"
let unicodeValue = "\u010Capk\u016Fv Krasopis";
// set/getCharPref work with 8bit strings (utf8)
Services.prefs.setCharPref(name, utf8Value);
Troubleshoot.snapshot(function (snapshot) {
let p = snapshot.modifiedPreferences;
is(p[name], unicodeValue, "The pref should have correct Unicode value.");
Services.prefs.deleteBranch(name);
done();
});
}
];
// This is inspired by JSON Schema, or by the example on its Wikipedia page