gecko/b2g/components/test/mochitest/test_permission_deny.html
2014-03-12 08:29:23 -04:00

84 lines
2.2 KiB
HTML

<!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.toLowerCase(), 'permission denied', '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>