File: MediaStreamTrack-applyConstraints.https.html

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (147 lines) | stat: -rw-r--r-- 6,276 bytes parent folder | download
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!doctype html>
<title>MediaStreamTrack applyConstraints</title>
<p class="instructions">When prompted, accept to share your video stream.</p>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/resources/testdriver.js></script>
<script src=/resources/testdriver-vendor.js></script>
<script src=permission-helper.js></script>
<script>
  'use strict'

  // https://w3c.github.io/mediacapture-main/#dom-mediastreamtrack-applyconstraints

  promise_test(async t => {
    await setMediaPermission("granted", ["camera"]);
    return navigator.mediaDevices.getUserMedia({ video: true })
      .then(t.step_func(stream => {
        return stream.getVideoTracks()[0].applyConstraints(
          { groupId: { exact: "INVALID" } }).then(
            t.unreached_func('Accepted invalid groupID'),
            t.step_func(e => {
              assert_equals(e.name, 'OverconstrainedError');
              assert_equals(e.constraint, 'groupId');
            }));
      }));
  }, 'applyConstraints rejects invalid groupID');

  promise_test(async t => {
    let long_string_groupId = "2".padStart(501);
    await setMediaPermission("granted", ["camera"]);
    return navigator.mediaDevices.getUserMedia({ video: true })
      .then(t.step_func(stream => {
        return stream.getVideoTracks()[0].applyConstraints(
          { groupId: { ideal: long_string_groupId } }).then(
            t.unreached_func('Accepted ideal long string groupID'),
            t.step_func(e => {
              assert_equals(e.name, 'OverconstrainedError');
            }));
      }));
  }, 'applyConstraints rejects long string ideal groupID');

  promise_test(async t => {
    let long_string_groupId = "2".padStart(501);
    await setMediaPermission("granted", ["camera"]);
    return navigator.mediaDevices.getUserMedia({ video: true })
      .then(t.step_func(stream => {
        return stream.getVideoTracks()[0].applyConstraints(
          { groupId: { exact: long_string_groupId } }).then(
            t.unreached_func('Accepted exact long string  groupID'),
            t.step_func(e => {
              assert_equals(e.name, 'OverconstrainedError');
            }));
      }));
  }, 'applyConstraints rejects long string groupID');

  promise_test(async t => {
    await setMediaPermission("granted", ["camera"]);
    return navigator.mediaDevices.getUserMedia({ video: true })
      .then(t.step_func(stream => {
        return stream.getVideoTracks()[0].applyConstraints(
          { mandatory: { groupId: "INVALID" }, groupId: { exact: "INVALID" } }).then(
            t.unreached_func('Accepted exact long string  groupID'),
            t.step_func(e => {
              assert_equals(e.name, 'OverconstrainedError');
            }));
      }));
  }, 'applyConstraints rejects using both mandatory and specific constraints');

  promise_test(t => {
    return navigator.mediaDevices.getUserMedia({ video: true })
      .then(t.step_func(stream => {
        var track = stream.getVideoTracks()[0];
        var groupId = track.getSettings().groupId;
        return track.applyConstraints({ groupId: "INVALID" }).then(
          t.step_func(() => {
            assert_equals(track.getSettings().groupId, groupId);
          }));
      }));
  }, 'applyConstraints accepts invalid ideal groupID, does not change setting');

  promise_test(t => {
    return navigator.mediaDevices.getUserMedia({ video: true })
      .then(t.step_func(stream => {
        var track = stream.getVideoTracks()[0];
        var groupId = track.getSettings().groupId;
        return navigator.mediaDevices.enumerateDevices().then(devices => {
          var anotherDevice = devices.find(device => {
            return device.kind == "videoinput" && device.groupId != groupId;
          });
          if (anotherDevice !== undefined) {
            return track.applyConstraints(
              { groupId: { exact: anotherDevice.groupId } }).then(
                t.unreached_func(),
                t.step_func(e => {
                  assert_equals(e.name, 'OverconstrainedError');
                  assert_equals(e.constraint, 'groupId');
                }));
          }
        });
      }));
  }, 'applyConstraints rejects attempt to switch device using groupId');

  promise_test(async t => {
    const stream = await navigator.mediaDevices.getUserMedia({ video: true });
    const [track] = stream.getVideoTracks();
    t.add_cleanup(() => track.stop());
    try {
      await track.applyConstraints({ resizeMode: { exact: "INVALID" } });
      t.unreached_func('applyConstraints() must fail with invalid resizeMode')();
    } catch (e) {
      assert_equals(e.name, 'OverconstrainedError');
      assert_equals(e.constraint, 'resizeMode');
    }
  }, 'applyConstraints rejects invalid resizeMode');

  promise_test(async t => {
    const stream = await navigator.mediaDevices.getUserMedia({ video: true });
    const [track] = stream.getVideoTracks();
    t.add_cleanup(() => track.stop());
    const resizeMode = track.getSettings().resizeMode;
    await track.applyConstraints({ resizeMode: "INVALID" });
    assert_equals(track.getSettings().resizeMode, resizeMode);
  }, 'applyConstraints accepts invalid ideal resizeMode, does not change setting');

  [
    {width: {max: 0}},
    {height: {max: 0}},
    {frameRate: {max: 0}},
    {width: {max: -1}},
    {height: {max: -1}},
    {frameRate: {max: -1}},
    {width: {min: 100, max: 10}},
    {height: {min: 100, max: 10}},
    {frameRate: {min: 100, max: 10}},
  ].forEach(constraints => promise_test(async t => {
    const stream = await navigator.mediaDevices.getUserMedia({ video: true });
    const [track] = stream.getTracks();
    t.add_cleanup(() => track.stop());
    try {
      await track.applyConstraints(constraints);
      assert_unreached('applyConstraints hould have rejected');
    } catch (err) {
      assert_equals(err.name, 'OverconstrainedError', "applyConstraints with impossible constraints rejects with OverconstrainedError");
      assert_equals(err.constraint, Object.keys(constraints)[0], "OverconstrainedError's constraint attribute is set");
    }
  }, `applyConstraints(${JSON.stringify(constraints)}) for video user media must fail with OverconstrainedError`));
</script>