[email protected] | de48685 | 2011-05-28 03:27:16 | [diff] [blame] | 1 | <html> |
2 | <head> | ||||
[email protected] | de48685 | 2011-05-28 03:27:16 | [diff] [blame] | 3 | <script> |
4 | |||||
[email protected] | 62b3df0 | 2012-08-04 07:22:13 | [diff] [blame] | 5 | if (window.testRunner) |
6 | testRunner.dumpAsText(); | ||||
[email protected] | de48685 | 2011-05-28 03:27:16 | [diff] [blame] | 7 | |
8 | function log(a) | ||||
9 | { | ||||
10 | document.getElementById("logger").innerHTML += a + "<br>"; | ||||
11 | } | ||||
12 | |||||
[email protected] | 4dac06d | 2012-10-23 07:24:08 | [diff] [blame] | 13 | function openIframe() |
14 | { | ||||
15 | if (document.createElement && (iframe = document.createElement('iframe'))) { | ||||
16 | document.body.appendChild(iframe); | ||||
17 | return iframe; | ||||
18 | } | ||||
19 | } | ||||
20 | |||||
[email protected] | de48685 | 2011-05-28 03:27:16 | [diff] [blame] | 21 | function runTest() |
22 | { | ||||
23 | if (!window.localStorage) { | ||||
24 | log("window.localStorage DOES NOT exist"); | ||||
25 | return; | ||||
26 | } | ||||
27 | |||||
[email protected] | c48583236 | 2012-01-04 01:10:54 | [diff] [blame] | 28 | localStorage.clear(); |
29 | |||||
[email protected] | 62b3df0 | 2012-08-04 07:22:13 | [diff] [blame] | 30 | if (window.testRunner && testRunner.setStorageAllowed) |
31 | testRunner.setStorageAllowed(true); | ||||
[email protected] | de48685 | 2011-05-28 03:27:16 | [diff] [blame] | 32 | else |
[email protected] | 62b3df0 | 2012-08-04 07:22:13 | [diff] [blame] | 33 | log("This test requires testRunner.setStorageAllowed, so it be can't run in a browser."); |
[email protected] | de48685 | 2011-05-28 03:27:16 | [diff] [blame] | 34 | |
35 | log("Length is " + localStorage.length); | ||||
36 | log("Value for FOO is " + localStorage.getItem("FOO")); | ||||
37 | |||||
38 | localStorage.setItem("FOO", "BAR"); | ||||
39 | |||||
40 | log("Length is " + localStorage.length); | ||||
41 | log("Value for FOO is " + localStorage.getItem("FOO")); | ||||
42 | log("Key for index 0 is " + localStorage.key(0)); | ||||
43 | |||||
44 | log("Disabling localStorage access."); | ||||
[email protected] | 62b3df0 | 2012-08-04 07:22:13 | [diff] [blame] | 45 | if (window.testRunner && testRunner.setStorageAllowed) |
46 | testRunner.setStorageAllowed(false); | ||||
[email protected] | de48685 | 2011-05-28 03:27:16 | [diff] [blame] | 47 | |
[email protected] | de48685 | 2011-05-28 03:27:16 | [diff] [blame] | 48 | try { |
[email protected] | 4dac06d | 2012-10-23 07:24:08 | [diff] [blame] | 49 | log("frame localStorage is accessible " + !!openIframe().contentDocument.defaultView.localStorage); |
[email protected] | de48685 | 2011-05-28 03:27:16 | [diff] [blame] | 50 | } catch(e) { |
[email protected] | 4dac06d | 2012-10-23 07:24:08 | [diff] [blame] | 51 | log("Caught exception trying to get frame localStorage: " + e); |
[email protected] | de48685 | 2011-05-28 03:27:16 | [diff] [blame] | 52 | } |
[email protected] | de48685 | 2011-05-28 03:27:16 | [diff] [blame] | 53 | } |
54 | |||||
55 | </script> | ||||
56 | </head> | ||||
57 | <body onload="runTest();"> | ||||
58 | This test verifies that all access to localStorage can be blocked<br> | ||||
59 | <div id="logger"></div> | ||||
60 | </body> | ||||
61 | </html> |