frameQuota.html (4924B)
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <title>slave for sessionStorage test</title> 4 5 <script type="text/javascript" src="interOriginFrame.js"></script> 6 <script type="text/javascript"> 7 8 const DOM_QUOTA_EXCEEDED_ERR = 0x80530016; 9 10 function checkException(func, exc) 11 { 12 var exceptionThrew = false; 13 try { 14 func(); 15 } 16 catch (ex) { 17 exceptionThrew = true; 18 is(ex.result, exc, "Expected "+exc+" exception"); 19 } 20 ok(exceptionThrew, "Exception "+exc+" threw at "+location); 21 } 22 23 function doStep() 24 { 25 var query = location.search.substring(1); 26 var queries = query.split("&"); 27 28 var operation = queries[0]; 29 var keyName = queries[1]; 30 var result = queries[2]; 31 32 switch (result) 33 { 34 case "success": 35 switch (operation) 36 { 37 case "add": 38 // Store 500 bytes long string must succeed 39 localStorage.setItem(keyName, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); 40 is(localStorage.getItem(keyName), "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "500 bytes key "+keyName+" stored"); 41 break; 42 43 case "remove": 44 localStorage.removeItem(keyName); 45 is(localStorage.getItem(keyName), null, "Key "+keyName+" removed"); 46 break; 47 } 48 49 break; 50 51 case "failure": 52 switch (operation) 53 { 54 case "add": 55 // Attempt to store 500 bytes long string that doens't 56 // fit the quota, have to throw DOM_QUOTA_EXCEEDED_ERR exception 57 checkException(function() { 58 localStorage.setItem(keyName, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); 59 }, DOM_QUOTA_EXCEEDED_ERR); 60 is(localStorage.getItem(keyName), null, "500 bytes key "+keyName+" is NOT stored"); 61 break; 62 63 case "add2": 64 // Attempt to change a key value to reach the DOM quota and 65 // check it fails and the old key value is still present. 66 checkException(function() { 67 localStorage.setItem(keyName, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); 68 }, DOM_QUOTA_EXCEEDED_ERR); 69 is(localStorage.getItem(keyName), "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "Key "+keyName+" left unchanged"); 70 break; 71 } 72 73 break; 74 75 default: 76 switch (operation) 77 { 78 case "clear": 79 localStorage.clear(); 80 break; 81 } 82 83 break; 84 } 85 86 // Just inform the master we are finished now 87 postMsg("done"); 88 return false; 89 } 90 91 </script> 92 93 </head> 94 95 <body onload="postMsg('frame loaded');"> 96 </body> 97 </html>