dom/tests/mochitest/localstorage/test_localStorageQuota.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 and DOM quota test</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">
    10 //Note: this test is currently giving failures when running standalone, see bug 914865
    12 var currentTest = 1;
    14 function doNextTest()
    15 {
    16   slave = frame;
    18   switch (currentTest)
    19   {
    20     case 1:
    21       slaveOrigin = "http://example.com";
    22       slave.location = slaveOrigin + slavePath + "frameQuota.html?add&A&success";
    23       break;
    25     // In subdomain now set another key with length 500 bytes, i.e.
    26     // allocate 501 bytes
    27     case 2:
    28       slaveOrigin = "http://test1.example.com";
    29       slave.location = slaveOrigin + slavePath + "frameQuota.html?add&B&success";
    30       break;
    32     // Try to set the same key value again to check we don't fail
    33     // even 1002 bytes has already been exhausted from the quota
    34     // We just change the value of an existing key.
    35     case 3:
    36       slaveOrigin = "http://test1.example.com";
    37       slave.location = slaveOrigin + slavePath + "frameQuota.html?add&B&success";
    38       break;
    40     // Try to set the same key to a larger value that would lead to
    41     // quota reach and check that the value is still the old one
    42     case 4:
    43       slaveOrigin = "http://test1.example.com";
    44       slave.location = slaveOrigin + slavePath + "frameQuota.html?add2&B&failure";
    45       break;
    47     // In a different subdomain try to set a new 500 bytes key
    48     // and check we fail because we are over the quota
    49     case 5:
    50       slaveOrigin = "https://test2.example.com";
    51       slave.location = slaveOrigin + slavePath + "frameQuota.html?add&C&failure";
    52       break;
    54     // Remove from the second subdomain the second key, it must not fail
    55     // This should release the allocated space of the quota assigned to
    56     // example.com.
    57     case 6:
    58       slaveOrigin = "http://test1.example.com";
    59       slave.location = slaveOrigin + slavePath + "frameQuota.html?remove&B&success";
    60       break;
    62     // Now try again to set 500 bytes key, it must succeed.
    63     case 7:
    64       slaveOrigin = "https://test2.example.com";
    65       slave.location = slaveOrigin + slavePath + "frameQuota.html?add&C&success";
    66       break;
    68     case 8:
    69       // Do a clean up...
    70       slaveOrigin = "http://example.com";
    71       slave.location = slaveOrigin + slavePath + "frameQuota.html?clear";
    72       break;
    74     case 9:
    75       // Do a clean up...
    76       slaveOrigin = "http://test1.example.com";
    77       slave.location = slaveOrigin + slavePath + "frameQuota.html?clear";
    78       break;
    80     case 10:
    81       // Do a clean up...
    82       slaveOrigin = "https://test2.example.com";
    83       slave.location = slaveOrigin + slavePath + "frameQuota.html?clear";
    84       break;
    86     default: // end
    87       SimpleTest.finish();
    88   }
    90   ++currentTest;
    91 }
    93 function doStep()
    94 {
    95 }
    97 SimpleTest.waitForExplicitFinish();
    99 function startTest() {
   100   // Initialy setup the quota to testing value of 1024B and
   101   // set a 500 bytes key with name length 1 (allocate 501 bytes)
   102   SpecialPowers.pushPrefEnv({"set": [["dom.storage.default_quota", 1], ["security.mixed_content.block_display_content", false], ["security.mixed_content.block_active_content", false]]}, doNextTest);
   103 }
   104 </script>
   106 </head>
   108 <body onload="startTest();">
   109   <iframe src="" name="frame"></iframe>
   110 </body>
   111 </html>

mercurial