tor-browser

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

MediaStreamTrack-applyConstraints.https.html (5077B)


      1 <!DOCTYPE html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script src="/resources/testdriver.js"></script>
      5 <script src="/resources/testdriver-vendor.js"></script>
      6 <script src="/mediacapture-image/resources/imagecapture-helpers.js"></script>
      7 <script>
      8 
      9 const meteringModeNames = ['none', 'manual', 'single-shot', 'continuous'];
     10 
     11 // This test verifies that we can all MediaStreamTrack.applyConstraints(), with
     12 // a mock Mojo service implementation.
     13 
     14 image_capture_test(async (t, imageCaptureTest) => {
     15  await test_driver.set_permission({name: 'camera', panTiltZoom: true},
     16        'granted');
     17 
     18  const constraints = { advanced : [{ whiteBalanceMode : 'single-shot',
     19                                      exposureMode     : 'manual',
     20                                      focusMode        : 'single-shot',
     21 
     22                                      pointsOfInterest : [{x : 0.1, y : 0.2},
     23                                                          {x : 0.3, y : 0.4}],
     24 
     25                                      exposureCompensation : 133.77,
     26                                      exposureTime         : 10000,
     27                                      colorTemperature     : 6000,
     28                                      iso                  : 120.0,
     29 
     30                                      brightness           : 3,
     31                                      contrast             : 4,
     32                                      saturation           : 5,
     33                                      sharpness            : 6,
     34                                      focusDistance        : 7,
     35 
     36                                      pan                  : 8,
     37                                      tilt                 : 9,
     38                                      zoom                 : 3.141592,
     39 
     40                                      torch                : true
     41                                    }]};
     42 
     43    let stream = await navigator.mediaDevices.getUserMedia({video: true});
     44    let videoTrack = stream.getVideoTracks()[0];
     45 
     46    try {
     47      await videoTrack.applyConstraints(constraints);
     48    } catch (error) {
     49      assert_unreached('applyConstraints(): ' + error.message);
     50    }
     51 
     52    const constraintsDict = constraints.advanced[0];
     53    let appliedConstraints = videoTrack.getConstraints();
     54    const appliedConstraintsDict = appliedConstraints.advanced[0];
     55 
     56    // Check that |appliedConstraints| and |constraints| are equal.
     57    assert_equals(constraintsDict.length, appliedConstraintsDict.length);
     58    Object.keys(appliedConstraintsDict).forEach((key, value) => {
     59      assert_not_equals(constraintsDict[key], undefined, 'key ' + key);
     60      if (key != 'pointsOfInterest') {
     61        assert_equals(constraintsDict[key], appliedConstraintsDict[key], key);
     62      } else {
     63        assert_point2d_array_approx_equals(constraintsDict[key],
     64                                           appliedConstraintsDict[key], 0.01);
     65      }
     66    });
     67 
     68    let theMock = imageCaptureTest.mockImageCapture();
     69    assert_equals(constraintsDict.whiteBalanceMode,
     70                  meteringModeNames[theMock.options().whiteBalanceMode],
     71                  'whiteBalanceMode');
     72    assert_equals(constraintsDict.exposureMode,
     73                  meteringModeNames[theMock.options().exposureMode],
     74                  'exposureMode');
     75    assert_equals(constraintsDict.focusMode,
     76                  meteringModeNames[theMock.options().focusMode],
     77                  'focusMode');
     78 
     79    assert_point2d_array_approx_equals(constraintsDict.pointsOfInterest,
     80                                       theMock.options().pointsOfInterest,
     81                                       0.01);
     82 
     83    assert_equals(constraintsDict.exposureCompensation,
     84                  theMock.options().exposureCompensation,
     85                  'exposureCompensation');
     86    assert_equals(constraintsDict.exposureTime,
     87                  theMock.options().exposureTime,
     88                  'exposureTime');
     89    assert_equals(constraintsDict.colorTemperature,
     90                  theMock.options().colorTemperature, 'colorTemperature');
     91    assert_equals(constraintsDict.iso, theMock.options().iso, 'iso');
     92 
     93    assert_equals(constraintsDict.brightness, theMock.options().brightness,
     94                  'brightness');
     95    assert_equals(constraintsDict.contrast, theMock.options().contrast,
     96                  'constrast');
     97    assert_equals(constraintsDict.saturation, theMock.options().saturation,
     98                  'saturation');
     99    assert_equals(constraintsDict.sharpness, theMock.options().sharpness,
    100                  'sharpness');
    101    assert_equals(constraintsDict.focusDistance, theMock.options().focusDistance
    102                  ,'focusDistance');
    103 
    104    assert_equals(constraintsDict.pan, theMock.options().pan, 'pan');
    105    assert_equals(constraintsDict.tilt, theMock.options().tilt, 'tilt');
    106    assert_equals(constraintsDict.zoom, theMock.options().zoom, 'zoom');
    107 
    108    assert_equals(constraintsDict.torch, theMock.options().torch, 'torch');
    109 
    110 }, 'exercises MediaStreamTrack.applyConstraints(constraints)');
    111 
    112 </script>