OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <script src="../resources/mojo-helpers.js"></script> | 4 <script src="../resources/mojo-helpers.js"></script> |
5 <script src="resources/mock-imagecapture.js"></script> | 5 <script src="resources/mock-imagecapture.js"></script> |
6 <body> | 6 <body> |
7 <canvas id='canvas' width=10 height=10/> | 7 <canvas id='canvas' width=10 height=10/> |
8 </body> | 8 </body> |
9 <script> | 9 <script> |
10 | 10 |
11 const meteringModeNames = ["none", "manual", "single-shot", "continuous"]; | |
12 const fillLightModeNames = ["none", "off", "auto", "flash", "torch"]; | 11 const fillLightModeNames = ["none", "off", "auto", "flash", "torch"]; |
13 | 12 |
14 // This test verifies that ImageCapture can call setOptions()s, with a mock Mojo | 13 // This test verifies that ImageCapture can call setOptions()s, with a mock Mojo |
15 // interface implementation. | 14 // interface implementation. |
16 async_test(function(t) { | 15 async_test(function(t) { |
17 var canvas = document.getElementById('canvas'); | 16 var canvas = document.getElementById('canvas'); |
18 var context = canvas.getContext("2d"); | 17 var context = canvas.getContext("2d"); |
19 context.fillStyle = "red"; | 18 context.fillStyle = "red"; |
20 context.fillRect(0, 0, 10, 10); | 19 context.fillRect(0, 0, 10, 10); |
21 var stream = canvas.captureStream(); | 20 var stream = canvas.captureStream(); |
22 | 21 |
23 var theMock = null; | 22 var theMock = null; |
24 const optionsDict = { zoom : 1.7, | 23 const optionsDict = { imageWidth : 1080, |
25 imageWidth : 1080, | |
26 imageHeight : 100, | 24 imageHeight : 100, |
27 focusMode : "single-shot", | |
28 pointsOfInterest : [{x : 0.1, y : 0.2}, | |
29 {x : 0.3, y : 0.4}], | |
30 exposureMode : "continuous", | |
31 exposureCompensation : 133, | |
32 whiteBalanceMode : "manual", | |
33 iso : 120, | |
34 redEyeReduction : true, | 25 redEyeReduction : true, |
35 fillLightMode : "flash", | 26 fillLightMode : "flash" |
36 colorTemperature : 6000, | |
37 brightness : 3, | |
38 contrast : 4, | |
39 saturation : 5, | |
40 sharpness : 6 | |
41 }; | 27 }; |
42 mockImageCaptureReady | 28 mockImageCaptureReady |
43 .then(mock => { | 29 .then(mock => { |
44 theMock = mock; | 30 theMock = mock; |
45 return new ImageCapture(stream.getVideoTracks()[0]); | 31 return new ImageCapture(stream.getVideoTracks()[0]); |
46 }, | 32 }, |
47 error => { | 33 error => { |
48 assert_unreached("Error creating MockImageCapture: " + error); | 34 assert_unreached("Error creating MockImageCapture: " + error); |
49 }) | 35 }) |
50 .then(capturer => { | 36 .then(capturer => { |
51 return capturer.setOptions(optionsDict); | 37 return capturer.setOptions(optionsDict); |
52 }) | 38 }) |
53 .then(function() { | 39 .then(function() { |
54 assert_true(theMock.options().has_zoom, 'has_zoom must be true'); | 40 assert_equals(true, theMock.options().has_width, 'has_width'); |
55 assert_approx_equals(optionsDict.zoom, theMock.options().zoom, 0.1, 'zoom
value'); | 41 assert_equals(optionsDict.imageWidth, theMock.options().width, 'width'); |
56 assert_equals(true, theMock.options().has_width, 'has_width must be true')
; | 42 assert_equals(true, theMock.options().has_height, 'has_height'); |
57 assert_equals(optionsDict.imageWidth, theMock.options().width, 'width valu
e'); | 43 assert_equals(optionsDict.imageHeight, theMock.options().height, |
58 assert_equals(true, theMock.options().has_height, 'has_height must be true
'); | 44 'height'); |
59 assert_equals(optionsDict.imageHeight, theMock.options().height, 'height v
alue'); | 45 |
60 assert_equals(true, theMock.options().has_focus_mode, 'has_focus_mode must
be true'); | |
61 assert_equals(optionsDict.focusMode, | |
62 meteringModeNames[theMock.options().focus_mode], | |
63 'focusMode value'); | |
64 assert_equals(optionsDict.pointsOfInterest.length, | |
65 theMock.options().points_of_interest.length, | |
66 'amount of points of interest'); | |
67 for (i = 0; i < optionsDict.pointsOfInterest.length; i++) { | |
68 assert_approx_equals(optionsDict.pointsOfInterest[i].x, | |
69 theMock.options().points_of_interest[i].x, | |
70 0.001, | |
71 'pointsOfInterest\'s x'); | |
72 assert_approx_equals(optionsDict.pointsOfInterest[i].y, | |
73 theMock.options().points_of_interest[i].y, | |
74 0.001, | |
75 'pointsOfInterest\' y'); | |
76 } | |
77 assert_equals(true, theMock.options().has_exposure_mode, 'has_exposure_mod
e must be true'); | |
78 assert_equals(optionsDict.exposureMode, | |
79 meteringModeNames[theMock.options().exposure_mode], | |
80 'exposureMode value'); | |
81 assert_equals(true, theMock.options().has_exposure_compensation, | |
82 'has_exposure_compensation must be true'); | |
83 assert_equals(optionsDict.exposureCompensation, | |
84 theMock.options().exposure_compensation, | |
85 'exposure_compensation value'); | |
86 assert_equals(true, theMock.options().has_white_balance_mode, 'has_white_b
alance_mode must be true'); | |
87 assert_equals(optionsDict.whiteBalanceMode, | |
88 meteringModeNames[theMock.options().white_balance_mode], | |
89 'whiteBalanceMode value'); | |
90 assert_equals(true, theMock.options().has_iso, 'has_iso must be true'); | |
91 assert_equals(optionsDict.iso, theMock.options().iso, 'iso value'); | |
92 assert_equals(true, theMock.options().has_red_eye_reduction, | |
93 'has_red_eye_reduction must be true'); | |
94 // Depending on how mojo boolean packing in integers is arranged, this can | 46 // Depending on how mojo boolean packing in integers is arranged, this can |
95 // be a number instead of a boolean, compare directly. | 47 // be a number instead of a boolean, compare directly. |
96 // TODO(mcasas): Revert to assert_equals() when yzshen@ has sorted it out. | 48 // TODO(mcasas): Revert to assert_equals() when yzshen@ has sorted it out. |
97 assert_true(optionsDict.redEyeReduction == theMock.options().red_eye_reduc
tion, | 49 assert_true( |
98 'red_eye_reduction value'); | 50 optionsDict.redEyeReduction == theMock.options().red_eye_reduction, |
99 assert_equals(true, theMock.options().has_fill_light_mode, 'has_fill_light
_mode must be true'); | 51 'red_eye_reduction'); |
| 52 |
| 53 assert_equals(true, theMock.options().has_fill_light_mode, |
| 54 'has_fill_light_mode'); |
100 assert_equals(optionsDict.fillLightMode, | 55 assert_equals(optionsDict.fillLightMode, |
101 fillLightModeNames[theMock.options().fill_light_mode], | 56 fillLightModeNames[theMock.options().fill_light_mode], |
102 'fillLightMode value'); | 57 'fillLightMode'); |
103 assert_true(theMock.options().has_color_temperature, | |
104 'has_color_temperature must be true'); | |
105 assert_equals(optionsDict.colorTemperature, | |
106 theMock.options().color_temperature, | |
107 'colorTemperature value'); | |
108 | 58 |
109 t.done(); | 59 t.done(); |
110 }) | 60 }) |
111 .catch(error => { | 61 .catch(error => { |
112 assert_unreached("Error during setOptions(): " + error.message); | 62 assert_unreached("Error during setOptions(): " + error.message); |
113 }); | 63 }); |
114 }, 'exercises ImageCapture.setOptions(options)'); | 64 }, 'exercises ImageCapture.setOptions(options)'); |
115 | 65 |
116 </script> | 66 </script> |
OLD | NEW |