Backed out 1 changesets (bug 1414096) for dt1 failures "devtools/client/commandline/test/browser_cmd_pref3.js" r=backout on a CLOSED TREE

Backed out changeset e843de356b7e (bug 1414096)
This commit is contained in:
Narcis Beleuzu 2017-11-08 18:04:01 +02:00
parent a29af12056
commit 57d9eb5fb1
17 changed files with 198 additions and 59 deletions

View File

@ -30,7 +30,7 @@ function init() {
distroIdField.textContent = distroId + " - " + distroVersion;
distroIdField.hidden = false;
let distroAbout = Services.prefs.getStringPref("distribution.about");
let distroAbout = Services.prefs.getComplexValue("distribution.about", Ci.nsISupportsString);
let distroField = document.getElementById("distributionAbout");
distroField.textContent = distroAbout;
distroField.hidden = false;

View File

@ -2563,6 +2563,20 @@ nsPrefBranch::GetComplexValue(const char* aPrefName,
return NS_OK;
}
if (aType.Equals(NS_GET_IID(nsISupportsString))) {
nsCOMPtr<nsISupportsString> theString(
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv)) {
// Debugging to see why we end up with very long strings here with
// some addons, see bug 836263.
NS_ConvertUTF8toUTF16 wdata(utf8String);
theString->SetData(wdata);
theString.forget(reinterpret_cast<nsISupportsString**>(aRetVal));
}
return rv;
}
NS_WARNING("nsPrefBranch::GetComplexValue - Unsupported interface type");
return NS_NOINTERFACE;
}
@ -2694,7 +2708,8 @@ nsPrefBranch::SetComplexValue(const char* aPrefName,
return SetCharPrefInternal(aPrefName, descriptorString);
}
if (aType.Equals(NS_GET_IID(nsIPrefLocalizedString))) {
if (aType.Equals(NS_GET_IID(nsISupportsString)) ||
aType.Equals(NS_GET_IID(nsIPrefLocalizedString))) {
nsCOMPtr<nsISupportsString> theString = do_QueryInterface(aValue);
if (theString) {

View File

@ -191,6 +191,8 @@ interface nsIPrefBranch : nsISupports
* @param aType The XPCOM interface that this complex preference
* represents. Interfaces currently supported are:
* - nsIFile
* - nsISupportsString (UniChar)
* (deprecated; see getStringPref)
* - nsIPrefLocalizedString (Localized UniChar)
* @param aValue The XPCOM object into which to the complex preference
* value should be retrieved.

View File

@ -36,6 +36,13 @@ function run_test() {
ps.setStringPref(prefName, "éèçàê€");
strictEqual(ps.getStringPref(prefName), "éèçàê€");
strictEqual(ps.getStringPref(prefName, "string"), "éèçàê€");
strictEqual(ps.getStringPref(prefName),
ps.getComplexValue(prefName, Ci.nsISupportsString).data);
let str = Cc["@mozilla.org/supports-string;1"].
createInstance(Ci.nsISupportsString);
str.data = "ù€ÚîœïŒëøÇ“";
ps.setComplexValue(prefName, Ci.nsISupportsString, str);
strictEqual(ps.getStringPref(prefName), "ù€ÚîœïŒëøÇ“");
prefName = "test.default.values.float";
do_check_throws(function() { ps.getFloatPref(prefName); },

View File

@ -48,9 +48,9 @@ function run_test() {
do_check_throws(function() {
pb.setCharPref(null, null); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.getStringPref(null); }, Cr.NS_ERROR_INVALID_ARG);
pb.getComplexValue(null, Components.interfaces.nsISupportsString); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.setStringPref(null, null); }, Cr.NS_ERROR_INVALID_ARG);
pb.setComplexValue(null, Components.interfaces.nsISupportsString, pb); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.clearUserPref(null); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {

View File

@ -102,14 +102,14 @@ void nsIDNService::prefsChanged(nsIPrefBranch *prefBranch, const char16_t *pref)
mLock.AssertCurrentThreadOwns();
if (!pref || NS_LITERAL_STRING(NS_NET_PREF_IDNBLACKLIST).Equals(pref)) {
nsAutoCString blacklist;
nsresult rv =
prefBranch->GetStringPref(NS_NET_PREF_IDNBLACKLIST, EmptyCString(), 0, blacklist);
if (NS_SUCCEEDED(rv)) {
CopyUTF8toUTF16(blacklist, mIDNBlacklist);
} else {
nsCOMPtr<nsISupportsString> blacklist;
nsresult rv = prefBranch->GetComplexValue(NS_NET_PREF_IDNBLACKLIST,
NS_GET_IID(nsISupportsString),
getter_AddRefs(blacklist));
if (NS_SUCCEEDED(rv))
blacklist->ToString(getter_Copies(mIDNBlacklist));
else
mIDNBlacklist.Truncate();
}
}
if (!pref || NS_LITERAL_STRING(NS_NET_PREF_SHOWPUNYCODE).Equals(pref)) {
bool val;

View File

@ -868,7 +868,7 @@ class Marionette(object):
Preferences.reset(arguments[0]);
""", script_args=(pref,))
def get_pref(self, pref, default_branch=False, value_type="unspecified"):
def get_pref(self, pref, default_branch=False, value_type="nsISupportsString"):
"""Get the value of the specified preference.
:param pref: Name of the preference.
@ -876,8 +876,8 @@ class Marionette(object):
from the default branch. Otherwise the user-defined
value if set is returned. Defaults to `False`.
:param value_type: Optional, XPCOM interface of the pref's complex value.
Possible values are: `nsIFile` and
`nsIPrefLocalizedString`.
Defaults to `nsISupportsString`. Other possible values are:
`nsIFile`, and `nsIPrefLocalizedString`.
Usage example::

View File

@ -22,16 +22,19 @@
int: 23,
bool: true,
string: "rheeet!",
unichar: "äöüßÄÖÜ",
wstring_data: "日本語",
unichar_data: "äöüßÄÖÜ",
file_data: "/",
wstring: Components.classes["@mozilla.org/pref-localizedstring;1"]
.createInstance(Components.interfaces.nsIPrefLocalizedString),
unichar: Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString),
file: Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsIFile)
};
kPrefValueSet1.wstring.data = kPrefValueSet1.wstring_data;
kPrefValueSet1.unichar.data = kPrefValueSet1.unichar_data;
SafeFileInit(kPrefValueSet1.file, kPrefValueSet1.file_data);
// preference values, set 2
@ -40,16 +43,19 @@
int: 42,
bool: false,
string: "Mozilla",
unichar: "áôùšŽ",
wstring_data: "헤드라인A",
unichar_data: "áôùšŽ",
file_data: "/home",
wstring: Components.classes["@mozilla.org/pref-localizedstring;1"]
.createInstance(Components.interfaces.nsIPrefLocalizedString),
unichar: Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString),
file: Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsIFile)
};
kPrefValueSet2.wstring.data = kPrefValueSet2.wstring_data;
kPrefValueSet2.unichar.data = kPrefValueSet2.unichar_data;
SafeFileInit(kPrefValueSet2.file, kPrefValueSet2.file_data);
@ -70,10 +76,11 @@
int: undefined,
bool: undefined,
string: undefined,
unichar: undefined,
wstring_data: undefined,
unichar_data: undefined,
file_data: undefined,
wstring: undefined,
unichar: undefined,
file: undefined
};
return result;
@ -85,10 +92,12 @@
kPref.setIntPref ("tests.static_preference_int", aPrefValueSet.int);
kPref.setBoolPref("tests.static_preference_bool", aPrefValueSet.bool);
kPref.setCharPref("tests.static_preference_string", aPrefValueSet.string);
kPref.setStringPref("tests.static_preference_unichar", aPrefValueSet.unichar);
kPref.setComplexValue("tests.static_preference_wstring",
Components.interfaces.nsIPrefLocalizedString,
aPrefValueSet.wstring);
kPref.setComplexValue("tests.static_preference_unichar",
Components.interfaces.nsISupportsString,
aPrefValueSet.unichar);
kPref.setComplexValue("tests.static_preference_file",
Components.interfaces.nsIFile,
aPrefValueSet.file);
@ -103,14 +112,16 @@
try {result.string = kPref.getCharPref("tests.static_preference_string")} catch (ignored) {};
try
{
result.unichar = kPref.getStringPref("tests.static_preference_unichar");
result.wstring = kPref.getComplexValue("tests.static_preference_wstring",
Components.interfaces.nsIPrefLocalizedString);
result.wstring_data = result.wstring.data;
}
catch (ignored) {};
try
{
result.wstring = kPref.getComplexValue("tests.static_preference_wstring",
Components.interfaces.nsIPrefLocalizedString);
result.wstring_data = result.wstring.data;
result.unichar = kPref.getComplexValue("tests.static_preference_unichar",
Components.interfaces.nsISupportsString);
result.unichar_data = result.unichar.data;
}
catch (ignored) {};
try
@ -134,8 +145,8 @@
GetXULElement(aPrefWindow, "tests.static_preference_int" ).value = aPrefValueSet.int;
GetXULElement(aPrefWindow, "tests.static_preference_bool" ).value = aPrefValueSet.bool;
GetXULElement(aPrefWindow, "tests.static_preference_string" ).value = aPrefValueSet.string;
GetXULElement(aPrefWindow, "tests.static_preference_unichar").value = aPrefValueSet.unichar;
GetXULElement(aPrefWindow, "tests.static_preference_wstring").value = aPrefValueSet.wstring_data;
GetXULElement(aPrefWindow, "tests.static_preference_unichar").value = aPrefValueSet.unichar_data;
GetXULElement(aPrefWindow, "tests.static_preference_file" ).value = aPrefValueSet.file_data;
}
@ -147,15 +158,18 @@
int: GetXULElement(aPrefWindow, "tests.static_preference_int" ).value,
bool: GetXULElement(aPrefWindow, "tests.static_preference_bool" ).value,
string: GetXULElement(aPrefWindow, "tests.static_preference_string" ).value,
unichar: GetXULElement(aPrefWindow, "tests.static_preference_unichar").value,
wstring_data: GetXULElement(aPrefWindow, "tests.static_preference_wstring").value,
unichar_data: GetXULElement(aPrefWindow, "tests.static_preference_unichar").value,
file_data: GetXULElement(aPrefWindow, "tests.static_preference_file" ).value,
wstring: Components.classes["@mozilla.org/pref-localizedstring;1"]
.createInstance(Components.interfaces.nsIPrefLocalizedString),
unichar: Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString),
file: Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsIFile)
}
result.wstring.data = result.wstring_data;
result.unichar.data = result.unichar_data;
SafeFileInit(result.file, result.file_data);
return result;
}
@ -166,8 +180,8 @@
GetXULElement(aPrefWindow, "static_element_int" ).value = aPrefValueSet.int;
GetXULElement(aPrefWindow, "static_element_bool" ).checked = aPrefValueSet.bool;
GetXULElement(aPrefWindow, "static_element_string" ).value = aPrefValueSet.string;
GetXULElement(aPrefWindow, "static_element_unichar").value = aPrefValueSet.unichar;
GetXULElement(aPrefWindow, "static_element_wstring").value = aPrefValueSet.wstring_data;
GetXULElement(aPrefWindow, "static_element_unichar").value = aPrefValueSet.unichar_data;
GetXULElement(aPrefWindow, "static_element_file" ).value = aPrefValueSet.file_data;
}
@ -179,15 +193,18 @@
int: GetXULElement(aPrefWindow, "static_element_int" ).value,
bool: GetXULElement(aPrefWindow, "static_element_bool" ).checked,
string: GetXULElement(aPrefWindow, "static_element_string" ).value,
unichar: GetXULElement(aPrefWindow, "static_element_unichar").value,
wstring_data: GetXULElement(aPrefWindow, "static_element_wstring").value,
unichar_data: GetXULElement(aPrefWindow, "static_element_unichar").value,
file_data: GetXULElement(aPrefWindow, "static_element_file" ).value,
wstring: Components.classes["@mozilla.org/pref-localizedstring;1"]
.createInstance(Components.interfaces.nsIPrefLocalizedString),
unichar: Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString),
file: Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsIFile)
}
result.wstring.data = result.wstring_data;
result.unichar.data = result.unichar_data;
SafeFileInit(result.file, result.file_data);
return result;
}
@ -203,8 +220,8 @@
ok(found.int === expected.int, "instant pref init int" );
ok(found.bool === expected.bool, "instant pref init bool" );
ok(found.string === expected.string, "instant pref init string" );
ok(found.unichar === expected.unichar, "instant pref init unichar");
ok(found.wstring_data === expected.wstring_data, "instant pref init wstring");
ok(found.unichar_data === expected.unichar_data, "instant pref init unichar");
todo(found.file_data === expected.file_data, "instant pref init file" );
// were all elements correctly initialized? (loose check)
@ -212,8 +229,8 @@
ok(found.int == expected.int, "instant element init int" );
ok(found.bool == expected.bool, "instant element init bool" );
ok(found.string == expected.string, "instant element init string" );
ok(found.unichar == expected.unichar, "instant element init unichar");
ok(found.wstring_data == expected.wstring_data, "instant element init wstring");
ok(found.unichar_data == expected.unichar_data, "instant element init unichar");
todo(found.file_data == expected.file_data, "instant element init file" );
// do some changes in the UI
@ -228,8 +245,8 @@
todo(found.int === expected.int, "instant change pref int" );
todo(found.bool === expected.bool, "instant change pref bool" );
todo(found.string === expected.string, "instant change pref string" );
todo(found.unichar === expected.unichar, "instant change pref unichar");
todo(found.wstring_data === expected.wstring_data, "instant change pref wstring");
todo(found.unichar_data === expected.unichar_data, "instant change pref unichar");
todo(found.file_data === expected.file_data, "instant change pref file" );
// and these changes should get passed to the system instantly
@ -238,16 +255,16 @@
todo(found.int === expected.int, "instant change element int" );
todo(found.bool === expected.bool, "instant change element bool" );
todo(found.string === expected.string, "instant change element string" );
todo(found.unichar === expected.unichar, "instant change element unichar");
todo(found.wstring_data === expected.wstring_data, "instant change element wstring");
todo(found.unichar_data === expected.unichar_data, "instant change element unichar");
todo(found.file_data === expected.file_data, "instant change element file" );
// try resetting the prefs to default values (which should be empty here)
GetXULElement(aPrefWindow, "tests.static_preference_int" ).reset();
GetXULElement(aPrefWindow, "tests.static_preference_bool" ).reset();
GetXULElement(aPrefWindow, "tests.static_preference_string" ).reset();
GetXULElement(aPrefWindow, "tests.static_preference_unichar").reset();
GetXULElement(aPrefWindow, "tests.static_preference_wstring").reset();
GetXULElement(aPrefWindow, "tests.static_preference_unichar").reset();
GetXULElement(aPrefWindow, "tests.static_preference_file" ).reset();
// check system
@ -256,8 +273,8 @@
ok(found.int === expected.int, "instant reset system int" );
ok(found.bool === expected.bool, "instant reset system bool" );
ok(found.string === expected.string, "instant reset system string" );
ok(found.unichar === expected.unichar, "instant reset system unichar");
ok(found.wstring_data === expected.wstring_data, "instant reset system wstring");
ok(found.unichar_data === expected.unichar_data, "instant reset system unichar");
ok(found.file_data === expected.file_data, "instant reset system file" );
// check UI
@ -268,26 +285,27 @@
int: "",
bool: false,
string: "",
unichar: "",
wstring_data: "",
unichar_data: "",
file_data: "",
wstring: {},
unichar: {},
file: {}
};
found = ReadPrefsFromUI(aPrefWindow);
ok(found.int === expected.int, "instant reset element int" );
ok(found.bool === expected.bool, "instant reset element bool" );
ok(found.string === expected.string, "instant reset element string" );
ok(found.unichar === expected.unichar, "instant reset element unichar");
ok(found.wstring_data === expected.wstring_data, "instant reset element wstring");
ok(found.unichar_data === expected.unichar_data, "instant reset element unichar");
// ok(found.file_data === expected.file_data, "instant reset element file" );
// check hasUserValue
ok(GetXULElement(aPrefWindow, "tests.static_preference_int" ).hasUserValue === false, "instant reset hasUserValue int" );
ok(GetXULElement(aPrefWindow, "tests.static_preference_bool" ).hasUserValue === false, "instant reset hasUserValue bool" );
ok(GetXULElement(aPrefWindow, "tests.static_preference_string" ).hasUserValue === false, "instant reset hasUserValue string" );
ok(GetXULElement(aPrefWindow, "tests.static_preference_unichar").hasUserValue === false, "instant reset hasUserValue unichar");
ok(GetXULElement(aPrefWindow, "tests.static_preference_wstring").hasUserValue === false, "instant reset hasUserValue wstring");
ok(GetXULElement(aPrefWindow, "tests.static_preference_unichar").hasUserValue === false, "instant reset hasUserValue unichar");
ok(GetXULElement(aPrefWindow, "tests.static_preference_file" ).hasUserValue === false, "instant reset hasUserValue file" );
// done with instant apply checks
@ -307,8 +325,8 @@
ok(found.int === expected.int, "non-instant pref init int" );
ok(found.bool === expected.bool, "non-instant pref init bool" );
ok(found.string === expected.string, "non-instant pref init string" );
ok(found.unichar === expected.unichar, "non-instant pref init unichar");
ok(found.wstring_data === expected.wstring_data, "non-instant pref init wstring");
ok(found.unichar_data === expected.unichar_data, "non-instant pref init unichar");
todo(found.file_data === expected.file_data, "non-instant pref init file" );
// were all elements correctly initialized? (loose check)
@ -316,8 +334,8 @@
ok(found.int == expected.int, "non-instant element init int" );
ok(found.bool == expected.bool, "non-instant element init bool" );
ok(found.string == expected.string, "non-instant element init string" );
ok(found.unichar == expected.unichar, "non-instant element init unichar");
ok(found.wstring_data == expected.wstring_data, "non-instant element init wstring");
ok(found.unichar_data == expected.unichar_data, "non-instant element init unichar");
todo(found.file_data == expected.file_data, "non-instant element init file" );
// do some changes in the UI
@ -332,8 +350,8 @@
todo(found.int === expected.int, "non-instant change pref int" );
todo(found.bool === expected.bool, "non-instant change pref bool" );
todo(found.string === expected.string, "non-instant change pref string" );
todo(found.unichar === expected.unichar, "non-instant change pref unichar");
todo(found.wstring_data === expected.wstring_data, "non-instant change pref wstring");
todo(found.unichar_data === expected.unichar_data, "non-instant change pref unichar");
todo(found.file_data === expected.file_data, "non-instant change pref file" );
// and these changes should *NOT* get passed to the system
@ -343,16 +361,16 @@
ok(found.int === expected.int, "non-instant change element int" );
ok(found.bool === expected.bool, "non-instant change element bool" );
ok(found.string === expected.string, "non-instant change element string" );
ok(found.unichar === expected.unichar, "non-instant change element unichar");
ok(found.wstring_data === expected.wstring_data, "non-instant change element wstring");
ok(found.unichar_data === expected.unichar_data, "non-instant change element unichar");
todo(found.file_data === expected.file_data, "non-instant change element file" );
// try resetting the prefs to default values (which should be empty here)
GetXULElement(aPrefWindow, "tests.static_preference_int" ).reset();
GetXULElement(aPrefWindow, "tests.static_preference_bool" ).reset();
GetXULElement(aPrefWindow, "tests.static_preference_string" ).reset();
GetXULElement(aPrefWindow, "tests.static_preference_unichar").reset();
GetXULElement(aPrefWindow, "tests.static_preference_wstring").reset();
GetXULElement(aPrefWindow, "tests.static_preference_unichar").reset();
GetXULElement(aPrefWindow, "tests.static_preference_file" ).reset();
// check system: the current values *MUST NOT* change
@ -361,8 +379,8 @@
ok(found.int === expected.int, "non-instant reset system int" );
ok(found.bool === expected.bool, "non-instant reset system bool" );
ok(found.string === expected.string, "non-instant reset system string" );
ok(found.unichar === expected.unichar, "non-instant reset system unichar");
ok(found.wstring_data === expected.wstring_data, "non-instant reset system wstring");
ok(found.unichar_data === expected.unichar_data, "non-instant reset system unichar");
todo(found.file_data === expected.file_data, "non-instant reset system file" );
// check UI: these values should be reset
@ -373,26 +391,27 @@
int: "",
bool: false,
string: "",
unichar: "",
wstring_data: "",
unichar_data: "",
file_data: "",
wstring: {},
unichar: {},
file: {}
};
found = ReadPrefsFromUI(aPrefWindow);
ok(found.int === expected.int, "non-instant reset element int" );
ok(found.bool === expected.bool, "non-instant reset element bool" );
ok(found.string === expected.string, "non-instant reset element string" );
ok(found.unichar === expected.unichar, "non-instant reset element unichar");
ok(found.wstring_data === expected.wstring_data, "non-instant reset element wstring");
ok(found.unichar_data === expected.unichar_data, "non-instant reset element unichar");
// ok(found.file_data === expected.file_data, "non-instant reset element file" );
// check hasUserValue
ok(GetXULElement(aPrefWindow, "tests.static_preference_int" ).hasUserValue === false, "non-instant reset hasUserValue int" );
ok(GetXULElement(aPrefWindow, "tests.static_preference_bool" ).hasUserValue === false, "non-instant reset hasUserValue bool" );
ok(GetXULElement(aPrefWindow, "tests.static_preference_string" ).hasUserValue === false, "non-instant reset hasUserValue string" );
ok(GetXULElement(aPrefWindow, "tests.static_preference_unichar").hasUserValue === false, "non-instant reset hasUserValue unichar");
ok(GetXULElement(aPrefWindow, "tests.static_preference_wstring").hasUserValue === false, "non-instant reset hasUserValue wstring");
ok(GetXULElement(aPrefWindow, "tests.static_preference_unichar").hasUserValue === false, "non-instant reset hasUserValue unichar");
ok(GetXULElement(aPrefWindow, "tests.static_preference_file" ).hasUserValue === false, "non-instant reset hasUserValue file" );
}
@ -415,8 +434,8 @@
GetXULElement(aPrefWindow, "tests.static_preference_int" ).reset();
GetXULElement(aPrefWindow, "tests.static_preference_bool" ).reset();
GetXULElement(aPrefWindow, "tests.static_preference_string" ).reset();
GetXULElement(aPrefWindow, "tests.static_preference_unichar").reset();
GetXULElement(aPrefWindow, "tests.static_preference_wstring").reset();
GetXULElement(aPrefWindow, "tests.static_preference_unichar").reset();
GetXULElement(aPrefWindow, "tests.static_preference_file" ).reset();
}
@ -441,8 +460,8 @@
ok(found.int === expected.int, "instant reset deferred int" );
ok(found.bool === expected.bool, "instant reset deferred bool" );
ok(found.string === expected.string, "instant reset deferred string" );
ok(found.unichar === expected.unichar, "instant reset deferred unichar");
ok(found.wstring_data === expected.wstring_data, "instant reset deferred wstring");
ok(found.unichar_data === expected.unichar_data, "instant reset deferred unichar");
todo(found.file_data === expected.file_data, "instant reset deferred file" );
}
@ -461,8 +480,8 @@
ok(found.int === expected.int, "non-instant cancel system int" );
ok(found.bool === expected.bool, "non-instant cancel system bool" );
ok(found.string === expected.string, "non-instant cancel system string" );
ok(found.unichar === expected.unichar, "non-instant cancel system unichar");
ok(found.wstring_data === expected.wstring_data, "non-instant cancel system wstring");
ok(found.unichar_data === expected.unichar_data, "non-instant cancel system unichar");
todo(found.file_data === expected.file_data, "non-instant cancel system file" );
// - test Accept
@ -473,8 +492,8 @@
ok(found.int === expected.int, "non-instant accept system int" );
ok(found.bool === expected.bool, "non-instant accept system bool" );
ok(found.string === expected.string, "non-instant accept system string" );
ok(found.unichar === expected.unichar, "non-instant accept system unichar");
ok(found.wstring_data === expected.wstring_data, "non-instant accept system wstring");
ok(found.unichar_data === expected.unichar_data, "non-instant accept system unichar");
todo(found.file_data === expected.file_data, "non-instant accept system file" );
// - test deferred reset in child window
@ -485,8 +504,8 @@
ok(found.int === expected.int, "non-instant reset deferred int" );
ok(found.bool === expected.bool, "non-instant reset deferred bool" );
ok(found.string === expected.string, "non-instant reset deferred string" );
ok(found.unichar === expected.unichar, "non-instant reset deferred unichar");
ok(found.wstring_data === expected.wstring_data, "non-instant reset deferred wstring");
ok(found.unichar_data === expected.unichar_data, "non-instant reset deferred unichar");
ok(found.file_data === expected.file_data, "non-instant reset deferred file" );
}

