Bug 1663532. Support setting/clearing prefs that don't have a default value in the reftest harness. r=kats

In order to fix bug 1657822 we need to run some reftests with the pref ui.useOverlayScrollbars. This preference doesn't have a default value (it is not set by anything on desktop, it appears only in mobile/android/app/mobile.js and when we set the pref for some mochitests, the look and feel code looks at this pref, which is how we almost (?) always query for overlay scrollbars.). The reftest harness doesn't currently handle this because it gets the current value first and doesn't expect the pref to not exist.

Differential Revision: https://phabricator.services.mozilla.com/D89399
This commit is contained in:
Timothy Nikkel 2020-09-08 08:45:56 +00:00
Родитель e7ed767ca6
Коммит a7adf2b1c8
1 изменённых файлов: 53 добавлений и 35 удалений

Просмотреть файл

@ -732,35 +732,48 @@ async function StartCurrentURI(aURLTargetType)
var badPref = undefined;
try {
prefSettings.forEach(function(ps) {
var oldVal;
if (ps.type == PREF_BOOLEAN) {
try {
oldVal = prefs.getBoolPref(ps.name);
} catch (e) {
badPref = "boolean preference '" + ps.name + "'";
throw "bad pref";
}
} else if (ps.type == PREF_STRING) {
try {
oldVal = prefs.getStringPref(ps.name);
} catch (e) {
badPref = "string preference '" + ps.name + "'";
throw "bad pref";
}
} else if (ps.type == PREF_INTEGER) {
try {
oldVal = prefs.getIntPref(ps.name);
} catch (e) {
badPref = "integer preference '" + ps.name + "'";
throw "bad pref";
}
} else {
throw "internal error - unknown preference type";
let prefExists = false;
try {
let prefType = prefs.getPrefType(ps.name);
prefExists = (prefType != prefs.PREF_INVALID);
} catch (e) {
}
if (oldVal != ps.value) {
if (!prefExists) {
logger.info("Pref " + ps.name + " not found, will be added");
}
let oldVal = undefined;
if (prefExists) {
if (ps.type == PREF_BOOLEAN) {
try {
oldVal = prefs.getBoolPref(ps.name);
} catch (e) {
badPref = "boolean preference '" + ps.name + "'";
throw "bad pref";
}
} else if (ps.type == PREF_STRING) {
try {
oldVal = prefs.getStringPref(ps.name);
} catch (e) {
badPref = "string preference '" + ps.name + "'";
throw "bad pref";
}
} else if (ps.type == PREF_INTEGER) {
try {
oldVal = prefs.getIntPref(ps.name);
} catch (e) {
badPref = "integer preference '" + ps.name + "'";
throw "bad pref";
}
} else {
throw "internal error - unknown preference type";
}
}
if (!prefExists || oldVal != ps.value) {
g.prefsToRestore.push( { name: ps.name,
type: ps.type,
value: oldVal } );
value: oldVal,
prefExisted: prefExists } );
var value = ps.value;
if (ps.type == PREF_BOOLEAN) {
prefs.setBoolPref(ps.name, value);
@ -1470,16 +1483,21 @@ function RestoreChangedPreferences()
getService(Ci.nsIPrefBranch);
g.prefsToRestore.reverse();
g.prefsToRestore.forEach(function(ps) {
var value = ps.value;
if (ps.type == PREF_BOOLEAN) {
prefs.setBoolPref(ps.name, value);
} else if (ps.type == PREF_STRING) {
prefs.setStringPref(ps.name, value);
value = '"' + value + '"';
} else if (ps.type == PREF_INTEGER) {
prefs.setIntPref(ps.name, value);
if (ps.prefExisted) {
var value = ps.value;
if (ps.type == PREF_BOOLEAN) {
prefs.setBoolPref(ps.name, value);
} else if (ps.type == PREF_STRING) {
prefs.setStringPref(ps.name, value);
value = '"' + value + '"';
} else if (ps.type == PREF_INTEGER) {
prefs.setIntPref(ps.name, value);
}
logger.info("RESTORE PREFERENCE pref(" + ps.name + "," + value + ")");
} else {
prefs.clearUserPref(ps.name);
logger.info("RESTORE PREFERENCE pref(" + ps.name + ", <no value set>) (clearing user pref)");
}
logger.info("RESTORE PREFERENCE pref(" + ps.name + "," + value + ")");
});
g.prefsToRestore = [];
}