1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/localstorage/frameQuotaSessionOnly.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,111 @@ 1.4 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.5 +<head> 1.6 +<title>slave for sessionStorage test</title> 1.7 + 1.8 +<script type="text/javascript" src="interOriginFrame.js"></script> 1.9 +<script type="text/javascript"> 1.10 + 1.11 +const DOM_QUOTA_REACHED = 2152924150; 1.12 + 1.13 +function checkException(func, exc) 1.14 +{ 1.15 + var exceptionThrew = false; 1.16 + try { 1.17 + func(); 1.18 + } 1.19 + catch (ex) { 1.20 + exceptionThrew = true; 1.21 + is(ex.result, exc, "Expected "+exc+" exception"); 1.22 + } 1.23 + ok(exceptionThrew, "Exception "+exc+" threw at "+location); 1.24 +} 1.25 + 1.26 +function doStep() 1.27 +{ 1.28 + var query = location.search.substring(1); 1.29 + var queries = query.split("&"); 1.30 + 1.31 + var operation = queries[0]; 1.32 + var keyName = queries[1]; 1.33 + var result = queries[2]; 1.34 + 1.35 + switch (result) 1.36 + { 1.37 + case "success": 1.38 + switch (operation) 1.39 + { 1.40 + case "add": 1.41 + // Store 500 bytes long string must succeed 1.42 + localStorage.setItem(keyName, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); 1.43 + is(localStorage.getItem(keyName), "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "500 bytes key "+keyName+" stored"); 1.44 + break; 1.45 + 1.46 + case "remove": 1.47 + localStorage.removeItem(keyName); 1.48 + is(localStorage.getItem(keyName), null, "Key "+keyName+" removed"); 1.49 + break; 1.50 + 1.51 + case "checkclean": 1.52 + is(localStorage.getItem(keyName), null, "Key "+keyName+" not present"); 1.53 + break; 1.54 + 1.55 + case "checknotclean": 1.56 + is(localStorage.getItem(keyName), "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "Key "+keyName+" is present"); 1.57 + break; 1.58 + } 1.59 + 1.60 + break; 1.61 + 1.62 + case "failure": 1.63 + switch (operation) 1.64 + { 1.65 + case "add": 1.66 + // Attempt to store 500 bytes long string that doens't 1.67 + // fit the quota, have to throw DOM_QUOTA_REACHED exception 1.68 + checkException(function() { 1.69 + localStorage.setItem(keyName, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); 1.70 + }, DOM_QUOTA_REACHED); 1.71 + is(localStorage.getItem(keyName), null, "500 bytes key "+keyName+" is NOT stored"); 1.72 + break; 1.73 + 1.74 + case "add2": 1.75 + // Attempt to change a key value to reach the DOM quota and 1.76 + // check it fails and the old key value is still present. 1.77 + checkException(function() { 1.78 + localStorage.setItem(keyName, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); 1.79 + }, DOM_QUOTA_REACHED); 1.80 + is(localStorage.getItem(keyName), "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "Key "+keyName+" left unchanged"); 1.81 + break; 1.82 + } 1.83 + 1.84 + break; 1.85 + 1.86 + case "": 1.87 + default: 1.88 + switch (operation) 1.89 + { 1.90 + case "clear": 1.91 + localStorage.clear(); 1.92 + break; 1.93 + } 1.94 + 1.95 + break; 1.96 + } 1.97 + 1.98 + // Just inform the master we are finished now 1.99 + postMsg("done"); 1.100 + return false; 1.101 +} 1.102 + 1.103 +function startTest() { 1.104 + SpecialPowers.pushPermissions([{'type': 'cookie', 'allow': SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION, 'context': document}], function() { 1.105 + postMsg('frame loaded'); 1.106 + }); 1.107 +} 1.108 +</script> 1.109 + 1.110 +</head> 1.111 + 1.112 +<body onload="startTest();"> 1.113 +</body> 1.114 +</html>