takePhoto-reject.https.html (1721B)
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> 6 <canvas id='canvas' width=10 height=10></canvas> 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, name) { 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 }, name); 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 optionsGenerators.forEach((optionsGenerator, key) => { 45 makePromiseTest( 46 optionsGenerator, 47 `ImageCapture.takePhoto(options) rejects with bad options, #${key}`); 48 }); 49 </script>