Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
1 <html xmlns="http://www.w3.org/1999/xhtml">
2 <head>
3 <title>localStorage enable preference test</title>
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
8 <script type="text/javascript">
10 SimpleTest.requestCompleteLog();
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 }
28 var storage;
29 function test1() {
30 is(typeof(window.localStorage), "object", "Storage is present");
31 storage = window.localStorage;
33 SpecialPowers.pushPrefEnv({"set": [["dom.storage.enabled", false]]}, test2);
34 }
36 function test2() {
37 is(window.localStorage, null, "Storage is null");
39 checkException(function() {storage.setItem("test", "value");}, "SecurityError");
41 SpecialPowers.pushPrefEnv({"set": [["dom.storage.enabled", true]]}, test3);
42 }
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 }
52 function doTest() {
53 SpecialPowers.pushPrefEnv({"set": [["dom.storage.enabled", true]]}, test1);
54 }
56 SimpleTest.waitForExplicitFinish();
58 </script>
60 </head>
62 <body onload="doTest();">
64 </body>
65 </html>