File: MediaDevices-getUserMedia.https.html

package info (click to toggle)
firefox-esr 68.10.0esr-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,143,932 kB
  • sloc: cpp: 5,227,879; javascript: 4,315,531; ansic: 2,467,042; python: 794,975; java: 349,993; asm: 232,034; xml: 228,320; sh: 82,008; lisp: 41,202; makefile: 22,347; perl: 15,555; objc: 5,277; cs: 4,725; yacc: 1,778; ada: 1,681; pascal: 1,673; lex: 1,417; exp: 527; php: 436; ruby: 225; awk: 162; sed: 53; csh: 44
file content (125 lines) | stat: -rw-r--r-- 5,350 bytes parent folder | download | duplicates (2)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!doctype html>
<html>
<head>
<title>getUserMedia: test that mediaDevices.getUserMedia is present</title>
<link rel="author" title="Dr Alex Gouaillard" href="mailto:agouaillard@gmail.com"/>
<link rel="help" href="https://w3c.github.io/mediacapture-main/#mediadevices-interface-extensions">
<meta name='assert' content='Check that the mediaDevices.getUserMedia() method is present.'/>
</head>
<body>
<h1 class="instructions">Description</h1>
<p class="instructions">This test checks for the presence of the
<code>navigator.mediaDevices.getUserMedia</code> method.</p>
<div id='log'></div>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
test(function () {
  assert_true(undefined !== navigator.mediaDevices.getUserMedia, "navigator.mediaDevices.getUserMedia exists.");
  // TODO: do some stuff with it
  assert_true(undefined !== navigator.mediaDevices.getSupportedConstraints, "navigator.mediaDevices.getSupportedConstraints exists.");
  var list = navigator.mediaDevices.getSupportedConstraints();
  // TODO: we are supposed to check that all values returned can be used in a constraint ....
  // NOTE: the current list of attributes that may or may not be here
  // ...   FF for example has many no tin that list, should we fail if an attribute is present but not listed in the specs?
  //   list.width
  //   list.height
  //   list.aspectRatio
  //   list.frameRate
  //   list.facingMode
  //   list.volume
  //   list.sampleRate
  //   list.sampleSize
  //   list.echoCancellation
  //   list.latency
  //   list.channelCount
  //   list.deviceId
  //   list.groupId
  }, "mediaDevices.getUserMedia() is present on navigator");

promise_test(t => {
  return navigator.mediaDevices.enumerateDevices()
    .then(t.step_func(async devices => {
      for (var i in devices) {
        await navigator.mediaDevices.getUserMedia(
          {video: {groupId: {exact: devices[i].groupId}}})
            .then(
              t.step_func(stream => {
                var found_device = devices.find(element => {
                  return element.deviceId ==
                           stream.getTracks()[0].getSettings().deviceId;
                });
                assert_true(undefined !== found_device);
                assert_equals(found_device.kind, "videoinput");
                assert_equals(found_device.groupId, devices[i].groupId);
              }),
              t.step_func(error => {
                assert_equals(error.name, "OverconstrainedError");
                assert_equals(error.constraint, "groupId");
                var found_device = devices.find(element => {
                  return element.kind == "videoinput" &&
                        element.groupId == devices[i].groupId});
                assert_true(undefined === found_device);
              }));
      }
    }));
}, 'groupId is correctly supported by getUserMedia() for video devices');

promise_test(t => {
  return navigator.mediaDevices.enumerateDevices()
    .then(t.step_func(async devices => {
      for (var i in devices) {
        await navigator.mediaDevices.getUserMedia(
          {audio: {groupId: {exact: devices[i].groupId}}})
            .then(
              t.step_func(stream => {
                var found_device = devices.find(element => {
                  return element.deviceId ==
                           stream.getTracks()[0].getSettings().deviceId;
                });
                assert_true(undefined !== found_device);
                assert_equals(found_device.kind, "audioinput");
                assert_equals(found_device.groupId, devices[i].groupId);
              }),
              t.step_func(error => {
                assert_equals(error.name, "OverconstrainedError");
                assert_equals(error.constraint, "groupId");
                var found_device = devices.find(element => {
                  return element.kind == "audioinput" &&
                        element.groupId == devices[i].groupId});
                assert_true(undefined === found_device);
              }));
      }
    }));
}, 'groupId is correctly supported by getUserMedia() for audio devices');

promise_test(async t => {
  const stream = await navigator.mediaDevices.getUserMedia(
      { video: {resizeMode: {exact: 'none'}}});
  const [track] = stream.getVideoTracks();
  t.add_cleanup(() => track.stop());
  assert_equals(track.getSettings().resizeMode, 'none');
}, 'getUserMedia() supports setting none as resizeMode.');

promise_test(async t => {
  const stream = await navigator.mediaDevices.getUserMedia(
      { video: {resizeMode: {exact: 'crop-and-scale'}}});
  const [track] = stream.getVideoTracks();
  t.add_cleanup(() => track.stop());
  assert_equals(track.getSettings().resizeMode, 'crop-and-scale');
}, 'getUserMedia() supports setting crop-and-scale as resizeMode.');

promise_test(async t => {
  try {
    let stream = await navigator.mediaDevices.getUserMedia(
        { video: {resizeMode: {exact: 'INVALID'}}});
    t.add_cleanup(() => stream.getVideoTracks()[0].stop());
    t.unreached_func('getUserMedia() should fail with invalid resizeMode')();
  } catch (e) {
    assert_equals(e.name, 'OverconstrainedError');
    assert_equals(e.constraint, 'resizeMode');
  }
}, 'getUserMedia() fails with exact invalid resizeMode.');
</script>
</body>
</html>