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