Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<head>
<title>localStorage enable preference test</title>
<script 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");
is(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>