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 (c68fe15a81fc)

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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/mediacapture-image/resources/imagecapture-helpers.js"></script>
</body>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>

// This test verifies that MediaTrackCapabilities are returned upon
const meteringModeNames = ['none', 'manual', 'single-shot', 'continuous'];

// This test verifies that MediaTrackCapabilities are returned upon
// MediaStreamTrack.getCapabilities(), with a mock Mojo service implementation.
// When PTZ permission is denied though, PTZ capabilities are not available.
  let context = canvas.getContext('2d');

function makeImageCaptureTest(hasPanTiltZoomPermissionGranted) {
  image_capture_test(async (t, imageCaptureTest) => {
    const ptzPermission = hasPanTiltZoomPermissionGranted ? 'granted' : 'denied';
    await test_driver.set_permission({name: 'camera', panTiltZoom: true},

        ptzPermission, false);

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

    let mockCapabilities = imageCaptureTest.mockImageCapture().state();
  assert_equals(typeof videoTrack.getCapabilities, 'function');

    // |stream| must be created _after_ |mock| is constructed to give the
    // latter time to override the bindings.
    let stream = canvas.captureStream();
    assert_equals(stream.getAudioTracks().length, 0);
  // TODO(mcasas): this shouldn't be needed, https://crbug.com/711524.
    assert_equals(stream.getVideoTracks().length, 1);

    let videoTrack = stream.getVideoTracks()[0];
    assert_equals(typeof videoTrack.getCapabilities, 'function');


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

    let capabilities = videoTrack.getCapabilities();
    assert_equals(typeof capabilities, 'object');
        meteringModeNames[mockCapabilities

    assert_equals(capabilities.whiteBalanceMode.length,
                  mockCapabilities.supportedWhiteBalanceModes.length,
                  'whiteBalanceMode');
  assert_equals(capabilities.exposureMode.length,
    for (i = 0; i < capabilities.whiteBalanceMode.length; ++i) {
      assert_equals(
          capabilities.whiteBalanceMode[i],
          meteringModeNames[mockCapabilities
                                .supportedWhiteBalanceModes[i]],
          'whiteBalanceMode');
    }

        'exposureMode');
    assert_equals(capabilities.exposureMode.length,
                  mockCapabilities.supportedExposureModes.length,
                  'exposureMode');
    for (i = 0; i < capabilities.exposureMode.length; ++i) {
      assert_equals(
                'focusMode');
          capabilities.exposureMode[i],
          meteringModeNames[mockCapabilities.supportedExposureModes[i]],
          'exposureMode');
    }

        'focusMode');
    assert_equals(capabilities.focusMode.length,
                  mockCapabilities.supportedFocusModes.length,
                  'focusMode');
    for (i = 0; i < capabilities.focusMode.length; ++i) {
      assert_equals(
  assert_equals(capabilities.exposureCompensation.max,
          capabilities.focusMode[i],
          meteringModeNames[mockCapabilities.supportedFocusModes[i]],
          'focusMode');
    }

                mockCapabilities.exposureCompensation.step);
    assert_true(capabilities.exposureCompensation instanceof
                MediaSettingsRange);
    assert_equals(capabilities.exposureCompensation.max,
                  mockCapabilities.exposureCompensation.max);
    assert_equals(capabilities.exposureCompensation.min,
                  mockCapabilities.exposureCompensation.min);
                mockCapabilities.exposureTime.min);
    assert_equals(capabilities.exposureCompensation.step,
                  mockCapabilities.exposureCompensation.step);

                mockCapabilities.exposureTime.step);
    assert_true(capabilities.exposureTime instanceof
                MediaSettingsRange);
    assert_equals(capabilities.exposureTime.max,
                  mockCapabilities.exposureTime.max);
                mockCapabilities.colorTemperature.max);
    assert_equals(capabilities.exposureTime.min,
                  mockCapabilities.exposureTime.min);
    assert_equals(capabilities.exposureTime.step,
                  mockCapabilities.exposureTime.step);


    assert_true(capabilities.colorTemperature instanceof
                MediaSettingsRange);
    assert_equals(capabilities.colorTemperature.max,
                  mockCapabilities.colorTemperature.max);
    assert_equals(capabilities.colorTemperature.min,

                  mockCapabilities.colorTemperature.min);
    assert_equals(capabilities.colorTemperature.step,
                  mockCapabilities.colorTemperature.step);

    assert_true(capabilities.iso instanceof MediaSettingsRange);
                mockCapabilities.brightness.min);
    assert_equals(capabilities.iso.max, mockCapabilities.iso.max);
    assert_equals(capabilities.iso.min, mockCapabilities.iso.min);
    assert_equals(capabilities.iso.step, mockCapabilities.iso.step);

    assert_true(capabilities.brightness instanceof MediaSettingsRange);
  assert_true(capabilities.contrast instanceof MediaSettingsRange);
    assert_equals(capabilities.brightness.max,
                  mockCapabilities.brightness.max);
    assert_equals(capabilities.brightness.min,
                  mockCapabilities.brightness.min);
  assert_equals(capabilities.contrast.step,
    assert_equals(capabilities.brightness.step,
                  mockCapabilities.brightness.step);

    assert_true(capabilities.contrast instanceof MediaSettingsRange);
  assert_true(capabilities.saturation instanceof MediaSettingsRange);
    assert_equals(capabilities.contrast.max,
                  mockCapabilities.contrast.max);
    assert_equals(capabilities.contrast.min,
                  mockCapabilities.contrast.min);
    assert_equals(capabilities.contrast.step,
  assert_equals(capabilities.saturation.step,
                  mockCapabilities.contrast.step);

    assert_true(capabilities.saturation instanceof MediaSettingsRange);
    assert_equals(capabilities.saturation.max,
                  mockCapabilities.saturation.max);
                mockCapabilities.sharpness.max);
    assert_equals(capabilities.saturation.min,
                  mockCapabilities.saturation.min);
    assert_equals(capabilities.saturation.step,
                  mockCapabilities.saturation.step);


    assert_true(capabilities.sharpness instanceof MediaSettingsRange);
    assert_equals(capabilities.sharpness.max,
                  mockCapabilities.sharpness.max);
    assert_equals(capabilities.sharpness.min,
                  mockCapabilities.sharpness.min);
                mockCapabilities.focusDistance.min);
    assert_equals(capabilities.sharpness.step,
                  mockCapabilities.sharpness.step);

    assert_true(capabilities.focusDistance instanceof MediaSettingsRange);
    assert_equals(capabilities.focusDistance.max,
  assert_equals(capabilities.pan.max, mockCapabilities.pan.max);
                  mockCapabilities.focusDistance.max);
    assert_equals(capabilities.focusDistance.min,
                  mockCapabilities.focusDistance.min);

    assert_equals(capabilities.focusDistance.step,
  assert_true(capabilities.tilt instanceof MediaSettingsRange);
                  mockCapabilities.focusDistance.step);

  assert_equals(capabilities.tilt.step, mockCapabilities.tilt.step);
    if (ptzPermission === 'granted') {
      assert_true(capabilities.pan instanceof MediaSettingsRange);
      assert_equals(capabilities.pan.max, mockCapabilities.pan.max);
      assert_equals(capabilities.pan.min, mockCapabilities.pan.min);
      assert_equals(capabilities.pan.step, mockCapabilities.pan.step);
  assert_equals(capabilities.zoom.step, mockCapabilities.zoom.step);

      assert_true(capabilities.tilt instanceof MediaSettingsRange);
      assert_equals(capabilities.tilt.max, mockCapabilities.tilt.max);
      assert_equals(capabilities.tilt.min, mockCapabilities.tilt.min);
      assert_equals(capabilities.tilt.step, mockCapabilities.tilt.step);
}, 'exercises MediaStreamTrack.getCapabilities()');
    } else if (ptzPermission === 'denied') {
      assert_false('pan' in capabilities);
      assert_false('tilt' in capabilities);
    }
    assert_true(capabilities.zoom instanceof MediaSettingsRange);
    assert_equals(capabilities.zoom.max, mockCapabilities.zoom.max);
    assert_equals(capabilities.zoom.min, mockCapabilities.zoom.min);
    assert_equals(capabilities.zoom.step, mockCapabilities.zoom.step);

    assert_equals(capabilities.torch, mockCapabilities.supportsTorch,
                  'torch');
  });
}

generate_tests(makeImageCaptureTest, [
  [
    "exercises MediaStreamTrack.getCapabilities() with PTZ permission denied",
    false,
  ],
  [
    "exercises MediaStreamTrack.getCapabilities() with PTZ permission granted",
    true,
  ],
]);
</script>