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.

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

mercurial