mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-02 20:20:00 +00:00
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:
parent
0bb0c3bf95
commit
9291640652
@ -96,8 +96,7 @@ let gOpenLocationLastURL = {
|
||||
}
|
||||
},
|
||||
reset: function() {
|
||||
if (prefSvc.prefHasUserValue(LAST_URL_PREF))
|
||||
prefSvc.clearUserPref(LAST_URL_PREF);
|
||||
prefSvc.clearUserPref(LAST_URL_PREF);
|
||||
gOpenLocationLastURLData = "";
|
||||
}
|
||||
};
|
||||
|
@ -457,10 +457,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"]
|
||||
|
@ -54,8 +54,7 @@ function test() {
|
||||
|
||||
function setupCleanSlate() {
|
||||
gLastOpenDirectory.reset();
|
||||
if (gPrefService.prefHasUserValue(kPrefName))
|
||||
gPrefService.clearUserPref(kPrefName);
|
||||
gPrefService.clearUserPref(kPrefName);
|
||||
}
|
||||
|
||||
setupCleanSlate();
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -99,9 +99,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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
|
@ -55,7 +55,7 @@
|
||||
* @see nsIPrefService
|
||||
*/
|
||||
|
||||
[scriptable, uuid(56c35506-f14b-11d3-99d3-ddbfac2ccf65)]
|
||||
[scriptable, uuid(e0b6e170-691b-11e0-ae3e-0800200c9a66)]
|
||||
interface nsIPrefBranch : nsISupports
|
||||
{
|
||||
|
||||
@ -211,7 +211,6 @@ interface nsIPrefBranch : nsISupports
|
||||
* This method does nothing if this object is a default branch.
|
||||
*
|
||||
* @return NS_OK The user preference was successfully cleared.
|
||||
* @return Other The preference does not exist or have a user set value.
|
||||
*/
|
||||
void clearUserPref(in string aPrefName);
|
||||
|
||||
|
@ -47,7 +47,7 @@ interface nsIObserver;
|
||||
*
|
||||
* @see nsIPrefBranch
|
||||
*/
|
||||
[scriptable, uuid(74567534-eb94-4b1c-8f45-389643bfc555)]
|
||||
[scriptable, uuid(784de8e2-e72f-441a-ae74-9d5fdfe13be3)]
|
||||
interface nsIPrefBranch2 : nsIPrefBranch
|
||||
{
|
||||
/**
|
||||
|
@ -613,7 +613,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))
|
||||
{
|
||||
@ -629,9 +628,8 @@ PREF_ClearUserPref(const char *pref_name)
|
||||
|
||||
pref_DoCallback(pref_name);
|
||||
gDirty = PR_TRUE;
|
||||
rv = NS_OK;
|
||||
}
|
||||
return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
|
@ -100,8 +100,7 @@ function run_test() {
|
||||
// Nonexisting user preferences
|
||||
|
||||
do_check_eq(pb.prefHasUserValue("UserPref.nonexistent.hasUserValue"), false);
|
||||
do_check_throws(function() {
|
||||
pb.clearUserPref("UserPref.nonexistent.clearUserPref");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.clearUserPref("UserPref.nonexistent.clearUserPref"); // shouldn't throw
|
||||
do_check_eq(pb.getPrefType("UserPref.nonexistent.getPrefType"), PREF_INVALID);
|
||||
do_check_eq(pb.root, "");
|
||||
|
||||
|
@ -3393,8 +3393,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);
|
||||
|
@ -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();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user