dom/tests/mochitest/localstorage/test_localStorageEnablePref.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/localstorage/test_localStorageEnablePref.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,65 @@
     1.4 +<html xmlns="http://www.w3.org/1999/xhtml">
     1.5 +<head>
     1.6 +<title>localStorage enable preference test</title>
     1.7 +
     1.8 +<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.10 +
    1.11 +<script type="text/javascript">
    1.12 +
    1.13 +SimpleTest.requestCompleteLog();
    1.14 +
    1.15 +function checkException(func, exc)
    1.16 +{
    1.17 +  var exceptionThrew = false;
    1.18 +  try {
    1.19 +    func();
    1.20 +  }
    1.21 +  catch (ex) {
    1.22 +    exceptionThrew = true;
    1.23 +    is(ex.name, exc, "Expected "+exc+" exception");
    1.24 +    if (ex.name != exc) {
    1.25 +      info("The exception which was thrown is: " + ex);
    1.26 +    }
    1.27 +  }
    1.28 +  ok(exceptionThrew, "Exception "+exc+" threw");
    1.29 +}
    1.30 +
    1.31 +var storage;
    1.32 +function test1() {
    1.33 +  is(typeof(window.localStorage), "object", "Storage is present");
    1.34 +  storage = window.localStorage;
    1.35 +
    1.36 +  SpecialPowers.pushPrefEnv({"set": [["dom.storage.enabled", false]]}, test2);
    1.37 +}
    1.38 +
    1.39 +function test2() {
    1.40 +  is(window.localStorage, null, "Storage is null");
    1.41 +
    1.42 +  checkException(function() {storage.setItem("test", "value");}, "SecurityError");
    1.43 +
    1.44 +  SpecialPowers.pushPrefEnv({"set": [["dom.storage.enabled", true]]}, test3);
    1.45 +}
    1.46 +
    1.47 +function test3() {
    1.48 +  is(typeof(window.localStorage), "object", "Storage is present again");
    1.49 +  storage.setItem("test", "value");
    1.50 +  ok(storage.getItem("test"), "value", "value can be set");
    1.51 +  window.localStorage.clear();
    1.52 +  SimpleTest.finish();
    1.53 +}
    1.54 +
    1.55 +function doTest() {
    1.56 +  SpecialPowers.pushPrefEnv({"set": [["dom.storage.enabled", true]]}, test1);
    1.57 +}
    1.58 +
    1.59 +SimpleTest.waitForExplicitFinish();
    1.60 +
    1.61 +</script>
    1.62 +
    1.63 +</head>
    1.64 +
    1.65 +<body onload="doTest();">
    1.66 +
    1.67 +</body>
    1.68 +</html>

mercurial