2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
10 <title>Test for Permissions API
</title>
11 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
12 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
17 <script type=
"application/javascript">
18 /*globals SpecialPowers, SimpleTest, is, ok, */
21 function setPermission(type, allow) {
22 return new Promise(resolve =
> {
23 SpecialPowers.popPermissions(() =
> {
24 SpecialPowers.pushPermissions(
25 [{ type, allow, context: document }],
32 function checkPermission(aIFrame, aExpectedState, aName) {
33 return SpecialPowers.spawn(
35 [{name: aName, expectedState: aExpectedState}],
38 let result = await content.navigator
40 .query({ name: aInput.name });
42 SpecialPowers.wrap(result).state,
44 `correct state for '${aInput.name}'`
47 ok(false, `query should not have rejected for '${aInput.name}'`)
53 function createIframe(aId, aAllow) {
54 return new Promise((resolve) =
> {
55 const iframe = document.createElement('iframe');
57 iframe.src = 'https://example.org/tests/dom/permission/tests/file_empty.html';
59 iframe.allow = aAllow;
61 iframe.onload = () =
> resolve(iframe);
62 document.body.appendChild(iframe);
66 function removeIframe(aId) {
67 return new Promise((resolve) =
> {
68 document.body.removeChild(document.getElementById(aId));
78 } = SpecialPowers.Ci.nsIPermissionManager;
82 id: 'query navigation top unknown',
89 id: 'query notifications top unknown',
91 name: 'notifications',
92 type: 'desktop-notification',
96 id: 'query push top unknown',
99 type: 'desktop-notification',
103 id: 'query persistent-storage unknown',
105 name: 'persistent-storage',
106 type: 'persistent-storage',
110 id: 'query storage-access unknown',
112 name: 'storage-access',
113 type: '
3rdPartyFrameStorage^https://example.org',
117 id: 'query camera top unknown',
124 id: 'query microphone top unknown',
131 id: 'query navigation top prompt',
138 id: 'query notifications top prompt',
140 name: 'notifications',
141 type: 'desktop-notification',
145 id: 'query push top prompt',
148 type: 'desktop-notification',
152 id: 'query persistent-storage top prompt',
154 name: 'persistent-storage',
155 type: 'persistent-storage',
159 id: 'query storage-access top prompt',
161 name: 'storage-access',
162 type: '
3rdPartyFrameStorage^https://example.org',
166 id: 'query camera top prompt',
173 id: 'query microphone top prompt',
180 id: 'query navigation top denied',
187 id: 'query notifications top denied',
189 name: 'notifications',
190 type: 'desktop-notification',
194 id: 'query push top denied',
197 type: 'desktop-notification',
201 id: 'query persistent-storage top denied',
203 name: 'persistent-storage',
204 type: 'persistent-storage',
208 id: 'query storage-access top denied',
210 name: 'storage-access',
211 type: '
3rdPartyFrameStorage^https://example.org',
215 id: 'query camera top denied',
222 id: 'query micrphone top denied',
229 id: 'query navigation top granted',
236 id: 'query notifications top granted',
238 name: 'notifications',
239 type: 'desktop-notification',
243 id: 'query push top granted',
246 type: 'desktop-notification',
250 id: 'query persistent-storage top granted',
252 name: 'persistent-storage',
253 type: 'persistent-storage',
257 id: 'query storage-access top granted',
259 name: 'storage-access',
260 type: '
3rdPartyFrameStorage^https://example.org',
264 id: 'query camera top granted',
271 id: 'query microphone top granted',
278 id: 'query navigation top denied, iframe has allow attribute',
280 allow: 'geolocation',
286 id: 'query navigation top granted, iframe has allow attribute',
288 allow: 'geolocation',
294 id: 'query navigation top prompt, iframe has allow attribute',
296 allow: 'geolocation',
302 id: 'query navigation top unknown, iframe has allow attribute',
304 allow: 'geolocation',
310 id: 'query storage-access top denied, iframe has allow none attribute',
312 allow:
"storage-access 'none'",
313 name: 'storage-access',
314 type: '
3rdPartyFrameStorage^https://example.org',
318 id: 'query storage-access top granted, iframe has allow none attribute',
320 allow:
"storage-access 'none'",
321 name: 'storage-access',
322 type: '
3rdPartyFrameStorage^https://example.org',
326 id: 'query storage-access top prompt, iframe has allow none attribute',
328 allow:
"storage-access 'none'",
329 name: 'storage-access',
330 type: '
3rdPartyFrameStorage^https://example.org',
334 id: 'query storage-access top unknown, iframe has allow none attribute',
336 allow:
"storage-access 'none'",
337 name: 'storage-access',
338 type: '
3rdPartyFrameStorage^https://example.org',
342 id: 'query camera top denied, iframe has allow attribute',
350 id: 'query camera top granted, iframe has allow attribute',
358 id: 'query camera top prompt, iframe has allow attribute',
363 expected: 'granted', //
"Always Ask" mitigation (bug
1609427)
366 id: 'query camera top unknown, iframe has allow attribute',
374 id: 'query microphone top denied, iframe has allow attribute',
382 id: 'query microphone top granted, iframe has allow attribute',
390 id: 'query microphone top prompt, iframe has allow attribute',
395 expected: 'granted', //
"Always Ask" mitigation (bug
1609427)
398 id: 'query microphone top unknown, iframe has allow attribute',
407 SimpleTest.waitForExplicitFinish();
409 async function nextTest() {
415 let test = tests.shift();
416 await setPermission(test.type, test.top)
417 .then(() =
> createIframe(test.id, test.allow))
418 .then(iframe =
> checkPermission(iframe, test.expected, test.name))
419 .then(() =
> removeIframe(test.id));
421 SimpleTest.executeSoon(nextTest);