diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /b2g/components/test/mochitest/test_sandbox_permission.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'b2g/components/test/mochitest/test_sandbox_permission.html')
-rw-r--r-- | b2g/components/test/mochitest/test_sandbox_permission.html | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/b2g/components/test/mochitest/test_sandbox_permission.html b/b2g/components/test/mochitest/test_sandbox_permission.html new file mode 100644 index 000000000..cd13599a3 --- /dev/null +++ b/b2g/components/test/mochitest/test_sandbox_permission.html @@ -0,0 +1,104 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=951997 +--> +<head> + <meta charset="utf-8"> + <title>Permission Prompt Test</title> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=951997">Permission prompt web content test</a> +<script type="application/javascript;version=1.8"> + +"use strict"; + +const APP_URL = "SandboxPromptTest.html"; + +var iframe; +var gUrl = SimpleTest.getTestFileURL("permission_handler_chrome.js"); +var gScript = SpecialPowers.loadChromeScript(gUrl); +var gResult = [ + { + "video-capture": ["back"], + }, + { + "audio-capture": [""], + "video-capture": ["back"], + }, + { + "audio-capture": [""], + }, + { + "geolocation": [], + }, + { + "desktop-notification": [], + } +]; + +function runNext() { + if (gResult.length > 0) { + // Put the requested permission in query string + let requestedPermission = JSON.stringify(Object.keys(gResult[0])); + info('request permissions for ' + requestedPermission); + iframe.src = APP_URL + '?' + encodeURIComponent(requestedPermission); + } else { + info('test finished, teardown'); + gScript.sendAsyncMessage("teardown", ""); + gScript.destroy(); + SimpleTest.finish(); + } +} + +// Create a sanbox iframe. +function loadBrowser() { + iframe = document.createElement("iframe"); + SpecialPowers.wrap(iframe).mozbrowser = true; + iframe.src = 'about:blank'; + document.body.appendChild(iframe); + + iframe.addEventListener("load", function onLoad() { + iframe.removeEventListener("load", onLoad); + runNext(); + }); +} + +gScript.addMessageListener("permission-request", function (detail) { + let permissions = detail.permissions; + let expectedValue = gResult.shift(); + let permissionTypes = Object.keys(permissions); + + is(permissionTypes.length, Object.keys(expectedValue).length, "expected number of permissions"); + + for (let type of permissionTypes) { + ok(expectedValue.hasOwnProperty(type), "expected permission type"); + for (let i in permissions[type]) { + is(permissions[type][i], expectedValue[type][i], "expected permission option"); + } + } + runNext(); +}); + +// Add permissions to this app. We use ALLOW_ACTION here. The ContentPermissionPrompt +// should prompt for permission, not allow it without prompt. +SpecialPowers.pushPrefEnv({"set": [["media.navigator.permission.disabled", false]]}, + function() { + SpecialPowers.addPermission('video-capture', + SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION, document); + SpecialPowers.addPermission('audio-capture', + SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION, document); + SpecialPowers.addPermission('geolocation', + SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION, document); + SpecialPowers.addPermission('desktop-notification', + SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION, document); + loadBrowser(); + }); + +SimpleTest.waitForExplicitFinish(); +</script> +</pre> +</body> +</html> |