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