|
1 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
2 <head> |
|
3 <title>localStorage enable preference test</title> |
|
4 |
|
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
7 |
|
8 <script type="text/javascript"> |
|
9 |
|
10 SimpleTest.requestCompleteLog(); |
|
11 |
|
12 function checkException(func, exc) |
|
13 { |
|
14 var exceptionThrew = false; |
|
15 try { |
|
16 func(); |
|
17 } |
|
18 catch (ex) { |
|
19 exceptionThrew = true; |
|
20 is(ex.name, exc, "Expected "+exc+" exception"); |
|
21 if (ex.name != exc) { |
|
22 info("The exception which was thrown is: " + ex); |
|
23 } |
|
24 } |
|
25 ok(exceptionThrew, "Exception "+exc+" threw"); |
|
26 } |
|
27 |
|
28 var storage; |
|
29 function test1() { |
|
30 is(typeof(window.localStorage), "object", "Storage is present"); |
|
31 storage = window.localStorage; |
|
32 |
|
33 SpecialPowers.pushPrefEnv({"set": [["dom.storage.enabled", false]]}, test2); |
|
34 } |
|
35 |
|
36 function test2() { |
|
37 is(window.localStorage, null, "Storage is null"); |
|
38 |
|
39 checkException(function() {storage.setItem("test", "value");}, "SecurityError"); |
|
40 |
|
41 SpecialPowers.pushPrefEnv({"set": [["dom.storage.enabled", true]]}, test3); |
|
42 } |
|
43 |
|
44 function test3() { |
|
45 is(typeof(window.localStorage), "object", "Storage is present again"); |
|
46 storage.setItem("test", "value"); |
|
47 ok(storage.getItem("test"), "value", "value can be set"); |
|
48 window.localStorage.clear(); |
|
49 SimpleTest.finish(); |
|
50 } |
|
51 |
|
52 function doTest() { |
|
53 SpecialPowers.pushPrefEnv({"set": [["dom.storage.enabled", true]]}, test1); |
|
54 } |
|
55 |
|
56 SimpleTest.waitForExplicitFinish(); |
|
57 |
|
58 </script> |
|
59 |
|
60 </head> |
|
61 |
|
62 <body onload="doTest();"> |
|
63 |
|
64 </body> |
|
65 </html> |