b2g/components/test/mochitest/test_permission_deny.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/b2g/components/test/mochitest/test_permission_deny.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,83 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=981113
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Permission Deny Test</title>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=981113">Test Permission Deny</a>
    1.17 +<script type="application/javascript;version=1.8">
    1.18 +
    1.19 +'use strict';
    1.20 +
    1.21 +SimpleTest.waitForExplicitFinish();
    1.22 +
    1.23 +const PROMPT_ACTION = SpecialPowers.Ci.nsIPermissionManager.PROMPT_ACTION;
    1.24 +
    1.25 +var gUrl = SimpleTest.getTestFileURL('permission_handler_chrome.js');
    1.26 +var gScript = SpecialPowers.loadChromeScript(gUrl);
    1.27 +var gTests = [
    1.28 +  {
    1.29 +    'video': true,
    1.30 +  },
    1.31 +  {
    1.32 +    'audio': true,
    1.33 +    'video': true,
    1.34 +  },
    1.35 +  {
    1.36 +    'audio': true,
    1.37 +  },
    1.38 +];
    1.39 +
    1.40 +function runNext() {
    1.41 +  if (gTests.length > 0) {
    1.42 +    // Put the requested permission in query string
    1.43 +    let requestedType = gTests.shift();
    1.44 +    info('getUserMedia for ' + JSON.stringify(requestedType));
    1.45 +    navigator.mozGetUserMedia(requestedType, function success() {
    1.46 +      ok(false, 'unexpected success, permission request should be denied');
    1.47 +      runNext();
    1.48 +    }, function failure(err) {
    1.49 +      is(err.toLowerCase(), 'permission denied', 'expected permission denied');
    1.50 +      runNext();
    1.51 +    });
    1.52 +  } else {
    1.53 +    info('test finished, teardown');
    1.54 +    gScript.sendAsyncMessage('teardown', '');
    1.55 +    gScript.destroy();
    1.56 +    SimpleTest.finish();
    1.57 +  }
    1.58 +}
    1.59 +
    1.60 +gScript.addMessageListener('permission-request', function(detail) {
    1.61 +  let response = {
    1.62 +    id: detail.id,
    1.63 +    type: 'permission-deny',
    1.64 +    remember: false,
    1.65 +  };
    1.66 +  gScript.sendAsyncMessage('permission-response', response);
    1.67 +});
    1.68 +
    1.69 +// Need to change camera permission from ALLOW to PROMPT, otherwise
    1.70 +// MediaManager will automatically allow video-only gUM request.
    1.71 +SpecialPowers.pushPermissions([
    1.72 +    {type: 'video-capture', allow: PROMPT_ACTION, context: document},
    1.73 +    {type: 'audio-capture', allow: PROMPT_ACTION, context: document},
    1.74 +    {type: 'camera', allow: PROMPT_ACTION, context: document},
    1.75 +  ], function() {
    1.76 +    SpecialPowers.pushPrefEnv({
    1.77 +        'set': [
    1.78 +          ['media.navigator.permission.disabled', false],
    1.79 +        ]
    1.80 +      }, runNext);
    1.81 +  }
    1.82 +);
    1.83 +</script>
    1.84 +</pre>
    1.85 +</body>
    1.86 +</html>

mercurial