summaryrefslogtreecommitdiffstats
path: root/b2g/components/test/mochitest/test_permission_deny.html
diff options
context:
space:
mode:
Diffstat (limited to 'b2g/components/test/mochitest/test_permission_deny.html')
-rw-r--r--b2g/components/test/mochitest/test_permission_deny.html83
1 files changed, 83 insertions, 0 deletions
diff --git a/b2g/components/test/mochitest/test_permission_deny.html b/b2g/components/test/mochitest/test_permission_deny.html
new file mode 100644
index 000000000..29c35bdec
--- /dev/null
+++ b/b2g/components/test/mochitest/test_permission_deny.html
@@ -0,0 +1,83 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=981113
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Permission Deny 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=981113">Test Permission Deny</a>
+<script type="application/javascript;version=1.8">
+
+'use strict';
+
+SimpleTest.waitForExplicitFinish();
+
+const PROMPT_ACTION = SpecialPowers.Ci.nsIPermissionManager.PROMPT_ACTION;
+
+var gUrl = SimpleTest.getTestFileURL('permission_handler_chrome.js');
+var gScript = SpecialPowers.loadChromeScript(gUrl);
+var gTests = [
+ {
+ 'video': true,
+ },
+ {
+ 'audio': true,
+ 'video': true,
+ },
+ {
+ 'audio': true,
+ },
+];
+
+function runNext() {
+ if (gTests.length > 0) {
+ // Put the requested permission in query string
+ let requestedType = gTests.shift();
+ info('getUserMedia for ' + JSON.stringify(requestedType));
+ navigator.mozGetUserMedia(requestedType, function success() {
+ ok(false, 'unexpected success, permission request should be denied');
+ runNext();
+ }, function failure(err) {
+ is(err.name, 'SecurityError', 'expected permission denied');
+ runNext();
+ });
+ } else {
+ info('test finished, teardown');
+ gScript.sendAsyncMessage('teardown', '');
+ gScript.destroy();
+ SimpleTest.finish();
+ }
+}
+
+gScript.addMessageListener('permission-request', function(detail) {
+ let response = {
+ id: detail.id,
+ type: 'permission-deny',
+ remember: false,
+ };
+ gScript.sendAsyncMessage('permission-response', response);
+});
+
+// Need to change camera permission from ALLOW to PROMPT, otherwise
+// MediaManager will automatically allow video-only gUM request.
+SpecialPowers.pushPermissions([
+ {type: 'video-capture', allow: PROMPT_ACTION, context: document},
+ {type: 'audio-capture', allow: PROMPT_ACTION, context: document},
+ {type: 'camera', allow: PROMPT_ACTION, context: document},
+ ], function() {
+ SpecialPowers.pushPrefEnv({
+ 'set': [
+ ['media.navigator.permission.disabled', false],
+ ]
+ }, runNext);
+ }
+);
+</script>
+</pre>
+</body>
+</html>