This helps share the logic to create the DevToolsServer and better highlights tab-debugger client (createLocalClientForTests) versus browser-toolbox-debugger client (spawnClientToDebugSystemPrincipal). Differential Revision: https://phabricator.services.mozilla.com/D319532
128 lines
3.7 KiB
HTML
128 lines
3.7 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
Bug 943251 - Test preferences actor
|
|
-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Test Preference Actor</title>
|
|
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
|
|
</head>
|
|
<body>
|
|
<pre id="test">
|
|
<script>
|
|
"use strict";
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
async function runTests() {
|
|
const {require} = ChromeUtils.importESModule("resource://devtools/shared/loader/Loader.sys.mjs");
|
|
const {
|
|
createLocalClientForTests,
|
|
} = require("resource://devtools/shared/commands/commands-factory.js");
|
|
|
|
const client = await createLocalClientForTests();
|
|
|
|
const p = await client.mainRoot.getFront("preference");
|
|
|
|
const prefs = {};
|
|
|
|
const localPref = {
|
|
boolPref: true,
|
|
intPref: 0x1234,
|
|
charPref: "Hello World",
|
|
};
|
|
|
|
async function checkValues() {
|
|
is(prefs.boolPref, localPref.boolPref, "read/write bool pref");
|
|
is(prefs.intPref, localPref.intPref, "read/write int pref");
|
|
is(prefs.charPref, localPref.charPref, "read/write string pref");
|
|
|
|
["test.all.bool", "test.all.int", "test.all.string"].forEach(function(key) {
|
|
let expectedValue;
|
|
switch (Services.prefs.getPrefType(key)) {
|
|
case Ci.nsIPrefBranch.PREF_STRING:
|
|
expectedValue = Services.prefs.getCharPref(key);
|
|
break;
|
|
case Ci.nsIPrefBranch.PREF_INT:
|
|
expectedValue = Services.prefs.getIntPref(key);
|
|
break;
|
|
case Ci.nsIPrefBranch.PREF_BOOL:
|
|
expectedValue = Services.prefs.getBoolPref(key);
|
|
break;
|
|
default:
|
|
ok(false, "unexpected pref type (" + key + ")");
|
|
break;
|
|
}
|
|
|
|
is(prefs.allPrefs[key].value, expectedValue,
|
|
"valid preference value (" + key + ")");
|
|
is(prefs.allPrefs[key].hasUserValue, Services.prefs.prefHasUserValue(key),
|
|
"valid hasUserValue (" + key + ")");
|
|
});
|
|
|
|
["test.bool", "test.int", "test.string"].forEach(function(key) {
|
|
ok(!prefs.allPrefs.hasOwnProperty(key), "expect no pref (" + key + ")");
|
|
is(Services.prefs.getPrefType(key), Ci.nsIPrefBranch.PREF_INVALID,
|
|
"pref (" + key + ") is clear");
|
|
});
|
|
}
|
|
|
|
function checkUndefined() {
|
|
let next = p.getCharPref("test.undefined");
|
|
next = next.then(
|
|
() => ok(false, "getCharPref should've thrown for an undefined preference"),
|
|
(ex) => {
|
|
const messageRe = new RegExp(
|
|
"Protocol error \\(Error\\): preference is not of the right type: " +
|
|
`test.undefined from: ${p.actorID} ` +
|
|
"\\(resource://devtools/server/actors/preference.js:\\d+:\\d+\\)"
|
|
);
|
|
ok(messageRe.test(ex.message), "Error message matches the expected format, got:" + ex.message);
|
|
}
|
|
);
|
|
return next;
|
|
}
|
|
|
|
function updatePrefsProperty(key, value) {
|
|
prefs[key] = value;
|
|
}
|
|
|
|
updatePrefsProperty("allPrefs", await p.getAllPrefs());
|
|
|
|
await Promise.all([
|
|
p.setBoolPref("test.bool", localPref.boolPref),
|
|
p.setIntPref("test.int", localPref.intPref),
|
|
p.setCharPref("test.string", localPref.charPref)
|
|
]);
|
|
updatePrefsProperty("boolPref", await p.getBoolPref("test.bool"));
|
|
updatePrefsProperty("intPref", await p.getIntPref("test.int"));;
|
|
updatePrefsProperty("charPref", await p.getCharPref("test.string"));
|
|
await Promise.all([
|
|
p.clearUserPref("test.bool"),
|
|
p.clearUserPref("test.int"),
|
|
p.clearUserPref("test.string")
|
|
]);
|
|
|
|
await checkUndefined();
|
|
await checkValues();
|
|
|
|
await client.close();
|
|
SimpleTest.finish();
|
|
}
|
|
|
|
window.onload = function() {
|
|
SpecialPowers.pushPrefEnv({
|
|
"set": [
|
|
["test.all.bool", true],
|
|
["test.all.int", 0x4321],
|
|
["test.all.string", "allizom"],
|
|
],
|
|
}, runTests);
|
|
};
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|