|
1 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
2 <head> |
|
3 <title>localStorage app isolation</title> |
|
4 |
|
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
7 |
|
8 <script type="application/javascript;version=1.7"> |
|
9 |
|
10 SimpleTest.waitForExplicitFinish(); |
|
11 |
|
12 var fileTestOnCurrentOrigin = (location.protocol + "//" + location.host + location.pathname) |
|
13 .replace("test_a", "frameA"); |
|
14 |
|
15 var previousPrefs = { |
|
16 mozBrowserFramesEnabled: undefined, |
|
17 }; |
|
18 |
|
19 try { |
|
20 previousPrefs.mozBrowserFramesEnabled = SpecialPowers.getBoolPref('dom.mozBrowserFramesEnabled'); |
|
21 } catch(e) |
|
22 { |
|
23 } |
|
24 |
|
25 SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true); |
|
26 |
|
27 SpecialPowers.addPermission("browser", true, window.document); |
|
28 SpecialPowers.addPermission("embed-apps", true, window.document); |
|
29 |
|
30 var gData = [ |
|
31 // APP 1 |
|
32 { |
|
33 app: 'http://example.org/manifest.webapp', |
|
34 action: 'read-no', |
|
35 }, |
|
36 { |
|
37 app: 'http://example.org/manifest.webapp', |
|
38 action: 'write', |
|
39 }, |
|
40 { |
|
41 app: 'http://example.org/manifest.webapp', |
|
42 action: 'read-yes', |
|
43 }, |
|
44 // APP 2 |
|
45 { |
|
46 app: 'https://example.com/manifest.webapp', |
|
47 action: 'read-no', |
|
48 }, |
|
49 { |
|
50 app: 'https://example.com/manifest.webapp', |
|
51 action: 'write', |
|
52 }, |
|
53 { |
|
54 app: 'https://example.com/manifest.webapp', |
|
55 action: 'read-yes', |
|
56 }, |
|
57 // Browser |
|
58 { |
|
59 browser: true, |
|
60 action: 'read-no', |
|
61 }, |
|
62 { |
|
63 browser: true, |
|
64 action: 'write', |
|
65 }, |
|
66 { |
|
67 browser: true, |
|
68 action: 'read-yes', |
|
69 }, |
|
70 // Clear APP 1 |
|
71 { |
|
72 app: 'http://example.org/manifest.webapp', |
|
73 action: 'clear', |
|
74 }, |
|
75 // Clear APP 2 |
|
76 { |
|
77 app: 'https://example.com/manifest.webapp', |
|
78 action: 'clear', |
|
79 }, |
|
80 // Clear Browser |
|
81 { |
|
82 browser: true, |
|
83 action: 'clear', |
|
84 }, |
|
85 ]; |
|
86 |
|
87 function runTest() |
|
88 { |
|
89 for (var i in gData) { |
|
90 var iframe = document.createElement('iframe'); |
|
91 var data = gData[i]; |
|
92 |
|
93 if (data.app) { |
|
94 iframe.setAttribute('mozbrowser', ''); |
|
95 iframe.setAttribute('mozapp', data.app); |
|
96 } else if (data.browser) { |
|
97 iframe.setAttribute('mozbrowser', ''); |
|
98 } |
|
99 |
|
100 if (data.app || data.browser) { |
|
101 iframe.addEventListener('mozbrowsershowmodalprompt', function(e) { |
|
102 is(e.detail.message, "success", "test number " + i); |
|
103 |
|
104 document.body.removeChild(iframe); |
|
105 |
|
106 i++; |
|
107 if (i >= gData.length) { |
|
108 localStorage.clear(); |
|
109 |
|
110 SpecialPowers.removePermission("browser", window.document); |
|
111 SpecialPowers.removePermission("embed-apps", window.document); |
|
112 |
|
113 if (previousPrefs.mozBrowserFramesEnabled !== undefined) { |
|
114 SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', previousPrefs.mozBrowserFramesEnabled); |
|
115 } |
|
116 |
|
117 SimpleTest.finish(); |
|
118 } else { |
|
119 gTestRunner.next(); |
|
120 } |
|
121 }); |
|
122 } |
|
123 |
|
124 iframe.src = fileTestOnCurrentOrigin + "?" + data.action; |
|
125 |
|
126 document.body.appendChild(iframe); |
|
127 |
|
128 yield undefined; |
|
129 } |
|
130 } |
|
131 |
|
132 var gTestRunner = runTest(); |
|
133 |
|
134 function startTest() |
|
135 { |
|
136 is(localStorage.getItem("0"), null, "no data"); |
|
137 localStorage.setItem("0", "foo"); |
|
138 is(localStorage.getItem("0"), "foo", "data have been written"); |
|
139 |
|
140 gTestRunner.next(); |
|
141 } |
|
142 |
|
143 addLoadEvent(startTest); |
|
144 |
|
145 </script> |
|
146 |
|
147 </head> |
|
148 |
|
149 <body> |
|
150 </body> |
|
151 </html> |