testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPrefEnv.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test for SpecialPowers extension</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 7 </head>
michael@0 8 <body onload="starttest();">
michael@0 9
michael@0 10 <pre id="test">
michael@0 11 <script class="testbody" type="text/javascript">
michael@0 12 function starttest() {
michael@0 13 try {
michael@0 14 SpecialPowers.setBoolPref("test.bool", 1);
michael@0 15 } catch(e) {
michael@0 16 SpecialPowers.setBoolPref("test.bool", true);
michael@0 17 }
michael@0 18 try {
michael@0 19 SpecialPowers.setIntPref("test.int", true);
michael@0 20 } catch(e) {
michael@0 21 SpecialPowers.setIntPref("test.int", 1);
michael@0 22 }
michael@0 23 SpecialPowers.setCharPref("test.char", 'test');
michael@0 24
michael@0 25 setTimeout(test1, 0, 0);
michael@0 26 }
michael@0 27
michael@0 28 SimpleTest.waitForExplicitFinish();
michael@0 29
michael@0 30 function test1(aCount) {
michael@0 31 if (aCount >= 20) {
michael@0 32 ok(false, "Too many times attempting to set pref, aborting");
michael@0 33 SimpleTest.finish();
michael@0 34 return;
michael@0 35 }
michael@0 36
michael@0 37 try {
michael@0 38 is(SpecialPowers.getBoolPref('test.bool'), true, 'test.bool should be true');
michael@0 39 } catch(e) {
michael@0 40 setTimeout(test1, 0, ++aCount);
michael@0 41 return;
michael@0 42 }
michael@0 43
michael@0 44 try {
michael@0 45 is(SpecialPowers.getIntPref('test.int'), 1, 'test.int should be 1');
michael@0 46 } catch(e) {
michael@0 47 setTimeout(test1, 0, ++aCount);
michael@0 48 return;
michael@0 49 }
michael@0 50
michael@0 51 try {
michael@0 52 is(SpecialPowers.getCharPref('test.char'), 'test', 'test.char should be test');
michael@0 53 } catch(e) {
michael@0 54 setTimeout(test1, 0, ++aCount);
michael@0 55 return;
michael@0 56 }
michael@0 57
michael@0 58 test2();
michael@0 59 }
michael@0 60
michael@0 61 function test2() {
michael@0 62 // test non-changing values
michael@0 63 SpecialPowers.pushPrefEnv({"set": [["test.bool", true], ["test.int", 1], ["test.char", "test"]]}, test3);
michael@0 64 }
michael@0 65
michael@0 66 function test3() {
michael@0 67 // test changing char pref
michael@0 68 is(SpecialPowers.getBoolPref('test.bool'), true, 'test.bool should be true');
michael@0 69 is(SpecialPowers.getIntPref('test.int'), 1, 'test.int should be 1');
michael@0 70 is(SpecialPowers.getCharPref('test.char'), 'test', 'test.char should be test');
michael@0 71 SpecialPowers.pushPrefEnv({"set": [["test.bool", true], ["test.int", 1], ["test.char", "test2"]]}, test4);
michael@0 72 }
michael@0 73
michael@0 74 function test4() {
michael@0 75 // test changing all values and adding test.char2 pref
michael@0 76 is(SpecialPowers.getCharPref('test.char'), 'test2', 'test.char should be test2');
michael@0 77 SpecialPowers.pushPrefEnv({"set": [["test.bool", false], ["test.int", 10], ["test.char", "test2"], ["test.char2", "test"]]}, test5);
michael@0 78 }
michael@0 79
michael@0 80 function test5() {
michael@0 81 // test flushPrefEnv
michael@0 82 is(SpecialPowers.getBoolPref('test.bool'), false, 'test.bool should be false');
michael@0 83 is(SpecialPowers.getIntPref('test.int'), 10, 'test.int should be 10');
michael@0 84 is(SpecialPowers.getCharPref('test.char'), 'test2', 'test.char should be test2');
michael@0 85 is(SpecialPowers.getCharPref('test.char2'), 'test', 'test.char2 should be test');
michael@0 86 SpecialPowers.flushPrefEnv(test6);
michael@0 87 }
michael@0 88
michael@0 89 function test6() {
michael@0 90 // test clearing prefs
michael@0 91 is(SpecialPowers.getBoolPref('test.bool'), true, 'test.bool should be true');
michael@0 92 is(typeof SpecialPowers.getBoolPref('test.bool'), typeof true, 'test.bool should be boolean');
michael@0 93 is(SpecialPowers.getIntPref('test.int'), 1, 'test.int should be 1');
michael@0 94 is(typeof SpecialPowers.getIntPref('test.int'), typeof 1, 'test.int should be integer');
michael@0 95 is(SpecialPowers.getCharPref('test.char'), 'test', 'test.char should be test');
michael@0 96 is(typeof SpecialPowers.getCharPref('test.char'), typeof 'test', 'test.char should be String');
michael@0 97 try {
michael@0 98 SpecialPowers.getCharPref('test.char2');
michael@0 99 ok(false, 'This ok should not be reached!');
michael@0 100 } catch(e) {
michael@0 101 ok(true, 'getCharPref("test.char2") should throw');
michael@0 102 }
michael@0 103 SpecialPowers.pushPrefEnv({"clear": [["test.bool"], ["test.int"], ["test.char"], ["test.char2"]]}, test6b);
michael@0 104 }
michael@0 105
michael@0 106 function test6b() {
michael@0 107 // test if clearing another time doesn't cause issues
michael@0 108 SpecialPowers.pushPrefEnv({"clear": [["test.bool"], ["test.int"], ["test.char"], ["test.char2"]]}, test7);
michael@0 109 }
michael@0 110
michael@0 111 function test7() {
michael@0 112 try {
michael@0 113 SpecialPowers.getBoolPref('test.bool');
michael@0 114 ok(false, 'This ok should not be reached!');
michael@0 115 } catch(e) {
michael@0 116 ok(true, 'getBoolPref("test.bool") should throw');
michael@0 117 }
michael@0 118
michael@0 119 try {
michael@0 120 SpecialPowers.getIntPref('test.int');
michael@0 121 ok(false, 'This ok should not be reached!');
michael@0 122 } catch(e) {
michael@0 123 ok(true, 'getIntPref("test.int") should throw');
michael@0 124 }
michael@0 125
michael@0 126 try {
michael@0 127 SpecialPowers.getCharPref('test.char');
michael@0 128 ok(false, 'This ok should not be reached!');
michael@0 129 } catch(e) {
michael@0 130 ok(true, 'getCharPref("test.char") should throw');
michael@0 131 }
michael@0 132
michael@0 133 try {
michael@0 134 SpecialPowers.getCharPref('test.char2');
michael@0 135 ok(false, 'This ok should not be reached!');
michael@0 136 } catch(e) {
michael@0 137 ok(true, 'getCharPref("test.char2") should throw');
michael@0 138 }
michael@0 139
michael@0 140 SpecialPowers.flushPrefEnv(test8);
michael@0 141 }
michael@0 142
michael@0 143 function test8() {
michael@0 144 is(SpecialPowers.getBoolPref('test.bool'), true, 'test.bool should be true');
michael@0 145 is(typeof SpecialPowers.getBoolPref('test.bool'), typeof true, 'test.bool should be boolean');
michael@0 146 is(SpecialPowers.getIntPref('test.int'), 1, 'test.int should be 1');
michael@0 147 is(typeof SpecialPowers.getIntPref('test.int'), typeof 1, 'test.int should be integer');
michael@0 148 is(SpecialPowers.getCharPref('test.char'), 'test', 'test.char should be test');
michael@0 149 is(typeof SpecialPowers.getCharPref('test.char'), typeof 'test', 'test.char should be String');
michael@0 150 try {
michael@0 151 SpecialPowers.getCharPref('test.char2');
michael@0 152 ok(false, 'This ok should not be reached!');
michael@0 153 } catch(e) {
michael@0 154 ok(true, 'getCharPref("test.char2") should throw');
michael@0 155 }
michael@0 156 SpecialPowers.clearUserPref("test.bool");
michael@0 157 SpecialPowers.clearUserPref("test.int");
michael@0 158 SpecialPowers.clearUserPref("test.char");
michael@0 159 setTimeout(test9, 0, 0);
michael@0 160 }
michael@0 161
michael@0 162 function test9(aCount) {
michael@0 163 if (aCount >= 20) {
michael@0 164 ok(false, "Too many times attempting to set pref, aborting");
michael@0 165 SimpleTest.finish();
michael@0 166 return;
michael@0 167 }
michael@0 168
michael@0 169 try {
michael@0 170 SpecialPowers.getBoolPref('test.bool');
michael@0 171 setTimeout(test9, 0, ++aCount);
michael@0 172 } catch(e) {
michael@0 173 test10(0);
michael@0 174 }
michael@0 175 }
michael@0 176
michael@0 177 function test10(aCount) {
michael@0 178 if (aCount >= 20) {
michael@0 179 ok(false, "Too many times attempting to set pref, aborting");
michael@0 180 SimpleTest.finish();
michael@0 181 return;
michael@0 182 }
michael@0 183
michael@0 184 try {
michael@0 185 SpecialPowers.getIntPref('test.int');
michael@0 186 setTimeout(test10, 0, ++aCount);
michael@0 187 } catch(e) {
michael@0 188 test11(0);
michael@0 189 }
michael@0 190 }
michael@0 191
michael@0 192 function test11(aCount) {
michael@0 193 if (aCount >= 20) {
michael@0 194 ok(false, "Too many times attempting to set pref, aborting");
michael@0 195 SimpleTest.finish();
michael@0 196 return;
michael@0 197 }
michael@0 198
michael@0 199 try {
michael@0 200 SpecialPowers.getCharPref('test.char');
michael@0 201 setTimeout(test11, 0, ++aCount);
michael@0 202 } catch(e) {
michael@0 203 SimpleTest.finish();
michael@0 204 }
michael@0 205 }
michael@0 206 // todo - test non-changing values, test complex values, test mixing of pushprefEnv 'set' and 'clear'
michael@0 207 // When bug 776424 gets fixed, getPref doesn't throw anymore, so this test would have to be changed accordingly
michael@0 208 </script>
michael@0 209 </pre>
michael@0 210 </body>
michael@0 211 </html>

mercurial