|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=758258 |
|
5 --> |
|
6 <head> |
|
7 <meta charset="utf-8"> |
|
8 <title>Test for nsIPrincipal extendedOrigin, appStatus and appId</title> |
|
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> |
|
11 </head> |
|
12 <body> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=758258">Mozilla Bug 758258</a> |
|
14 <p id="display"></p> |
|
15 <div id="content"> |
|
16 |
|
17 </div> |
|
18 <pre id="test"> |
|
19 <script type="application/javascript;version=1.7"> |
|
20 |
|
21 /** Test for Bug 758258 **/ |
|
22 |
|
23 var Ci = Components.interfaces; |
|
24 var Cc = Components.classes; |
|
25 |
|
26 SimpleTest.waitForExplicitFinish(); |
|
27 |
|
28 var permManager = Cc["@mozilla.org/permissionmanager;1"] |
|
29 .getService(Ci.nsIPermissionManager); |
|
30 |
|
31 const gPermName = 'foobar'; |
|
32 |
|
33 var previousPrefs = { |
|
34 mozBrowserFramesEnabled: undefined, |
|
35 }; |
|
36 |
|
37 try { |
|
38 previousPrefs.mozBrowserFramesEnabled = SpecialPowers.getBoolPref('dom.mozBrowserFramesEnabled'); |
|
39 } catch(e) |
|
40 { |
|
41 } |
|
42 |
|
43 SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true); |
|
44 |
|
45 // We use http://test/ as url so all apps use the same url and app isolation is |
|
46 // more obvious. |
|
47 var gData = [ |
|
48 // APP 1 |
|
49 { |
|
50 app: 'http://example.org/manifest.webapp', |
|
51 action: 'read-no', |
|
52 src: 'http://test/', |
|
53 }, |
|
54 { |
|
55 app: 'http://example.org/manifest.webapp', |
|
56 action: 'write', |
|
57 src: 'http://test/', |
|
58 }, |
|
59 { |
|
60 app: 'http://example.org/manifest.webapp', |
|
61 action: 'read-yes', |
|
62 src: 'http://test/', |
|
63 }, |
|
64 // APP 2 |
|
65 { |
|
66 app: 'https://example.com/manifest.webapp', |
|
67 action: 'read-no', |
|
68 src: 'http://test/', |
|
69 }, |
|
70 { |
|
71 app: 'https://example.com/manifest.webapp', |
|
72 action: 'write', |
|
73 src: 'http://test/', |
|
74 }, |
|
75 { |
|
76 app: 'https://example.com/manifest.webapp', |
|
77 action: 'read-yes', |
|
78 src: 'http://test/', |
|
79 }, |
|
80 // Browser |
|
81 { |
|
82 browser: true, |
|
83 action: 'read-no', |
|
84 src: 'http://test/', |
|
85 }, |
|
86 { |
|
87 browser: true, |
|
88 action: 'write', |
|
89 src: 'http://test/', |
|
90 }, |
|
91 { |
|
92 browser: true, |
|
93 action: 'read-yes', |
|
94 src: 'http://test/', |
|
95 }, |
|
96 ]; |
|
97 |
|
98 function runTest() { |
|
99 for (var i in gData) { |
|
100 var iframe = document.createElement('iframe'); |
|
101 var data = gData[i]; |
|
102 |
|
103 if (data.app) { |
|
104 iframe.setAttribute('mozbrowser', ''); |
|
105 iframe.setAttribute('mozapp', data.app); |
|
106 } else if (data.browser) { |
|
107 iframe.setAttribute('mozbrowser', ''); |
|
108 } |
|
109 |
|
110 if (data.app || data.browser) { |
|
111 iframe.addEventListener('load', function(e) { |
|
112 var principal = iframe.contentDocument.nodePrincipal; |
|
113 |
|
114 switch (data.action) { |
|
115 case 'read-no': |
|
116 is(permManager.testPermissionFromPrincipal(principal, gPermName), |
|
117 Ci.nsIPermissionManager.UNKNOWN_ACTION, |
|
118 "Permission should not be set yet"); |
|
119 is(permManager.testExactPermissionFromPrincipal(principal, gPermName), |
|
120 Ci.nsIPermissionManager.UNKNOWN_ACTION, |
|
121 "Permission should not be set yet"); |
|
122 break; |
|
123 case 'write': |
|
124 permManager.addFromPrincipal(principal, gPermName, Ci.nsIPermissionManager.ALLOW_ACTION); |
|
125 break; |
|
126 case 'read-yes': |
|
127 is(permManager.testPermissionFromPrincipal(principal, gPermName), |
|
128 Ci.nsIPermissionManager.ALLOW_ACTION, |
|
129 "Permission should be set"); |
|
130 is(permManager.testExactPermissionFromPrincipal(principal, gPermName), |
|
131 Ci.nsIPermissionManager.ALLOW_ACTION, |
|
132 "Permission should be set"); |
|
133 break; |
|
134 default: |
|
135 ok(false, "shouldn't be there"); |
|
136 } |
|
137 |
|
138 // Calling removeChild() produces an error that creates failures. |
|
139 //document.getElementById('content').removeChild(iframe); |
|
140 |
|
141 i++; |
|
142 if (i >= gData.length) { |
|
143 if (previousPrefs.mozBrowserFramesEnabled !== undefined) { |
|
144 SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', previousPrefs.mozBrowserFramesEnabled); |
|
145 } |
|
146 |
|
147 SimpleTest.finish(); |
|
148 } else { |
|
149 gTestRunner.next(); |
|
150 } |
|
151 }); |
|
152 } |
|
153 |
|
154 iframe.src = data.src; |
|
155 |
|
156 document.getElementById('content').appendChild(iframe); |
|
157 |
|
158 yield; |
|
159 } |
|
160 } |
|
161 |
|
162 var gTestRunner = runTest(); |
|
163 gTestRunner.next(); |
|
164 |
|
165 </script> |
|
166 </pre> |
|
167 </body> |
|
168 </html> |