summaryrefslogtreecommitdiffstats
path: root/b2g/components/test/mochitest/test_permission_deny.html
blob: 29c35bdecd1337fb06539e5f6669f8eb561e49f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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>