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