tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_localStorageQuota.html (4668B)


      1 <html xmlns="http://www.w3.org/1999/xhtml">
      2 <head>
      3 <title>localStorage and DOM quota test</title>
      4 
      5 <script 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" />
      8 
      9 <script type="text/javascript">
     10 //Note: this test is currently giving failures when running standalone, see bug 914865
     11 
     12 var currentTest = 1;
     13 
     14 function doNextTest()
     15 {
     16  slave = frame;
     17 
     18  switch (currentTest)
     19  {
     20    case 1:
     21      if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) {
     22        slaveOrigin = "http://test1.example.com";
     23      } else {
     24        slaveOrigin = "http://example.com";
     25      }
     26      slave.location = slaveOrigin + slavePath + "frameQuota.html?add&A&success";
     27      break;
     28 
     29    // Now set another key with length 500 bytes, i.e. allocate 501 bytes
     30    case 2:
     31      slaveOrigin = "http://test1.example.com";
     32      slave.location = slaveOrigin + slavePath + "frameQuota.html?add&B&success";
     33      break;
     34 
     35    // Try to set the same key value again to check we don't fail
     36    // even 1002 bytes has already been exhausted from the quota
     37    // We just change the value of an existing key.
     38    case 3:
     39      slaveOrigin = "http://test1.example.com";
     40      slave.location = slaveOrigin + slavePath + "frameQuota.html?add&B&success";
     41      break;
     42 
     43    // Try to set the same key to a larger value that would lead to
     44    // quota reach and check that the value is still the old one
     45    case 4:
     46      slaveOrigin = "http://test1.example.com";
     47      slave.location = slaveOrigin + slavePath + "frameQuota.html?add2&B&failure";
     48      break;
     49 
     50    // Try to set a new 500 bytes key and check we fail because we are over the
     51    // quota.
     52    case 5:
     53      if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) {
     54        slaveOrigin = "http://test1.example.com";
     55      } else if (SpecialPowers.Services.appinfo.fissionAutostart){
     56        // Fission makes the "https://test2.example.com" run in the different
     57        // process with the other two and Legacy LS has issues with usage
     58        // synchronization within processes, see Bug 1683299 for more details.
     59        slaveOrigin = "http://test2.example.com";
     60      } else {
     61        slaveOrigin = "https://test2.example.com";
     62      }
     63      slave.location = slaveOrigin + slavePath + "frameQuota.html?add&C&failure";
     64      break;
     65 
     66    // Remove the second key, it must not fail. This should release the
     67    // allocated space of the quota assigned to test1.example.com.
     68    case 6:
     69      slaveOrigin = "http://test1.example.com";
     70      slave.location = slaveOrigin + slavePath + "frameQuota.html?remove&B&success";
     71      break;
     72 
     73    // Now try again to set 500 bytes key, it must succeed.
     74    case 7:
     75      if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) {
     76        slaveOrigin = "http://test1.example.com";
     77      } else if (SpecialPowers.Services.appinfo.fissionAutostart){
     78        slaveOrigin = "http://test2.example.com";
     79      } else {
     80        slaveOrigin = "https://test2.example.com";
     81      }
     82      slave.location = slaveOrigin + slavePath + "frameQuota.html?add&C&success";
     83      break;
     84 
     85    case 8:
     86      if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) {
     87        SimpleTest.executeSoon(doNextTest);
     88      } else {
     89        // Do a clean up...
     90        slaveOrigin = "http://example.com";
     91        slave.location = slaveOrigin + slavePath + "frameQuota.html?clear";
     92      }
     93      break;
     94 
     95    case 9:
     96      // Do a clean up...
     97      slaveOrigin = "http://test1.example.com";
     98      slave.location = slaveOrigin + slavePath + "frameQuota.html?clear";
     99      break;
    100 
    101    case 10:
    102      if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) {
    103        SimpleTest.executeSoon(doNextTest);
    104      } else {
    105        // Do a clean up...
    106        slaveOrigin = "https://test2.example.com";
    107        slave.location = slaveOrigin + slavePath + "frameQuota.html?clear";
    108      }
    109      break;
    110 
    111    default: // end
    112      SimpleTest.finish();
    113  }
    114 
    115  ++currentTest;
    116 }
    117 
    118 function doStep()
    119 {
    120 }
    121 
    122 SimpleTest.waitForExplicitFinish();
    123 
    124 function startTest() {
    125  // Initialy setup the quota to testing value of 1024B and
    126  // set a 500 bytes key with name length 1 (allocate 501 bytes)
    127  SpecialPowers.pushPrefEnv({"set": [["dom.storage.default_quota", 1], ["dom.storage.default_site_quota", 1], ["security.mixed_content.block_display_content", false], ["security.mixed_content.block_active_content", false]]}, doNextTest);
    128 }
    129 </script>
    130 
    131 </head>
    132 
    133 <body onload="startTest();">
    134  <iframe src="" name="frame"></iframe>
    135 </body>
    136 </html>