зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1094939 - Preferences actor should throw with the name for an unknown preference. r=ochameau
Differential Revision: https://phabricator.services.mozilla.com/D50728 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
d5351b1c6b
Коммит
ca5176f7cc
|
@ -4,11 +4,19 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { Ci } = require("chrome");
|
||||
const protocol = require("devtools/shared/protocol");
|
||||
const Services = require("Services");
|
||||
const { preferenceSpec } = require("devtools/shared/specs/preference");
|
||||
|
||||
const { PREF_STRING, PREF_INT, PREF_BOOL } = Services.prefs;
|
||||
|
||||
function ensurePrefType(name, expectedType) {
|
||||
const type = Services.prefs.getPrefType(name);
|
||||
if (type !== expectedType) {
|
||||
throw new Error(`preference is not of the right type: ${name}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normally the preferences are set using Services.prefs, but this actor allows
|
||||
* a debugger client to set preferences on the debuggee. This is particularly useful
|
||||
|
@ -23,14 +31,17 @@ var PreferenceActor = protocol.ActorClassWithSpec(preferenceSpec, {
|
|||
typeName: "preference",
|
||||
|
||||
getBoolPref: function(name) {
|
||||
ensurePrefType(name, PREF_BOOL);
|
||||
return Services.prefs.getBoolPref(name);
|
||||
},
|
||||
|
||||
getCharPref: function(name) {
|
||||
ensurePrefType(name, PREF_STRING);
|
||||
return Services.prefs.getCharPref(name);
|
||||
},
|
||||
|
||||
getIntPref: function(name) {
|
||||
ensurePrefType(name, PREF_INT);
|
||||
return Services.prefs.getIntPref(name);
|
||||
},
|
||||
|
||||
|
@ -41,13 +52,13 @@ var PreferenceActor = protocol.ActorClassWithSpec(preferenceSpec, {
|
|||
try {
|
||||
let value;
|
||||
switch (Services.prefs.getPrefType(name)) {
|
||||
case Ci.nsIPrefBranch.PREF_STRING:
|
||||
case PREF_STRING:
|
||||
value = Services.prefs.getCharPref(name);
|
||||
break;
|
||||
case Ci.nsIPrefBranch.PREF_INT:
|
||||
case PREF_INT:
|
||||
value = Services.prefs.getIntPref(name);
|
||||
break;
|
||||
case Ci.nsIPrefBranch.PREF_BOOL:
|
||||
case PREF_BOOL:
|
||||
value = Services.prefs.getBoolPref(name);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -77,6 +77,21 @@ function runTests() {
|
|||
});
|
||||
}
|
||||
|
||||
function checkUndefined() {
|
||||
let next = p.getCharPref("test.undefined");
|
||||
next = next.then(
|
||||
() => ok(false, "getCharPref should've thrown for an undefined preference"),
|
||||
(ex) => {
|
||||
is(
|
||||
ex,
|
||||
"Protocol error (unknownError): preference is not of the right type: test.undefined",
|
||||
"getCharPref should throw an exception with the preference name"
|
||||
);
|
||||
}
|
||||
);
|
||||
return next;
|
||||
}
|
||||
|
||||
function updatePrefsProperty(key) {
|
||||
return function(value) {
|
||||
prefs[key] = value;
|
||||
|
@ -93,6 +108,7 @@ function runTests() {
|
|||
.then(() => p.clearUserPref("test.bool"))
|
||||
.then(() => p.clearUserPref("test.int"))
|
||||
.then(() => p.clearUserPref("test.string"))
|
||||
.then(() => checkUndefined())
|
||||
.then(checkValues);
|
||||
});
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче