Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=951997
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Permission Prompt Test</title>
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
10 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=951997">Permission prompt web content test</a>
14 <script type="application/javascript;version=1.8">
16 "use strict";
18 const APP_URL = "SandboxPromptTest.html";
20 var iframe;
21 var gUrl = SimpleTest.getTestFileURL("permission_handler_chrome.js");
22 var gScript = SpecialPowers.loadChromeScript(gUrl);
23 var gResult = [
24 {
25 "video-capture": ["back"],
26 },
27 {
28 "audio-capture": [""],
29 "video-capture": ["back"],
30 },
31 {
32 "audio-capture": [""],
33 },
34 {
35 "geolocation": [],
36 },
37 {
38 "desktop-notification": [],
39 }
40 ];
42 function runNext() {
43 if (gResult.length > 0) {
44 // Put the requested permission in query string
45 let requestedPermission = JSON.stringify(Object.keys(gResult[0]));
46 info('request permissions for ' + requestedPermission);
47 iframe.src = APP_URL + '?' + encodeURIComponent(requestedPermission);
48 } else {
49 info('test finished, teardown');
50 gScript.sendAsyncMessage("teardown", "");
51 gScript.destroy();
52 SimpleTest.finish();
53 }
54 }
56 // Create a sanbox iframe.
57 function loadBrowser() {
58 iframe = document.createElement("iframe");
59 SpecialPowers.wrap(iframe).mozbrowser = true;
60 iframe.src = 'about:blank';
61 document.body.appendChild(iframe);
63 iframe.addEventListener("load", function onLoad() {
64 iframe.removeEventListener("load", onLoad);
65 runNext();
66 });
67 }
69 gScript.addMessageListener("permission-request", function (detail) {
70 let permissions = detail.permissions;
71 let expectedValue = gResult.shift();
72 let permissionTypes = Object.keys(permissions);
74 is(permissionTypes.length, Object.keys(expectedValue).length, "expected number of permissions");
76 for (let type of permissionTypes) {
77 ok(expectedValue.hasOwnProperty(type), "expected permission type");
78 for (let i in permissions[type]) {
79 is(permissions[type][i], expectedValue[type][i], "expected permission option");
80 }
81 }
82 runNext();
83 });
85 // Add permissions to this app. We use ALLOW_ACTION here. The ContentPermissionPrompt
86 // should prompt for permission, not allow it without prompt.
87 SpecialPowers.pushPrefEnv({"set": [["media.navigator.permission.disabled", false]]},
88 function() {
89 SpecialPowers.addPermission('video-capture',
90 SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION, document);
91 SpecialPowers.addPermission('audio-capture',
92 SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION, document);
93 SpecialPowers.addPermission('geolocation',
94 SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION, document);
95 SpecialPowers.addPermission('desktop-notification',
96 SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION, document);
97 loadBrowser();
98 });
100 SimpleTest.waitForExplicitFinish();
101 </script>
102 </pre>
103 </body>
104 </html>