View File

@ -47,7 +47,7 @@ this.Preferences =
*
* @returns the value of the pref, if any; otherwise the default value
*/
Preferences.get = function(prefName, defaultValue, valueType = null) {
Preferences.get = function(prefName, defaultValue, valueType = Ci.nsISupportsString) {
if (Array.isArray(prefName))
return prefName.map(v => this.get(v, defaultValue));
@ -57,13 +57,7 @@ Preferences.get = function(prefName, defaultValue, valueType = null) {
Preferences._get = function(prefName, defaultValue, valueType) {
switch (this._prefBranch.getPrefType(prefName)) {
case Ci.nsIPrefBranch.PREF_STRING:
if (valueType) {
let ifaces = ["nsIFile", "nsIPrefLocalizedString"];
if (ifaces.includes(valueType.name)) {
return this._prefBranch.getComplexValue(prefName, valueType).data;
}
}
return this._prefBranch.getStringPref(prefName);
return this._prefBranch.getComplexValue(prefName, valueType).data;
case Ci.nsIPrefBranch.PREF_INT:
return this._prefBranch.getIntPref(prefName);

View File

@ -104,6 +104,7 @@ const PREFS_BLACKLIST = [
];
// 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.getStringPref(name);

View File

@ -112,7 +112,9 @@ add_test(function test_set_unsupported_pref() {
run_next_test();
});
// Make sure that we can get a string pref that we didn't set ourselves.
// Make sure that we can get a string pref that we didn't set ourselves
// (i.e. that the way we get a string pref using getComplexValue doesn't
// hork us getting a string pref that wasn't set using setComplexValue).
add_test(function test_get_string_pref() {
let svc = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).

View File

@ -59,6 +59,11 @@ avoid-removeChild
Rejects using element.parentNode.removeChild(element) when element.remove()
can be used instead.
avoid-nsISupportsString-preferences
-----------------------------------
Rejects using getComplexValue and setComplexValue with nsISupportsString.
balanced-listeners
------------------

View File

@ -137,6 +137,7 @@ module.exports = {
// Maximum depth callbacks can be nested.
"max-nested-callbacks": ["error", 10],
"mozilla/avoid-nsISupportsString-preferences": "error",
"mozilla/avoid-removeChild": "error",
"mozilla/import-browser-window-globals": "error",
"mozilla/import-globals": "error",

View File

@ -32,6 +32,8 @@ module.exports = {
rules: {
"avoid-Date-timing": require("../lib/rules/avoid-Date-timing"),
"avoid-removeChild": require("../lib/rules/avoid-removeChild"),
"avoid-nsISupportsString-preferences":
require("../lib/rules/avoid-nsISupportsString-preferences"),
"balanced-listeners": require("../lib/rules/balanced-listeners"),
"import-browser-window-globals":
require("../lib/rules/import-browser-window-globals"),
@ -64,6 +66,7 @@ module.exports = {
rulesConfig: {
"avoid-Date-timing": "off",
"avoid-removeChild": "off",
"avoid-nsISupportsString-preferences": "off",
"balanced-listeners": "off",
"import-browser-window-globals": "off",
"import-content-task-globals": "off",

View File

@ -0,0 +1,49 @@
/**
* @fileoverview Rejects using getComplexValue and setComplexValue with
* nsISupportsString.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
"use strict";
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
function isNsISupportsString(arg) {
let isNsISupportsStringIdentifier = obj =>
obj.type == "Identifier" && obj.name == "nsISupportsString";
return isNsISupportsStringIdentifier(arg) ||
(arg.type == "MemberExpression" &&
isNsISupportsStringIdentifier(arg.property));
}
module.exports = function(context) {
// ---------------------------------------------------------------------------
// Public
// --------------------------------------------------------------------------
return {
"CallExpression": function(node) {
let callee = node.callee;
if (callee.type !== "MemberExpression" ||
callee.property.type !== "Identifier" ||
node.arguments.length < 2 ||
!isNsISupportsString(node.arguments[1])) {
return;
}
if (callee.property.name == "getComplexValue") {
context.report(node, "use getStringPref instead of " +
"getComplexValue with nsISupportsString");
} else if (callee.property.name == "setComplexValue") {
context.report(node, "use setStringPref instead of " +
"setComplexValue with nsISupportsString");
}
}
};
};

View File

@ -1,6 +1,6 @@
{
"name": "eslint-plugin-mozilla",
"version": "0.4.7",
"version": "0.4.6",
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
"keywords": [
"eslint",

View File

@ -0,0 +1,41 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
var rule = require("../lib/rules/avoid-nsISupportsString-preferences");
var RuleTester = require("eslint/lib/testers/rule-tester");
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------
function invalidCode(code, accessType = "get") {
let message = "use " + accessType + "StringPref instead of " +
accessType + "ComplexValue with nsISupportsString";
return {code, errors: [{message, type: "CallExpression"}]};
}
ruleTester.run("avoid-nsISupportsString-preferences", rule, {
valid: [
"branch.getStringPref('name');",
"branch.getComplexValue('name', Ci.nsIPrefLocalizedString);",
"branch.setStringPref('name', 'blah');",
"branch.setComplexValue('name', Ci.nsIPrefLocalizedString, pref);"
],
invalid: [
invalidCode("branch.getComplexValue('name', Ci.nsISupportsString);"),
invalidCode("branch.getComplexValue('name', nsISupportsString);"),
invalidCode("branch.getComplexValue('name', Ci.nsISupportsString).data;"),
invalidCode("branch.setComplexValue('name', Ci.nsISupportsString, str);",
"set"),
invalidCode("branch.setComplexValue('name', nsISupportsString, str);",
"set")
]
});