summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-applyConstraints-reject.https.html
blob: 0bb4c9f74eb76fa5e8f701a1714601b619a0a9f7 (plain)
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
<!DOCTYPE html>
<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>
<script>

// This test verifies that MediaStreamTrack.applyConstraints() rejects if any
// passed constraint is unsupported or outside its allowed range.
var makePromiseTest = function(getConstraint) {
  image_capture_test(async (t, imageCaptureTest) => {
    await test_driver.set_permission({name: 'camera', panTiltZoom: true},
        'granted');

    imageCaptureTest.mockImageCapture().state().supportsTorch = false;

    let stream = await navigator.mediaDevices.getUserMedia({video: true});
    let videoTrack = stream.getVideoTracks()[0];

    const constraint = getConstraint(imageCaptureTest.mockImageCapture().state());
    try {
      await videoTrack.applyConstraints(constraint);
      assert_unreached('expected applyConstraints to reject');
    } catch (error) {
      assert_equals(error.name, 'OverconstrainedError');
      assert_equals(error.constraint, Object.keys(constraint)[0]);
    }
  });
};

const constraintGenerators = [
  capabilities => ({ whiteBalanceMode: { exact: 'manual' } }),
  capabilities => ({ exposureMode: { exact: 'none' } }),
  capabilities => ({ focusMode: { exact: 'continuous' } }),
  capabilities => ({
    exposureCompensation: { exact: capabilities.exposureCompensation.max + 1 }
  }),
  capabilities => ({
    exposureCompensation: { exact: capabilities.exposureCompensation.min - 1 }
  }),
  capabilities => ({
    colorTemperature: { exact: capabilities.colorTemperature.max + 1 }
  }),
  capabilities => ({
    colorTemperature: { exact: capabilities.colorTemperature.min - 1 }
  }),
  capabilities => ({ iso: { exact: capabilities.iso.max + 1 } }),
  capabilities => ({ iso: { exact: capabilities.iso.min - 1 } }),
  capabilities => ({ brightness: { exact: capabilities.brightness.max + 1 } }),
  capabilities => ({ brightness: { exact: capabilities.brightness.min - 1 } }),
  capabilities => ({ contrast: { exact: capabilities.contrast.max + 1 } }),
  capabilities => ({ contrast: { exact: capabilities.contrast.min - 1 } }),
  capabilities => ({ saturation: { exact: capabilities.saturation.max + 1 } }),
  capabilities => ({ saturation: { exact: capabilities.saturation.min - 1 } }),
  capabilities => ({ sharpness: { exact: capabilities.sharpness.max + 1 } }),
  capabilities => ({ sharpness: { exact: capabilities.sharpness.min - 1 } }),
  capabilities => ({ pan: { exact: capabilities.pan.max + 1 } }),
  capabilities => ({ pan: { exact: capabilities.pan.min - 1 } }),
  capabilities => ({ tilt: { exact: capabilities.tilt.max + 1 } }),
  capabilities => ({ tilt: { exact: capabilities.tilt.min - 1 } }),
  capabilities => ({ zoom: { exact: capabilities.zoom.max + 1 } }),
  capabilities => ({ zoom: { exact: capabilities.zoom.min - 1 } }),
  capabilities => ({ torch: { exact: true } }),
];

for (key in constraintGenerators) {
  generate_tests(
      makePromiseTest, [[
        'MediaStreamTrack.applyConstraints(constraints) rejects with bad' +
        ' constraints, #' + key,
        constraintGenerators[key]
      ]]);
}

</script>