1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
<!DOCTYPE HTML>
<html>
<!--
Bug 943251 - Allow accessing about:config from WebIDE
-->
<head>
<meta charset="utf-8">
<title>Test Preference Actor</title>
<script type="application/javascript" 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>
function runTests() {
var Cu = Components.utils;
var Cc = Components.classes;
var Ci = Components.interfaces;
var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var {DebuggerClient} = require("devtools/shared/client/main");
var {DebuggerServer} = require("devtools/server/main");
var Services = require("Services");
SimpleTest.waitForExplicitFinish();
var {getPreferenceFront} = require("devtools/shared/fronts/preference");
DebuggerServer.init();
DebuggerServer.addBrowserActors();
var client = new DebuggerClient(DebuggerServer.connectPipe());
client.connect().then(function onConnect() {
client.listTabs(function onListTabs(aResponse) {
var p = getPreferenceFront(client, aResponse);
var prefs = {};
var localPref = {
boolPref: true,
intPref: 0x1234,
charPref: "Hello World",
};
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) {
var 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");
});
client.close().then(() => {
DebuggerServer.destroy();
SimpleTest.finish()
});
}
p.getAllPrefs().then((json) => prefs["allPrefs"] = json)
.then(() => p.setBoolPref("test.bool", localPref.boolPref))
.then(() => p.setIntPref("test.int", localPref.intPref))
.then(() => p.setCharPref("test.string", localPref.charPref))
.then(() => p.getBoolPref("test.bool")).then((value) => prefs["boolPref"] = value)
.then(() => p.getIntPref("test.int")).then((value) => prefs["intPref"] = value)
.then(() => p.getCharPref("test.string")).then((value) => prefs["charPref"] = value)
.then(() => p.clearUserPref("test.bool"))
.then(() => p.clearUserPref("test.int"))
.then(() => p.clearUserPref("test.string"))
.then(checkValues);
});
});
}
window.onload = function () {
SpecialPowers.pushPrefEnv({
"set": [
["devtools.debugger.forbid-certified-apps", false],
["test.all.bool", true],
["test.all.int", 0x4321],
["test.all.string", "allizom"],
]
}, runTests);
}
</script>
</pre>
</body>
</html>
|