dom/tests/mochitest/sessionstorage/test_sessionStorageClone.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>sessionStorage clone equal origins</title>
     5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6 <script type="text/javascript" src="interOriginTest.js"></script>
     7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     9 <script type="text/javascript">
    11 var currentTest = 1;
    12 var currentStep = 1;
    14 /*
    15 window.addEventListener("storage", onStorageEvent, false);
    17 function onStorageEvent(event)
    18 {
    19 }
    20 */
    22 function doNextTest()
    23 {
    24   // We must perform the first step of the test
    25   // to prepare the land.
    26   currentStep = 1;
    27   doStep();
    29   switch (currentTest)
    30   {
    31     case 1:
    32       // Open a window from the same origin and check data
    33       // are copied but not further modified on our side
    34       slaveOrigin = "http://mochi.test:8888";
    35       slave = window.open(slaveOrigin + slavePath + "frameEqual.html");
    36       break;
    38     case 2:
    39       slave.close();
    40       // Open a window from a different origin and check data
    41       // are NOT copied and not modified on our side
    42       slaveOrigin = "http://example.com";
    43       slave = window.open(slaveOrigin + slavePath + "frameNotEqual.html");
    44       break;
    46     case 3:
    47       slave.close();
    48       sessionStorage.clear();
    49       SimpleTest.finish();
    50       break;
    51   }
    53   ++currentTest;
    54 }
    56 function doStep()
    57 {
    58   switch (currentStep)
    59   {
    60     case 1:
    61       sessionStorage.setItem("A", "1");
    62       sessionStorage.setItem("B", "2");
    63       is(sessionStorage.getItem("A"), "1", "A is 1 in the master");
    64       is(sessionStorage.getItem("B"), "2", "B is 2 in the master");
    65       is(sessionStorage.length, 2, "Num of items is 2");
    66       break;
    68     case 3:
    69       is(sessionStorage.getItem("A"), "1", "A is 1 in the master");
    70       is(sessionStorage.getItem("B"), "2", "B is 2 in the master");
    71       is(sessionStorage.getItem("C"), null, "C is null in the master");
    72       is(sessionStorage.length, 2, "Num of items is 2");
    74       sessionStorage.setItem("C", "4");
    75       is(sessionStorage.getItem("C"), "4", "C is 4 in the master");
    76       is(sessionStorage.length, 3, "Num of items is 3");
    77       break;
    78   }
    80   ++currentStep;
    81   ++currentStep;
    83   return true;
    84 }
    86 SimpleTest.waitForExplicitFinish();
    88 </script>
    90 </head>
    92 <body onload="doNextTest();">
    93 </body>
    94 </html>

mercurial