b2g/components/test/mochitest/test_sandbox_permission.html

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial