dom/tests/mochitest/localstorage/frameQuotaSessionOnly.html

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:47f3f97b4da4
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 case "":
84 default:
85 switch (operation)
86 {
87 case "clear":
88 localStorage.clear();
89 break;
90 }
91
92 break;
93 }
94
95 // Just inform the master we are finished now
96 postMsg("done");
97 return false;
98 }
99
100 function startTest() {
101 SpecialPowers.pushPermissions([{'type': 'cookie', 'allow': SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION, 'context': document}], function() {
102 postMsg('frame loaded');
103 });
104 }
105 </script>
106
107 </head>
108
109 <body onload="startTest();">
110 </body>
111 </html>

mercurial