|
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_REACHED = 2152924150; |
|
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 case "checkclean": |
|
49 is(localStorage.getItem(keyName), null, "Key "+keyName+" not present"); |
|
50 break; |
|
51 |
|
52 case "checknotclean": |
|
53 is(localStorage.getItem(keyName), "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "Key "+keyName+" is present"); |
|
54 break; |
|
55 } |
|
56 |
|
57 break; |
|
58 |
|
59 case "failure": |
|
60 switch (operation) |
|
61 { |
|
62 case "add": |
|
63 // Attempt to store 500 bytes long string that doens't |
|
64 // fit the quota, have to throw DOM_QUOTA_REACHED exception |
|
65 checkException(function() { |
|
66 localStorage.setItem(keyName, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); |
|
67 }, DOM_QUOTA_REACHED); |
|
68 is(localStorage.getItem(keyName), null, "500 bytes key "+keyName+" is NOT stored"); |
|
69 break; |
|
70 |
|
71 case "add2": |
|
72 // Attempt to change a key value to reach the DOM quota and |
|
73 // check it fails and the old key value is still present. |
|
74 checkException(function() { |
|
75 localStorage.setItem(keyName, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); |
|
76 }, DOM_QUOTA_REACHED); |
|
77 is(localStorage.getItem(keyName), "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "Key "+keyName+" left unchanged"); |
|
78 break; |
|
79 } |
|
80 |
|
81 break; |
|
82 |
|
83 default: |
|
84 switch (operation) |
|
85 { |
|
86 case "clear": |
|
87 localStorage.clear(); |
|
88 break; |
|
89 } |
|
90 |
|
91 break; |
|
92 } |
|
93 |
|
94 // Just inform the master we are finished now |
|
95 postMsg("done"); |
|
96 return false; |
|
97 } |
|
98 |
|
99 </script> |
|
100 |
|
101 </head> |
|
102 |
|
103 <body onload="postMsg('frame loaded');"> |
|
104 </body> |
|
105 </html> |