Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=981113
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Permission Deny 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=981113">Test Permission Deny</a>
14 <script type="application/javascript;version=1.8">
16 'use strict';
18 SimpleTest.waitForExplicitFinish();
20 const PROMPT_ACTION = SpecialPowers.Ci.nsIPermissionManager.PROMPT_ACTION;
22 var gUrl = SimpleTest.getTestFileURL('permission_handler_chrome.js');
23 var gScript = SpecialPowers.loadChromeScript(gUrl);
24 var gTests = [
25 {
26 'video': true,
27 },
28 {
29 'audio': true,
30 'video': true,
31 },
32 {
33 'audio': true,
34 },
35 ];
37 function runNext() {
38 if (gTests.length > 0) {
39 // Put the requested permission in query string
40 let requestedType = gTests.shift();
41 info('getUserMedia for ' + JSON.stringify(requestedType));
42 navigator.mozGetUserMedia(requestedType, function success() {
43 ok(false, 'unexpected success, permission request should be denied');
44 runNext();
45 }, function failure(err) {
46 is(err.toLowerCase(), 'permission denied', 'expected permission denied');
47 runNext();
48 });
49 } else {
50 info('test finished, teardown');
51 gScript.sendAsyncMessage('teardown', '');
52 gScript.destroy();
53 SimpleTest.finish();
54 }
55 }
57 gScript.addMessageListener('permission-request', function(detail) {
58 let response = {
59 id: detail.id,
60 type: 'permission-deny',
61 remember: false,
62 };
63 gScript.sendAsyncMessage('permission-response', response);
64 });
66 // Need to change camera permission from ALLOW to PROMPT, otherwise
67 // MediaManager will automatically allow video-only gUM request.
68 SpecialPowers.pushPermissions([
69 {type: 'video-capture', allow: PROMPT_ACTION, context: document},
70 {type: 'audio-capture', allow: PROMPT_ACTION, context: document},
71 {type: 'camera', allow: PROMPT_ACTION, context: document},
72 ], function() {
73 SpecialPowers.pushPrefEnv({
74 'set': [
75 ['media.navigator.permission.disabled', false],
76 ]
77 }, runNext);
78 }
79 );
80 </script>
81 </pre>
82 </body>
83 </html>