Bug 503971 - nsIContentPrefService methods should throw when passed a null setting name; r=myk sr=mconnor

This commit is contained in:
Geoff Lankow 2009-08-24 19:12:04 +02:00
Родитель 4d9b7e5a17
Коммит 02b24a12ab
3 изменённых файлов: 86 добавлений и 0 удалений

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

@ -81,6 +81,7 @@ interface nsIContentPrefService : nsISupports
* @param aName the name of the pref to get
*
* @returns the value of the pref
* @throws NS_ERROR_ILLEGAL_VALUE if aName is null or an empty string
*/
nsIVariant getPref(in nsIURI aURI, in AString aName);
@ -91,6 +92,7 @@ interface nsIContentPrefService : nsISupports
* the global pref (applies to all URIs)
* @param aName the name of the pref to set
* @param aValue the new value of the pref
* @throws NS_ERROR_ILLEGAL_VALUE if aName is null or an empty string
*/
void setPref(in nsIURI aURI, in AString aName, in nsIVariant aValue);
@ -99,6 +101,7 @@ interface nsIContentPrefService : nsISupports
*
* @param aURI the URI for which to check for the pref
* @param aName the name of the pref to check for
* @throws NS_ERROR_ILLEGAL_VALUE if aName is null or an empty string
*/
boolean hasPref(in nsIURI aURI, in AString aName);
@ -107,6 +110,7 @@ interface nsIContentPrefService : nsISupports
*
* @param aURI the URI for which to remove the pref
* @param aName the name of the pref to remove
* @throws NS_ERROR_ILLEGAL_VALUE if aName is null or an empty string
*/
void removePref(in nsIURI aURI, in AString aName);
@ -120,6 +124,7 @@ interface nsIContentPrefService : nsISupports
* Remove all prefs with the given name.
*
* @param aName the setting name for which to remove prefs
* @throws NS_ERROR_ILLEGAL_VALUE if aName is null or an empty string
*/
void removePrefsByName(in AString aName);
@ -138,6 +143,7 @@ interface nsIContentPrefService : nsISupports
* @param aName the setting name for which to retrieve prefs
*
* @returns a property bag of prefs
* @throws NS_ERROR_ILLEGAL_VALUE if aName is null or an empty string
*/
nsIPropertyBag2 getPrefsByName(in AString aName);

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

@ -128,6 +128,10 @@ ContentPrefService.prototype = {
// nsIContentPrefService
getPref: function ContentPrefService_getPref(aURI, aName) {
if (!aName)
throw Components.Exception("aName cannot be null or an empty string",
Cr.NS_ERROR_ILLEGAL_VALUE);
if (aURI) {
var group = this.grouper.group(aURI);
return this._selectPref(group, aName);
@ -232,6 +236,10 @@ ContentPrefService.prototype = {
},
removePrefsByName: function ContentPrefService_removePrefsByName(aName) {
if (!aName)
throw Components.Exception("aName cannot be null or an empty string",
Cr.NS_ERROR_ILLEGAL_VALUE);
var settingID = this._selectSettingID(aName);
if (!settingID) {
return;
@ -280,6 +288,10 @@ ContentPrefService.prototype = {
},
getPrefsByName: function ContentPrefService_getPrefsByName(aName) {
if (!aName)
throw Components.Exception("aName cannot be null or an empty string",
Cr.NS_ERROR_ILLEGAL_VALUE);
return this._selectPrefsByName(aName);
},

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

@ -0,0 +1,68 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Content Preferences (cpref).
*
* The Initial Developer of the Original Code is Mozilla.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Geoff Lankow <geoff@darktrojan.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
function run_test() {
var cps = Cc["@mozilla.org/content-pref/service;1"].
getService(Ci.nsIContentPrefService);
var uri = ContentPrefTest.getURI("http://www.example.com/");
do_check_thrown(function () { cps.setPref(uri, null, 8); });
do_check_thrown(function () { cps.hasPref(uri, null); });
do_check_thrown(function () { cps.getPref(uri, null); });
do_check_thrown(function () { cps.removePref(uri, null); });
do_check_thrown(function () { cps.getPrefsByName(null); });
do_check_thrown(function () { cps.removePrefsByName(null); });
do_check_thrown(function () { cps.setPref(uri, "", 21); });
do_check_thrown(function () { cps.hasPref(uri, ""); });
do_check_thrown(function () { cps.getPref(uri, ""); });
do_check_thrown(function () { cps.removePref(uri, ""); });
do_check_thrown(function () { cps.getPrefsByName(""); });
do_check_thrown(function () { cps.removePrefsByName(""); });
}
function do_check_thrown (aCallback) {
var exThrown = false;
try {
aCallback();
do_throw("NS_ERROR_ILLEGAL_VALUE should have been thrown here");
} catch (e) {
do_check_eq(e.result, Cr.NS_ERROR_ILLEGAL_VALUE);
exThrown = true;
}
do_check_true(exThrown);
}