blob: fff36e1a3b8bcf46c6a6f3ac765a509f37c45a07 [file] [log] [blame]
Rijubrata Bhaumikebd787772018-08-29 16:34:381<!DOCTYPE html>
2<script src="/resources/testharness.js"></script>
3<script src="/resources/testharnessreport.js"></script>
4<script src="/mediacapture-image/resources/imagecapture-helpers.js"></script>
5<body>
Simon Pietersf620b1e2023-06-12 10:02:376<canvas id='canvas' width=10 height=10></canvas>
Rijubrata Bhaumikebd787772018-08-29 16:34:387</body>
8<script>
9
10let canvas = document.getElementById('canvas');
11let context = canvas.getContext('2d');
12context.fillStyle = 'red';
13context.fillRect(0, 0, 10, 10);
14
15// This test verifies that ImageCapture.takePhoto() rejects if any passed
16// option is unsupported or outside its allowed range.
17function makePromiseTest(getOption) {
18 image_capture_test(async (t, imageCaptureTest) => {
19 imageCaptureTest.mockImageCapture().state().redEyeReduction = 0;
20
21 let stream = canvas.captureStream();
22 let capturer = new ImageCapture(stream.getVideoTracks()[0]);
23 await capturer.getPhotoCapabilities();
24 const options = getOption(imageCaptureTest.mockImageCapture().state());
25
26 try {
27 await capturer.takePhoto(options);
28 assert_unreached('expected takePhoto to reject');
29 } catch (error) {
30 assert_equals(error.name, 'NotSupportedError');
31 }
32 });
33}
34
35const optionsGenerators = [
36 capabilities => ({ redEyeReduction: true }),
37 capabilities => ({ imageHeight: capabilities.height.max + 1 }),
38 capabilities => ({ imageHeight: capabilities.height.min - 1 }),
39 capabilities => ({ imageWidth: capabilities.width.max + 1 }),
40 capabilities => ({ imageWidth: capabilities.width.min - 1 }),
41 capabilities => ({ fillLightMode: 'off' }),
42];
43
44for (key in optionsGenerators) {
45 generate_tests(
46 makePromiseTest,
47 [[ 'ImageCapture.takePhoto(options) rejects with bad options, #' + key,
48 optionsGenerators[key] ]]);
49}
50
51</script>