1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPrefEnv.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,211 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test for SpecialPowers extension</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.10 +</head> 1.11 +<body onload="starttest();"> 1.12 + 1.13 +<pre id="test"> 1.14 +<script class="testbody" type="text/javascript"> 1.15 +function starttest() { 1.16 + try { 1.17 + SpecialPowers.setBoolPref("test.bool", 1); 1.18 + } catch(e) { 1.19 + SpecialPowers.setBoolPref("test.bool", true); 1.20 + } 1.21 + try { 1.22 + SpecialPowers.setIntPref("test.int", true); 1.23 + } catch(e) { 1.24 + SpecialPowers.setIntPref("test.int", 1); 1.25 + } 1.26 + SpecialPowers.setCharPref("test.char", 'test'); 1.27 + 1.28 + setTimeout(test1, 0, 0); 1.29 +} 1.30 + 1.31 +SimpleTest.waitForExplicitFinish(); 1.32 + 1.33 +function test1(aCount) { 1.34 + if (aCount >= 20) { 1.35 + ok(false, "Too many times attempting to set pref, aborting"); 1.36 + SimpleTest.finish(); 1.37 + return; 1.38 + } 1.39 + 1.40 + try { 1.41 + is(SpecialPowers.getBoolPref('test.bool'), true, 'test.bool should be true'); 1.42 + } catch(e) { 1.43 + setTimeout(test1, 0, ++aCount); 1.44 + return; 1.45 + } 1.46 + 1.47 + try { 1.48 + is(SpecialPowers.getIntPref('test.int'), 1, 'test.int should be 1'); 1.49 + } catch(e) { 1.50 + setTimeout(test1, 0, ++aCount); 1.51 + return; 1.52 + } 1.53 + 1.54 + try { 1.55 + is(SpecialPowers.getCharPref('test.char'), 'test', 'test.char should be test'); 1.56 + } catch(e) { 1.57 + setTimeout(test1, 0, ++aCount); 1.58 + return; 1.59 + } 1.60 + 1.61 + test2(); 1.62 +} 1.63 + 1.64 +function test2() { 1.65 + // test non-changing values 1.66 + SpecialPowers.pushPrefEnv({"set": [["test.bool", true], ["test.int", 1], ["test.char", "test"]]}, test3); 1.67 +} 1.68 + 1.69 +function test3() { 1.70 + // test changing char pref 1.71 + is(SpecialPowers.getBoolPref('test.bool'), true, 'test.bool should be true'); 1.72 + is(SpecialPowers.getIntPref('test.int'), 1, 'test.int should be 1'); 1.73 + is(SpecialPowers.getCharPref('test.char'), 'test', 'test.char should be test'); 1.74 + SpecialPowers.pushPrefEnv({"set": [["test.bool", true], ["test.int", 1], ["test.char", "test2"]]}, test4); 1.75 +} 1.76 + 1.77 +function test4() { 1.78 + // test changing all values and adding test.char2 pref 1.79 + is(SpecialPowers.getCharPref('test.char'), 'test2', 'test.char should be test2'); 1.80 + SpecialPowers.pushPrefEnv({"set": [["test.bool", false], ["test.int", 10], ["test.char", "test2"], ["test.char2", "test"]]}, test5); 1.81 +} 1.82 + 1.83 +function test5() { 1.84 + // test flushPrefEnv 1.85 + is(SpecialPowers.getBoolPref('test.bool'), false, 'test.bool should be false'); 1.86 + is(SpecialPowers.getIntPref('test.int'), 10, 'test.int should be 10'); 1.87 + is(SpecialPowers.getCharPref('test.char'), 'test2', 'test.char should be test2'); 1.88 + is(SpecialPowers.getCharPref('test.char2'), 'test', 'test.char2 should be test'); 1.89 + SpecialPowers.flushPrefEnv(test6); 1.90 +} 1.91 + 1.92 +function test6() { 1.93 + // test clearing prefs 1.94 + is(SpecialPowers.getBoolPref('test.bool'), true, 'test.bool should be true'); 1.95 + is(typeof SpecialPowers.getBoolPref('test.bool'), typeof true, 'test.bool should be boolean'); 1.96 + is(SpecialPowers.getIntPref('test.int'), 1, 'test.int should be 1'); 1.97 + is(typeof SpecialPowers.getIntPref('test.int'), typeof 1, 'test.int should be integer'); 1.98 + is(SpecialPowers.getCharPref('test.char'), 'test', 'test.char should be test'); 1.99 + is(typeof SpecialPowers.getCharPref('test.char'), typeof 'test', 'test.char should be String'); 1.100 + try { 1.101 + SpecialPowers.getCharPref('test.char2'); 1.102 + ok(false, 'This ok should not be reached!'); 1.103 + } catch(e) { 1.104 + ok(true, 'getCharPref("test.char2") should throw'); 1.105 + } 1.106 + SpecialPowers.pushPrefEnv({"clear": [["test.bool"], ["test.int"], ["test.char"], ["test.char2"]]}, test6b); 1.107 +} 1.108 + 1.109 +function test6b() { 1.110 + // test if clearing another time doesn't cause issues 1.111 + SpecialPowers.pushPrefEnv({"clear": [["test.bool"], ["test.int"], ["test.char"], ["test.char2"]]}, test7); 1.112 +} 1.113 + 1.114 +function test7() { 1.115 + try { 1.116 + SpecialPowers.getBoolPref('test.bool'); 1.117 + ok(false, 'This ok should not be reached!'); 1.118 + } catch(e) { 1.119 + ok(true, 'getBoolPref("test.bool") should throw'); 1.120 + } 1.121 + 1.122 + try { 1.123 + SpecialPowers.getIntPref('test.int'); 1.124 + ok(false, 'This ok should not be reached!'); 1.125 + } catch(e) { 1.126 + ok(true, 'getIntPref("test.int") should throw'); 1.127 + } 1.128 + 1.129 + try { 1.130 + SpecialPowers.getCharPref('test.char'); 1.131 + ok(false, 'This ok should not be reached!'); 1.132 + } catch(e) { 1.133 + ok(true, 'getCharPref("test.char") should throw'); 1.134 + } 1.135 + 1.136 + try { 1.137 + SpecialPowers.getCharPref('test.char2'); 1.138 + ok(false, 'This ok should not be reached!'); 1.139 + } catch(e) { 1.140 + ok(true, 'getCharPref("test.char2") should throw'); 1.141 + } 1.142 + 1.143 + SpecialPowers.flushPrefEnv(test8); 1.144 +} 1.145 + 1.146 +function test8() { 1.147 + is(SpecialPowers.getBoolPref('test.bool'), true, 'test.bool should be true'); 1.148 + is(typeof SpecialPowers.getBoolPref('test.bool'), typeof true, 'test.bool should be boolean'); 1.149 + is(SpecialPowers.getIntPref('test.int'), 1, 'test.int should be 1'); 1.150 + is(typeof SpecialPowers.getIntPref('test.int'), typeof 1, 'test.int should be integer'); 1.151 + is(SpecialPowers.getCharPref('test.char'), 'test', 'test.char should be test'); 1.152 + is(typeof SpecialPowers.getCharPref('test.char'), typeof 'test', 'test.char should be String'); 1.153 + try { 1.154 + SpecialPowers.getCharPref('test.char2'); 1.155 + ok(false, 'This ok should not be reached!'); 1.156 + } catch(e) { 1.157 + ok(true, 'getCharPref("test.char2") should throw'); 1.158 + } 1.159 + SpecialPowers.clearUserPref("test.bool"); 1.160 + SpecialPowers.clearUserPref("test.int"); 1.161 + SpecialPowers.clearUserPref("test.char"); 1.162 + setTimeout(test9, 0, 0); 1.163 +} 1.164 + 1.165 +function test9(aCount) { 1.166 + if (aCount >= 20) { 1.167 + ok(false, "Too many times attempting to set pref, aborting"); 1.168 + SimpleTest.finish(); 1.169 + return; 1.170 + } 1.171 + 1.172 + try { 1.173 + SpecialPowers.getBoolPref('test.bool'); 1.174 + setTimeout(test9, 0, ++aCount); 1.175 + } catch(e) { 1.176 + test10(0); 1.177 + } 1.178 +} 1.179 + 1.180 +function test10(aCount) { 1.181 + if (aCount >= 20) { 1.182 + ok(false, "Too many times attempting to set pref, aborting"); 1.183 + SimpleTest.finish(); 1.184 + return; 1.185 + } 1.186 + 1.187 + try { 1.188 + SpecialPowers.getIntPref('test.int'); 1.189 + setTimeout(test10, 0, ++aCount); 1.190 + } catch(e) { 1.191 + test11(0); 1.192 + } 1.193 +} 1.194 + 1.195 +function test11(aCount) { 1.196 + if (aCount >= 20) { 1.197 + ok(false, "Too many times attempting to set pref, aborting"); 1.198 + SimpleTest.finish(); 1.199 + return; 1.200 + } 1.201 + 1.202 + try { 1.203 + SpecialPowers.getCharPref('test.char'); 1.204 + setTimeout(test11, 0, ++aCount); 1.205 + } catch(e) { 1.206 + SimpleTest.finish(); 1.207 + } 1.208 +} 1.209 +// todo - test non-changing values, test complex values, test mixing of pushprefEnv 'set' and 'clear' 1.210 +// When bug 776424 gets fixed, getPref doesn't throw anymore, so this test would have to be changed accordingly 1.211 +</script> 1.212 +</pre> 1.213 +</body> 1.214 +</html>