1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/localstorage/test_localStorageQuotaSessionOnly.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,112 @@ 1.4 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.5 +<head> 1.6 +<title>localStorage and DOM quota test</title> 1.7 + 1.8 +<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 +<script type="text/javascript" src="interOriginTest.js"></script> 1.10 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.11 + 1.12 +<script type="text/javascript"> 1.13 + 1.14 +var currentTest = 1; 1.15 + 1.16 +function doNextTest() 1.17 +{ 1.18 + slave = frame; 1.19 + 1.20 + switch (currentTest) 1.21 + { 1.22 + case 1: 1.23 + slaveOrigin = "http://example.com"; 1.24 + slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add&A&success"; 1.25 + break; 1.26 + 1.27 + // In subdomain now set another key with length 500 bytes, i.e. 1.28 + // allocate 501 bytes 1.29 + case 2: 1.30 + slaveOrigin = "http://test1.example.com"; 1.31 + slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add&B&success"; 1.32 + break; 1.33 + 1.34 + // Try to set the same key value again to check we don't fail 1.35 + // even 1002 bytes has already been exhausted from the quota 1.36 + // We just change the value of an existing key. 1.37 + case 3: 1.38 + slaveOrigin = "http://test1.example.com"; 1.39 + slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add&B&success"; 1.40 + break; 1.41 + 1.42 + // Try to set the same key to a larger value that would lead to 1.43 + // quota reach and check that the value is still the old one 1.44 + case 4: 1.45 + slaveOrigin = "http://test1.example.com"; 1.46 + slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add2&B&failure"; 1.47 + break; 1.48 + 1.49 + // In a different subdomain try to set a new 500 bytes key 1.50 + // and check we fail because we are over the quota 1.51 + case 5: 1.52 + slaveOrigin = "https://test2.example.com"; 1.53 + slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add&C&failure"; 1.54 + break; 1.55 + 1.56 + // Remove from the second subdomain the second key, it must not fail 1.57 + // This should release the allocated space of the quota assigned to 1.58 + // example.com. 1.59 + case 6: 1.60 + slaveOrigin = "http://test1.example.com"; 1.61 + slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?remove&B&success"; 1.62 + break; 1.63 + 1.64 + // Now try again to set 500 bytes key, it must succeed. 1.65 + case 7: 1.66 + slaveOrigin = "https://test2.example.com"; 1.67 + slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add&C&success"; 1.68 + break; 1.69 + 1.70 + case 8: 1.71 + // Do a clean up... 1.72 + slaveOrigin = "http://example.com"; 1.73 + slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?clear"; 1.74 + break; 1.75 + 1.76 + case 9: 1.77 + // Do a clean up... 1.78 + slaveOrigin = "http://test1.example.com"; 1.79 + slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?clear"; 1.80 + break; 1.81 + 1.82 + case 10: 1.83 + // Do a clean up... 1.84 + slaveOrigin = "https://test2.example.com"; 1.85 + slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?clear"; 1.86 + break; 1.87 + 1.88 + default: 1.89 + SimpleTest.finish(); 1.90 + } 1.91 + 1.92 + ++currentTest; 1.93 +} 1.94 + 1.95 +function doStep() 1.96 +{ 1.97 +} 1.98 + 1.99 +SimpleTest.waitForExplicitFinish(); 1.100 + 1.101 +function startTest() { 1.102 + SpecialPowers.pushPermissions([{'type': 'cookie', 'allow': SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION, 'context': document}], function() { 1.103 + // Initialy setup the quota to testing value of 1024B and 1.104 + // set a 500 bytes key with name length 1 (allocate 501 bytes) 1.105 + SpecialPowers.pushPrefEnv({"set": [["dom.storage.default_quota", 1], ["security.mixed_content.block_display_content", false], ["security.mixed_content.block_active_content", false]]}, doNextTest); 1.106 + }); 1.107 +} 1.108 +</script> 1.109 + 1.110 +</head> 1.111 + 1.112 +<body onload="startTest();"> 1.113 + <iframe src="" name="frame"></iframe> 1.114 +</body> 1.115 +</html>