dom/tests/mochitest/localstorage/test_localStorageEnablePref.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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>

mercurial