tor-browser

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

GUM-faceFraming.https.html (5656B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title>Test face framing support</title>
      5 <link rel="help" href="https://w3c.github.io/mediacapture-extensions/">
      6 </head>
      7 <body>
      8 <h1 class="instructions">Description</h1>
      9 <p class="instructions">This test checks face framing support.</p>
     10 <div id='log'></div>
     11 <script src=/resources/testharness.js></script>
     12 <script src=/resources/testharnessreport.js></script>
     13 <script>
     14 "use strict";
     15 
     16 const constraintSet = {
     17  faceFraming: true
     18 };
     19 
     20 Object.keys(constraintSet).forEach(property => {
     21  test(t => {
     22    const supportedConstraints =
     23        navigator.mediaDevices.getSupportedConstraints();
     24    assert_implements_optional(
     25        supportedConstraints[property],
     26        `Optional property ${property} not in supported constraints`);
     27  }, `Test getSupportedConstraints().${property}`);
     28 
     29  promise_test(async t => {
     30    const supportedConstraints =
     31        navigator.mediaDevices.getSupportedConstraints();
     32 
     33    const stream = await navigator.mediaDevices.getUserMedia({video: true});
     34    assert_equals(stream.getAudioTracks().length, 0);
     35    assert_equals(stream.getVideoTracks().length, 1);
     36    const [videoTrack] = stream.getVideoTracks();
     37 
     38    assert_equals(typeof videoTrack.getCapabilities, 'function');
     39    const capabilities = videoTrack.getCapabilities();
     40    assert_equals(typeof capabilities, 'object');
     41 
     42    if (!supportedConstraints[property]) {
     43      assert_false(property in capabilities);
     44    }
     45 
     46    assert_implements_optional(
     47        property in capabilities,
     48        `Optional property ${property} not in capabilities`);
     49 
     50    // Accept [false], [false, true], [true] and [true, false].
     51    assert_array_equals(
     52        capabilities[property],
     53        capabilities[property].length == 1
     54            ? [!!capabilities[property][0]]
     55            : [!!capabilities[property][0], !capabilities[property][0]]);
     56  }, `Test getCapabilities().${property}`);
     57 
     58  promise_test(async t => {
     59    const supportedConstraints =
     60        navigator.mediaDevices.getSupportedConstraints();
     61 
     62    const stream = await navigator.mediaDevices.getUserMedia({video: true});
     63    assert_equals(stream.getAudioTracks().length, 0);
     64    assert_equals(stream.getVideoTracks().length, 1);
     65    const [videoTrack] = stream.getVideoTracks();
     66 
     67    const capabilities = videoTrack.getCapabilities();
     68 
     69    assert_equals(typeof videoTrack.getSettings, 'function');
     70    const settings = videoTrack.getSettings();
     71    assert_equals(typeof settings, 'object');
     72 
     73    if (!supportedConstraints[property] || !(property in capabilities))
     74      assert_false(property in settings);
     75 
     76    assert_implements_optional(
     77        property in capabilities,
     78        `Optional property ${property} not in capabilities`);
     79 
     80    assert_in_array(settings[property], capabilities[property]);
     81  }, `Test getSettings().${property}`);
     82 
     83  promise_test(async t => {
     84    const supportedConstraints =
     85        navigator.mediaDevices.getSupportedConstraints();
     86 
     87    const stream = await navigator.mediaDevices.getUserMedia({video: true});
     88    assert_equals(stream.getAudioTracks().length, 0);
     89    assert_equals(stream.getVideoTracks().length, 1);
     90    const [videoTrack] = stream.getVideoTracks();
     91 
     92    const capabilities = videoTrack.getCapabilities();
     93    const constraints = {
     94      [property]: {exact: constraintSet[property]}
     95    };
     96    const oldSettings = videoTrack.getSettings();
     97 
     98    if (supportedConstraints[property] && !(property in capabilities)) {
     99      // The user agent supports |constraints| but |videoTrack| is not capable
    100      // to apply them.
    101      await videoTrack.applyConstraints(constraints).then(
    102        () => {
    103          assert_unreached('Unexpected success applying constraints');
    104        },
    105        error => {});
    106    } else {
    107      // The user agent does not support |constraints| and will ignore them or
    108      // the user agent supports |constraints| and |videoTrack| is capable to
    109      // apply them.
    110      await videoTrack.applyConstraints(constraints).then(
    111        () => {},
    112        error => {
    113          assert_unreached(`Error applying constraints: ${error.message}`);
    114        });
    115    }
    116 
    117    assert_equals(typeof videoTrack.getConstraints, 'function');
    118    const appliedConstraints = videoTrack.getConstraints();
    119    assert_equals(typeof appliedConstraints, 'object');
    120    const newSettings = videoTrack.getSettings();
    121 
    122    if (!supportedConstraints[property] || !(property in capabilities)) {
    123      // The user agent does not support |constraints| and ignored them or
    124      // the user agent supports |constraints| but |videoTrack| was not capable
    125      // to apply them.
    126      assert_object_equals(appliedConstraints, {});
    127    } else {
    128      // The user agent supports |constraints| and |videoTrack| was capable to
    129      // apply them.
    130      assert_object_equals(appliedConstraints, constraints);
    131    }
    132 
    133    if (!supportedConstraints[property] || !(property in capabilities) ||
    134        !capabilities[property].includes(constraintSet[property])) {
    135      // The user agent does not support |constraints| and ignored them or
    136      // the user agent supports |constraints| but |videoTrack| was not capable
    137      // to apply them or the user agent supports |constraints| and
    138      // |videoTrack| was capable to apply them but could not satisfy advanced
    139      // constraints and skipped them.
    140      assert_object_equals(newSettings, oldSettings);
    141    } else {
    142      // The user agent supports |constraints| and |videoTrack| was capable to
    143      // apply them and could satisfy advanced constraints.
    144      assert_equals(newSettings[property], constraintSet[property]);
    145    }
    146  }, `Test applyConstraints() with ${property}`);
    147 });
    148 </script>
    149 </body>
    150 </html>