takePhoto-with-PhotoSettings.https.html (2409B)
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 const fillLightModeNames = ['off', 'auto', 'flash']; 11 12 // This test verifies that ImageCapture can call takePhoto with a PhotoSettings 13 // argument, with a mock Mojo interface implementation. 14 15 image_capture_test(async (t, imageCaptureTest) => { 16 let canvas = document.getElementById('canvas'); 17 let context = canvas.getContext('2d'); 18 context.fillStyle = 'red'; 19 context.fillRect(0, 0, 10, 10); 20 let stream = canvas.captureStream(); 21 22 const optionsDict = { imageWidth : 1080, 23 imageHeight : 100, 24 redEyeReduction : true, 25 fillLightMode : 'flash' 26 }; 27 28 let capturer = new ImageCapture(stream.getVideoTracks()[0]); 29 let blob = await capturer.takePhoto(optionsDict); 30 31 // JS Blob is almost-opaque, can only check |type| and |size|. 32 assert_equals(blob.type, 'image/cat'); 33 assert_equals(blob.size, 2); 34 35 36 assert_equals(true, imageCaptureTest.mockImageCapture().options().hasWidth, 37 'hasWidth'); 38 assert_equals(optionsDict.imageWidth, 39 imageCaptureTest.mockImageCapture().options().width,'width'); 40 assert_equals(true, imageCaptureTest.mockImageCapture().options().hasHeight, 41 'hasHeight'); 42 assert_equals(optionsDict.imageHeight, 43 imageCaptureTest.mockImageCapture().options().height, 44 'height'); 45 46 // Depending on how mojo boolean packing in integers is arranged, this can 47 // be a number instead of a boolean, compare directly. 48 // TODO(mcasas): Revert to assert_equals() when yzshen@ has sorted it out. 49 assert_true( 50 optionsDict.redEyeReduction == imageCaptureTest.mockImageCapture(). 51 options().redEyeReduction, 'redEyeReduction'); 52 53 assert_equals(true, 54 imageCaptureTest.mockImageCapture().options().hasFillLightMode, 55 'hasFillLightMode'); 56 assert_equals(optionsDict.fillLightMode, 57 fillLightModeNames[ 58 imageCaptureTest.mockImageCapture().options().fillLightMode], 59 'fillLightMode'); 60 61 }, 'exercises ImageCapture.takePhoto(PhotoSettings dictionary)'); 62 63 </script>