1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/mochitest/test_preference.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,115 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +Bug 943251 - Allow accessing about:config from app-manager 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Test Preference Actor</title> 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 1.14 +</head> 1.15 +<body> 1.16 +<pre id="test"> 1.17 +<script> 1.18 + 1.19 +function runTests() { 1.20 + var Cu = Components.utils; 1.21 + var Cc = Components.classes; 1.22 + var Ci = Components.interfaces; 1.23 + 1.24 + Cu.import("resource://gre/modules/devtools/Loader.jsm"); 1.25 + Cu.import("resource://gre/modules/devtools/dbg-client.jsm"); 1.26 + Cu.import("resource://gre/modules/devtools/dbg-server.jsm"); 1.27 + Cu.import("resource://gre/modules/Services.jsm"); 1.28 + 1.29 + SimpleTest.waitForExplicitFinish(); 1.30 + 1.31 + var {getPreferenceFront} = devtools.require("devtools/server/actors/preference"); 1.32 + 1.33 + DebuggerServer.init(function () { return true; }); 1.34 + DebuggerServer.addBrowserActors(); 1.35 + 1.36 + var client = new DebuggerClient(DebuggerServer.connectPipe()); 1.37 + client.connect(function onConnect() { 1.38 + client.listTabs(function onListTabs(aResponse) { 1.39 + var p = getPreferenceFront(client, aResponse); 1.40 + 1.41 + var prefs = {}; 1.42 + 1.43 + var localPref = { 1.44 + boolPref: true, 1.45 + intPref: 0x1234, 1.46 + charPref: "Hello World", 1.47 + }; 1.48 + 1.49 + 1.50 + function checkValues() { 1.51 + is(prefs.boolPref, localPref.boolPref, "read/write bool pref"); 1.52 + is(prefs.intPref, localPref.intPref, "read/write int pref"); 1.53 + is(prefs.charPref, localPref.charPref, "read/write string pref"); 1.54 + 1.55 + ["test.all.bool", "test.all.int", "test.all.string"].forEach(function(key) { 1.56 + var expectedValue; 1.57 + switch(Services.prefs.getPrefType(key)) { 1.58 + case Ci.nsIPrefBranch.PREF_STRING: 1.59 + expectedValue = Services.prefs.getCharPref(key); 1.60 + break; 1.61 + case Ci.nsIPrefBranch.PREF_INT: 1.62 + expectedValue = Services.prefs.getIntPref(key); 1.63 + break; 1.64 + case Ci.nsIPrefBranch.PREF_BOOL: 1.65 + expectedValue = Services.prefs.getBoolPref(key); 1.66 + break; 1.67 + default: 1.68 + ok(false, "unexpected pref type (" + key + ")"); 1.69 + break; 1.70 + } 1.71 + 1.72 + is(prefs.allPrefs[key].value, expectedValue, "valid preference value (" + key + ")"); 1.73 + is(prefs.allPrefs[key].hasUserValue, Services.prefs.prefHasUserValue(key), "valid hasUserValue (" + key + ")"); 1.74 + }); 1.75 + 1.76 + ["test.bool", "test.int", "test.string"].forEach(function(key) { 1.77 + ok(!prefs.allPrefs.hasOwnProperty(key), "expect no pref (" + key + ")"); 1.78 + is(Services.prefs.getPrefType(key), Ci.nsIPrefBranch.PREF_INVALID, "pref (" + key + ") is clear"); 1.79 + }); 1.80 + 1.81 + client.close(() => { 1.82 + DebuggerServer.destroy(); 1.83 + SimpleTest.finish() 1.84 + }); 1.85 + } 1.86 + 1.87 + 1.88 + p.getAllPrefs().then((json) => prefs["allPrefs"] = json) 1.89 + .then(() => p.setBoolPref("test.bool", localPref.boolPref)) 1.90 + .then(() => p.setIntPref("test.int", localPref.intPref)) 1.91 + .then(() => p.setCharPref("test.string", localPref.charPref)) 1.92 + .then(() => p.getBoolPref("test.bool")).then((value) => prefs["boolPref"] = value) 1.93 + .then(() => p.getIntPref("test.int")).then((value) => prefs["intPref"] = value) 1.94 + .then(() => p.getCharPref("test.string")).then((value) => prefs["charPref"] = value) 1.95 + .then(() => p.clearUserPref("test.bool")) 1.96 + .then(() => p.clearUserPref("test.int")) 1.97 + .then(() => p.clearUserPref("test.string")) 1.98 + .then(checkValues); 1.99 + 1.100 + }); 1.101 + }); 1.102 + 1.103 +} 1.104 + 1.105 +window.onload = function () { 1.106 + SpecialPowers.pushPrefEnv({ 1.107 + "set": [ 1.108 + ["devtools.debugger.forbid-certified-apps", false], 1.109 + ["test.all.bool", true], 1.110 + ["test.all.int", 0x4321], 1.111 + ["test.all.string", "allizom"], 1.112 + ] 1.113 + }, runTests); 1.114 +} 1.115 +</script> 1.116 +</pre> 1.117 +</body> 1.118 +</html>