1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/b2g/components/test/mochitest/test_sandbox_permission.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,104 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=951997 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Permission Prompt Test</title> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.13 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=951997">Permission prompt web content test</a> 1.17 +<script type="application/javascript;version=1.8"> 1.18 + 1.19 +"use strict"; 1.20 + 1.21 +const APP_URL = "SandboxPromptTest.html"; 1.22 + 1.23 +var iframe; 1.24 +var gUrl = SimpleTest.getTestFileURL("permission_handler_chrome.js"); 1.25 +var gScript = SpecialPowers.loadChromeScript(gUrl); 1.26 +var gResult = [ 1.27 + { 1.28 + "video-capture": ["back"], 1.29 + }, 1.30 + { 1.31 + "audio-capture": [""], 1.32 + "video-capture": ["back"], 1.33 + }, 1.34 + { 1.35 + "audio-capture": [""], 1.36 + }, 1.37 + { 1.38 + "geolocation": [], 1.39 + }, 1.40 + { 1.41 + "desktop-notification": [], 1.42 + } 1.43 +]; 1.44 + 1.45 +function runNext() { 1.46 + if (gResult.length > 0) { 1.47 + // Put the requested permission in query string 1.48 + let requestedPermission = JSON.stringify(Object.keys(gResult[0])); 1.49 + info('request permissions for ' + requestedPermission); 1.50 + iframe.src = APP_URL + '?' + encodeURIComponent(requestedPermission); 1.51 + } else { 1.52 + info('test finished, teardown'); 1.53 + gScript.sendAsyncMessage("teardown", ""); 1.54 + gScript.destroy(); 1.55 + SimpleTest.finish(); 1.56 + } 1.57 +} 1.58 + 1.59 +// Create a sanbox iframe. 1.60 +function loadBrowser() { 1.61 + iframe = document.createElement("iframe"); 1.62 + SpecialPowers.wrap(iframe).mozbrowser = true; 1.63 + iframe.src = 'about:blank'; 1.64 + document.body.appendChild(iframe); 1.65 + 1.66 + iframe.addEventListener("load", function onLoad() { 1.67 + iframe.removeEventListener("load", onLoad); 1.68 + runNext(); 1.69 + }); 1.70 +} 1.71 + 1.72 +gScript.addMessageListener("permission-request", function (detail) { 1.73 + let permissions = detail.permissions; 1.74 + let expectedValue = gResult.shift(); 1.75 + let permissionTypes = Object.keys(permissions); 1.76 + 1.77 + is(permissionTypes.length, Object.keys(expectedValue).length, "expected number of permissions"); 1.78 + 1.79 + for (let type of permissionTypes) { 1.80 + ok(expectedValue.hasOwnProperty(type), "expected permission type"); 1.81 + for (let i in permissions[type]) { 1.82 + is(permissions[type][i], expectedValue[type][i], "expected permission option"); 1.83 + } 1.84 + } 1.85 + runNext(); 1.86 +}); 1.87 + 1.88 +// Add permissions to this app. We use ALLOW_ACTION here. The ContentPermissionPrompt 1.89 +// should prompt for permission, not allow it without prompt. 1.90 +SpecialPowers.pushPrefEnv({"set": [["media.navigator.permission.disabled", false]]}, 1.91 + function() { 1.92 + SpecialPowers.addPermission('video-capture', 1.93 + SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION, document); 1.94 + SpecialPowers.addPermission('audio-capture', 1.95 + SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION, document); 1.96 + SpecialPowers.addPermission('geolocation', 1.97 + SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION, document); 1.98 + SpecialPowers.addPermission('desktop-notification', 1.99 + SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION, document); 1.100 + loadBrowser(); 1.101 + }); 1.102 + 1.103 +SimpleTest.waitForExplicitFinish(); 1.104 +</script> 1.105 +</pre> 1.106 +</body> 1.107 +</html>