test_localStorageQuotaSessionOnly.html (4197B)
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 11 var currentTest = 1; 12 13 function doNextTest() 14 { 15 slave = frame; 16 17 switch (currentTest) 18 { 19 case 1: 20 slaveOrigin = "http://example.com"; 21 slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add&A&success"; 22 break; 23 24 // In subdomain now set another key with length 500 bytes, i.e. 25 // allocate 501 bytes 26 case 2: 27 slaveOrigin = "http://test1.example.com"; 28 slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add&B&success"; 29 break; 30 31 // Try to set the same key value again to check we don't fail 32 // even 1002 bytes has already been exhausted from the quota 33 // We just change the value of an existing key. 34 case 3: 35 slaveOrigin = "http://test1.example.com"; 36 slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add&B&success"; 37 break; 38 39 // Try to set the same key to a larger value that would lead to 40 // quota reach and check that the value is still the old one 41 case 4: 42 slaveOrigin = "http://test1.example.com"; 43 slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add2&B&failure"; 44 break; 45 46 // In a different subdomain try to set a new 500 bytes key 47 // and check we fail because we are over the quota 48 case 5: 49 slaveOrigin = "https://test2.example.com"; 50 slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add&C&failure"; 51 break; 52 53 // Remove from the second subdomain the second key, it must not fail 54 // This should release the allocated space of the quota assigned to 55 // example.com. 56 case 6: 57 slaveOrigin = "http://test1.example.com"; 58 slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?remove&B&success"; 59 break; 60 61 // Now try again to set 500 bytes key, it must succeed. 62 case 7: 63 slaveOrigin = "https://test2.example.com"; 64 slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add&C&success"; 65 break; 66 67 case 8: 68 // Do a clean up... 69 slaveOrigin = "http://example.com"; 70 slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?clear"; 71 break; 72 73 case 9: 74 // Do a clean up... 75 slaveOrigin = "http://test1.example.com"; 76 slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?clear"; 77 break; 78 79 case 10: 80 // Do a clean up... 81 slaveOrigin = "https://test2.example.com"; 82 slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?clear"; 83 break; 84 85 default: 86 SimpleTest.finish(); 87 } 88 89 ++currentTest; 90 } 91 92 function doStep() 93 { 94 } 95 96 SimpleTest.waitForExplicitFinish(); 97 98 function startTest() { 99 if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) { 100 ok(true, "Test ignored when the next gen local storage is enabled."); 101 SimpleTest.finish(); 102 return; 103 } 104 105 SpecialPowers.pushPermissions([ 106 { 107 type: "cookie", 108 allow: SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION, 109 context: "http://example.com", 110 }, 111 { 112 type: "cookie", 113 allow: SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION, 114 context: "http://test1.example.com", 115 }, 116 { 117 type: "cookie", 118 allow: SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION, 119 context: "https://test2.example.com", 120 }, 121 ], function() { 122 // Initialy setup the quota to testing value of 1024B and 123 // set a 500 bytes key with name length 1 (allocate 501 bytes) 124 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); 125 }); 126 } 127 </script> 128 129 </head> 130 131 <body onload="startTest();"> 132 <iframe src="" name="frame"></iframe> 133 </body> 134 </html>