| Rijubrata Bhaumik | ebd78777 | 2018-08-29 16:34:38 | [diff] [blame] | 1 | <!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 Pieters | f620b1e | 2023-06-12 10:02:37 | [diff] [blame] | 6 | <canvas id='canvas' width=10 height=10></canvas> |
| Rijubrata Bhaumik | ebd78777 | 2018-08-29 16:34:38 | [diff] [blame] | 7 | </body> |
| 8 | <script> |
| 9 | |
| 10 | let canvas = document.getElementById('canvas'); |
| 11 | let context = canvas.getContext('2d'); |
| 12 | context.fillStyle = 'red'; |
| 13 | context.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. |
| 17 | function 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 | |
| 35 | const 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 | |
| 44 | for (key in optionsGenerators) { |
| 45 | generate_tests( |
| 46 | makePromiseTest, |
| 47 | [[ 'ImageCapture.takePhoto(options) rejects with bad options, #' + key, |
| 48 | optionsGenerators[key] ]]); |
| 49 | } |
| 50 | |
| 51 | </script> |