tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MediaStreamTrack-applyConstraints.https.html (5280B)


      1 <!doctype html>
      2 <title>MediaStreamTrack applyConstraints</title>
      3 <p class="instructions">When prompted, accept to share your video stream.</p>
      4 <script src=/resources/testharness.js></script>
      5 <script src=/resources/testharnessreport.js></script>
      6 <script src=/resources/testdriver.js></script>
      7 <script src=/resources/testdriver-vendor.js></script>
      8 <script src=permission-helper.js></script>
      9 <script>
     10  'use strict'
     11 
     12  // https://w3c.github.io/mediacapture-main/#dom-mediastreamtrack-applyconstraints
     13 
     14  promise_test(async t => {
     15    await setMediaPermission("granted", ["camera"]);
     16    return navigator.mediaDevices.getUserMedia({ video: true })
     17      .then(t.step_func(stream => {
     18        return stream.getVideoTracks()[0].applyConstraints(
     19          { groupId: { exact: "INVALID" } }).then(
     20            t.unreached_func('Accepted invalid groupID'),
     21            t.step_func(e => {
     22              assert_equals(e.name, 'OverconstrainedError');
     23              assert_equals(e.constraint, 'groupId');
     24            }));
     25      }));
     26  }, 'applyConstraints rejects invalid groupID');
     27 
     28  promise_test(async t => {
     29    let long_string_groupId = "2".padStart(501);
     30    await setMediaPermission("granted", ["camera"]);
     31    return navigator.mediaDevices.getUserMedia({ video: true })
     32      .then(t.step_func(stream => {
     33        return stream.getVideoTracks()[0].applyConstraints(
     34          { groupId: { ideal: long_string_groupId } }).then(
     35            t.unreached_func('Accepted ideal long string groupID'),
     36            t.step_func(e => {
     37              assert_equals(e.name, 'OverconstrainedError');
     38            }));
     39      }));
     40  }, 'applyConstraints rejects long string ideal groupID');
     41 
     42  promise_test(async t => {
     43    let long_string_groupId = "2".padStart(501);
     44    await setMediaPermission("granted", ["camera"]);
     45    return navigator.mediaDevices.getUserMedia({ video: true })
     46      .then(t.step_func(stream => {
     47        return stream.getVideoTracks()[0].applyConstraints(
     48          { groupId: { exact: long_string_groupId } }).then(
     49            t.unreached_func('Accepted exact long string  groupID'),
     50            t.step_func(e => {
     51              assert_equals(e.name, 'OverconstrainedError');
     52            }));
     53      }));
     54  }, 'applyConstraints rejects long string groupID');
     55 
     56  promise_test(async t => {
     57    await setMediaPermission("granted", ["camera"]);
     58    return navigator.mediaDevices.getUserMedia({ video: true })
     59      .then(t.step_func(stream => {
     60        return stream.getVideoTracks()[0].applyConstraints(
     61          { mandatory: { groupId: "INVALID" }, groupId: { exact: "INVALID" } }).then(
     62            t.unreached_func('Accepted exact long string  groupID'),
     63            t.step_func(e => {
     64              assert_equals(e.name, 'OverconstrainedError');
     65            }));
     66      }));
     67  }, 'applyConstraints rejects using both mandatory and specific constraints');
     68 
     69  promise_test(t => {
     70    return navigator.mediaDevices.getUserMedia({ video: true })
     71      .then(t.step_func(stream => {
     72        var track = stream.getVideoTracks()[0];
     73        var groupId = track.getSettings().groupId;
     74        return track.applyConstraints({ groupId: "INVALID" }).then(
     75          t.step_func(() => {
     76            assert_equals(track.getSettings().groupId, groupId);
     77          }));
     78      }));
     79  }, 'applyConstraints accepts invalid ideal groupID, does not change setting');
     80 
     81  promise_test(t => {
     82    return navigator.mediaDevices.getUserMedia({ video: true })
     83      .then(t.step_func(stream => {
     84        var track = stream.getVideoTracks()[0];
     85        var groupId = track.getSettings().groupId;
     86        return navigator.mediaDevices.enumerateDevices().then(devices => {
     87          var anotherDevice = devices.find(device => {
     88            return device.kind == "videoinput" && device.groupId != groupId;
     89          });
     90          if (anotherDevice !== undefined) {
     91            return track.applyConstraints(
     92              { groupId: { exact: anotherDevice.groupId } }).then(
     93                t.unreached_func(),
     94                t.step_func(e => {
     95                  assert_equals(e.name, 'OverconstrainedError');
     96                  assert_equals(e.constraint, 'groupId');
     97                }));
     98          }
     99        });
    100      }));
    101  }, 'applyConstraints rejects attempt to switch device using groupId');
    102 
    103  promise_test(async t => {
    104    const stream = await navigator.mediaDevices.getUserMedia({ video: true });
    105    const [track] = stream.getVideoTracks();
    106    t.add_cleanup(() => track.stop());
    107    try {
    108      await track.applyConstraints({ resizeMode: { exact: "INVALID" } });
    109      t.unreached_func('applyConstraints() must fail with invalid resizeMode')();
    110    } catch (e) {
    111      assert_equals(e.name, 'OverconstrainedError');
    112      assert_equals(e.constraint, 'resizeMode');
    113    }
    114  }, 'applyConstraints rejects invalid resizeMode');
    115 
    116  promise_test(async t => {
    117    const stream = await navigator.mediaDevices.getUserMedia({ video: true });
    118    const [track] = stream.getVideoTracks();
    119    t.add_cleanup(() => track.stop());
    120    const resizeMode = track.getSettings().resizeMode;
    121    await track.applyConstraints({ resizeMode: "INVALID" });
    122    assert_equals(track.getSettings().resizeMode, resizeMode);
    123  }, 'applyConstraints accepts invalid ideal resizeMode, does not change setting');
    124 </script>