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.

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

mercurial