tor-browser

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

GUM-backgroundBlur.https.html (5746B)


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