DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (882de07e4cbe)

VCS Links

Line Code
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 148 149 150
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<body>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/mediacapture-image/resources/imagecapture-helpers.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>

// This test verifies that we can all MediaStreamTrack.applyConstraints(), with
const meteringModeNames = ['none', 'manual', 'single-shot', 'continuous'];

// This test verifies that we can all MediaStreamTrack.applyConstraints(), with
// a mock Mojo service implementation.

image_capture_test(async (t, imageCaptureTest) => {
  let context = canvas.getContext('2d');
  await test_driver.set_permission({name: 'camera', panTiltZoom: true},
        'granted', false);

  let canvas = document.getElementById('canvas');
                                      exposureMode     : 'manual',
  let context = canvas.getContext('2d');
  context.fillStyle = 'red';
  context.fillRect(0, 0, 10, 10);

  const constraints = { advanced : [{ whiteBalanceMode : 'single-shot',
                                                          {x : 0.3, y : 0.4}],
                                      exposureMode     : 'manual',
                                      focusMode        : 'single-shot',

                                      pointsOfInterest : [{x : 0.1, y : 0.2},
                                                          {x : 0.3, y : 0.4}],
                                      iso                  : 120.0,

                                      exposureCompensation : 133.77,
                                      exposureTime         : 10000,
                                      colorTemperature     : 6000,
                                      iso                  : 120.0,
                                      sharpness            : 6,

                                      brightness           : 3,
                                      contrast             : 4,
                                      saturation           : 5,
                                      sharpness            : 6,
                                      zoom                 : 3.141592,
                                      focusDistance        : 7,

                                      pan                  : 8,
                                      tilt                 : 9,
                                      zoom                 : 3.141592,


                                      torch                : true
                                    }]};

    let stream = canvas.captureStream();
    let videoTrack = stream.getVideoTracks()[0];
    // TODO(mcasas): this shouldn't be needed, https://crbug.com/711524.

    // |videoTrack|'s capabilities gathering, just like the actual capture, is
    // a process kicked off right after creation, we introduce a small delay
    try {
    // to allow for those to be collected, since they are needed to understand
    // which constraints are supported in applyConstraints().
    // TODO(mcasas): this shouldn't be needed, https://crbug.com/711524.
    await new Promise(resolve => step_timeout(resolve, 100));


    try {
      await videoTrack.applyConstraints(constraints);
    } catch (error) {
      assert_unreached('applyConstraints(): ' + error.message);
    }
    // Check that |appliedConstraints| and |constraints| are equal.

    const constraintsDict = constraints.advanced[0];
    let appliedConstraints = videoTrack.getConstraints();
    const appliedConstraintsDict = appliedConstraints.advanced[0];

        assert_equals(constraintsDict[key], appliedConstraintsDict[key], key);
    // Check that |appliedConstraints| and |constraints| are equal.
    assert_equals(constraintsDict.length, appliedConstraintsDict.length);
    Object.keys(appliedConstraintsDict).forEach((key, value) => {
      assert_not_equals(constraintsDict[key], undefined, 'key ' + key);
      }
      if (key != 'pointsOfInterest') {
        assert_equals(constraintsDict[key], appliedConstraintsDict[key], key);
      } else {
        assert_point2d_array_approx_equals(constraintsDict[key],
                                           appliedConstraintsDict[key], 0.01);
                  meteringModeNames[theMock.options().whiteBalanceMode],
      }
    });

    let theMock = imageCaptureTest.mockImageCapture();
    assert_equals(constraintsDict.whiteBalanceMode,
    assert_equals(constraintsDict.focusMode,
                  meteringModeNames[theMock.options().whiteBalanceMode],
                  'whiteBalanceMode');
    assert_equals(constraintsDict.exposureMode,
                  meteringModeNames[theMock.options().exposureMode],
                  'exposureMode');
                                       theMock.options().pointsOfInterest,
    assert_equals(constraintsDict.focusMode,
                  meteringModeNames[theMock.options().focusMode],
                  'focusMode');

    assert_point2d_array_approx_equals(constraintsDict.pointsOfInterest,
                  'exposureCompensation');
                                       theMock.options().pointsOfInterest,
                                       0.01);

    assert_equals(constraintsDict.exposureCompensation,
                  theMock.options().exposureCompensation,
                  theMock.options().colorTemperature, 'colorTemperature');
                  'exposureCompensation');
    assert_equals(constraintsDict.exposureTime,
                  theMock.options().exposureTime,
                  'exposureTime');
    assert_equals(constraintsDict.colorTemperature,
    assert_equals(constraintsDict.contrast, theMock.options().contrast,
                  theMock.options().colorTemperature, 'colorTemperature');
    assert_equals(constraintsDict.iso, theMock.options().iso, 'iso');

    assert_equals(constraintsDict.brightness, theMock.options().brightness,
                  'brightness');
    assert_equals(constraintsDict.contrast, theMock.options().contrast,
                  'constrast');
    assert_equals(constraintsDict.saturation, theMock.options().saturation,
                  ,'focusDistance');
                  'saturation');
    assert_equals(constraintsDict.sharpness, theMock.options().sharpness,
                  'sharpness');
    assert_equals(constraintsDict.focusDistance, theMock.options().focusDistance
                  ,'focusDistance');
    assert_equals(constraintsDict.torch, theMock.options().torch, 'torch');

    assert_equals(constraintsDict.pan, theMock.options().pan, 'pan');
    assert_equals(constraintsDict.tilt, theMock.options().tilt, 'tilt');
    assert_equals(constraintsDict.zoom, theMock.options().zoom, 'zoom');

    assert_equals(constraintsDict.torch, theMock.options().torch, 'torch');

}, 'exercises MediaStreamTrack.applyConstraints(constraints)');

</script>