Bug 487059 - clearUserPref shouldn't throw if a pref doesn't have a default or user value. r+sr=bsedberg

This commit is contained in:
Dão Gottwald 2009-04-10 10:24:24 +02:00
parent 725fb78407
commit 65b5d09e58
20 changed files with 27 additions and 93 deletions

View File

@ -90,8 +90,7 @@ function disableAddons() {
// Select the default theme
var prefB = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
if (prefB.prefHasUserValue("general.skins.selectedSkin"))
prefB.clearUserPref("general.skins.selectedSkin");
prefB.clearUserPref("general.skins.selectedSkin");
// Disable plugins
var phs = Components.classes["@mozilla.org/plugin/host;1"]

View File

@ -11,6 +11,5 @@ function test() {
is(gBrowser.mTabs.length, 1, "a new tab has been opened");
is(document.activeElement, gURLBar.inputField, "location bar is focused for the new tab");
if (gPrefService.prefHasUserValue("browser.tabs.closeWindowWithLastTab"))
gPrefService.clearUserPref("browser.tabs.closeWindowWithLastTab");
gPrefService.clearUserPref("browser.tabs.closeWindowWithLastTab");
}

View File

@ -453,10 +453,7 @@ var MigrationWizard = {
var prefBranch = prefSvc.getBranch(null);
if (this._newHomePage == "DEFAULT") {
try {
prefBranch.clearUserPref("browser.startup.homepage");
}
catch (e) { }
prefBranch.clearUserPref("browser.startup.homepage");
}
else {
var str = Components.classes["@mozilla.org/supports-string;1"]

View File

@ -77,10 +77,7 @@ function test() {
// close tab, restore default values and finish the test
gBrowser.removeTab(tab);
// we need this if-statement because if there is no user set value,
// clearUserPref throws a uncatched exception and finish is not called
if (gPrefService.prefHasUserValue("browser.startup.page"))
gPrefService.clearUserPref("browser.startup.page");
gPrefService.clearUserPref("browser.startup.page");
gPrefService.clearUserPref("browser.startup.homepage");
finish();
}, true);

View File

@ -41,9 +41,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=238987
var prefs = Components.classes[prefSvcContractID].getService(prefSvcIID)
.getBranch("accessibility.");
if (!newValue) {
try {
prefs.clearUserPref("tabfocus");
} catch(ex) {}
prefs.clearUserPref("tabfocus");
} else {
prefs.setIntPref("tabfocus", newValue);
}

View File

@ -104,9 +104,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=409604
var prefs = Components.classes[prefSvcContractID].getService(prefSvcIID)
.getBranch("ui.key.");
if (!newValue) {
try {
prefs.clearUserPref("contentAccess");
} catch(ex) {}
prefs.clearUserPref("contentAccess");
} else {
prefs.setIntPref("contentAccess", newValue);
}

View File

@ -29,9 +29,7 @@ function setUserPref(reset) {
var prefs = Components.classes[prefSvcContractID].getService(prefSvcIID)
.getBranch("browser.link.");
if (reset) {
try {
prefs.clearUserPref("open_newwindow");
} catch (ex) {}
prefs.clearUserPref("open_newwindow");
} else {
prefs.setIntPref("open_newwindow", 3);
}

View File

@ -88,11 +88,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=369370
kidWin.close();
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
try {
prefs.clearUserPref("browser.enable_automatic_image_resizing");
} catch (ex) {
// throws if it wasn't already set because app default was true
}
prefs.clearUserPref("browser.enable_automatic_image_resizing");
SimpleTest.finish();
}

View File

@ -34,9 +34,7 @@ function setOrRestoreTabFocus(newValue) {
var prefs = Components.classes[prefSvcContractID].getService(prefSvcIID)
.getBranch("accessibility.");
if (!newValue) {
try {
prefs.clearUserPref("tabfocus");
} catch(ex) {}
prefs.clearUserPref("tabfocus");
} else {
prefs.setIntPref("tabfocus", newValue);
}

View File

@ -46,9 +46,7 @@ function execTests() {
}
function restoreEatSpace() {
try {
getPrefs().clearUserPref("eat_space_to_next_word");
} catch(ex) {}
getPrefs().clearUserPref("eat_space_to_next_word");
}
function doCommand(cmd) {

View File

@ -38,12 +38,8 @@ function setPrefs(eat_space, stop_at_punctuation) {
}
function restorePrefs() {
try {
getPrefs().clearUserPref("eat_space_to_next_word");
} catch(ex) {}
try {
getPrefs().clearUserPref("stop_at_punctuation");
} catch(ex) {}
getPrefs().clearUserPref("eat_space_to_next_word");
getPrefs().clearUserPref("stop_at_punctuation");
}
function test() {

View File

@ -63,11 +63,7 @@ var CI = Components.interfaces;
var prefs =
CC["@mozilla.org/preferences-service;1"].getService(CI.nsIPrefBranch);
try {
prefs.clearUserPref('font.minimum-size.x-western');
} catch (ex) {
// throws if it wasn't already set
}
prefs.clearUserPref('font.minimum-size.x-western');
// preference change is async (although one setTimeout might be enough?)
setTimeout(setTimeout, 0, step1, 0);

View File

@ -551,7 +551,6 @@ PREF_ClearUserPref(const char *pref_name)
if (!gHashTable.ops)
return NS_ERROR_NOT_INITIALIZED;
nsresult rv = NS_ERROR_UNEXPECTED;
PrefHashEntry* pref = pref_HashTableLookup(pref_name);
if (pref && PREF_HAS_USER_VALUE(pref))
{
@ -567,9 +566,8 @@ PREF_ClearUserPref(const char *pref_name)
pref_DoCallback(pref_name);
gDirty = PR_TRUE;
rv = NS_OK;
}
return rv;
return NS_OK;
}
static PLDHashOperator

View File

@ -53,9 +53,7 @@ function run_test() {
for each (var pref in prefData) {
try {
pref.oldVal = prefs.getBoolPref(pref.name);
pref.set = true;
} catch(e) {
pref.set = false;
}
prefs.setBoolPref(pref.name, pref.newVal);
}
@ -73,11 +71,7 @@ function run_test() {
do_check_eq(uri4.asciiHost, uri5.asciiHost);
} finally {
for each (var pref in prefData) {
if (pref.set) {
prefs.setBoolPref(pref.name, pref.oldVal);
} else {
prefs.clearUserPref(pref.name);
}
prefs.clearUserPref(pref.name);
}
}
}

View File

@ -31,12 +31,6 @@ function run_test() {
var pbi = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranch2);
var whitelistPref = "network.IDN.whitelist.com";
var savedPrefValue = false;
var prefExists = false;
try {
savedPrefValue = pbi.getBoolPref(whitelistPref);
prefExists = true;
} catch(e) { }
pbi.setBoolPref(whitelistPref, true);
@ -62,8 +56,5 @@ function run_test() {
expected_fail("foo\u0370bar.com");
// reset the pref
if (prefExists)
pbi.setBoolPref(whitelistPref, savedPrefValue);
else
pbi.clearUserPref(whitelistPref);
pbi.clearUserPref(whitelistPref);
}

View File

@ -81,11 +81,8 @@ function test()
ok(dmui.visible, "Download Manager window is open, as expected.");
// Reset the pref to its default value
try {
Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch).
clearUserPref(PREF_BDM_CLOSEWHENDONE);
}
catch (err) { }
Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch).
clearUserPref(PREF_BDM_CLOSEWHENDONE);
finish();
}

View File

@ -3182,8 +3182,7 @@ SearchService.prototype = {
var currentEnginePref = BROWSER_SEARCH_PREF + "selectedEngine";
if (this._currentEngine == this.defaultEngine) {
if (gPrefSvc.prefHasUserValue(currentEnginePref))
gPrefSvc.clearUserPref(currentEnginePref);
gPrefSvc.clearUserPref(currentEnginePref);
}
else {
setLocalizedPref(currentEnginePref, this._currentEngine.name);

View File

@ -109,14 +109,8 @@ bug413093obs.prototype = {
// reset the changed config values to default value
let prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService);
try {
prefs.clearUserPref("browser.download.manager.retention");
}
catch (err) { }
try {
prefs.clearUserPref("browser.download.manager.closeWhenDone");
}
catch (err) { }
prefs.clearUserPref("browser.download.manager.retention");
prefs.clearUserPref("browser.download.manager.closeWhenDone");
SimpleTest.finish();
});

View File

@ -99,12 +99,11 @@ function test()
win.close();
setClose(false);
os.removeObserver(testObs, DLMGR_UI_DONE);
try {
Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch).
clearUserPref("browser.download.manager.closeWhenDone");
}
catch (err) { }
Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch).
clearUserPref("browser.download.manager.closeWhenDone");
SimpleTest.finish();
}
};

View File

@ -87,11 +87,6 @@ function run_test()
.replace(/%CUSTOM2%/, "custom_parameter_2");
// Replace extension update URL
var origURL = null;
try {
origURL = prefs.getCharPref("extensions.update.url");
}
catch (e) {}
gPrefs.setCharPref("extensions.update.url", gTestURL);
// Initiate update
@ -99,10 +94,7 @@ function run_test()
do_check_true(gSeenExpectedURL);
if (origURL)
gPrefs.setCharPref("extensions.update.url", origURL);
else
gPrefs.clearUserPref("extensions.update.url");
gPrefs.clearUserPref("extensions.update.url");
shutdownTest();
}