|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test for CameraParameters we need to fake</title> |
|
5 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> |
|
6 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
7 <script type="text/javascript" src="camera_common.js"></script> |
|
8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
9 </head> |
|
10 <body> |
|
11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=976802">Mozilla Bug 976802</a> |
|
12 <video id="viewfinder" width="200" height="200" autoplay></video> |
|
13 <img src="#" alt="This image is going to load" id="testimage"/> |
|
14 |
|
15 <script class="testbody" type="text/javascript;version=1.7"> |
|
16 |
|
17 var whichCamera = navigator.mozCameras.getListOfCameras()[0]; |
|
18 var initialConfig = { |
|
19 mode: 'picture', |
|
20 recorderProfile: 'cif', |
|
21 previewSize: { |
|
22 width: 352, |
|
23 height: 288 |
|
24 } |
|
25 }; |
|
26 |
|
27 var cameraObj = null; |
|
28 |
|
29 // Shorthand functions |
|
30 function onError(e) { |
|
31 ok(false, "Error" + JSON.stringify(e)); |
|
32 } |
|
33 |
|
34 function end() { |
|
35 CameraTest.end(); |
|
36 } |
|
37 function next() { |
|
38 if (cameraObj) { |
|
39 cameraObj.release( |
|
40 function success() { |
|
41 CameraTest.next(); |
|
42 }, |
|
43 onError |
|
44 ); |
|
45 cameraObj = null; |
|
46 } else { |
|
47 CameraTest.next(); |
|
48 } |
|
49 } |
|
50 function run() { |
|
51 CameraTest.run(); |
|
52 } |
|
53 |
|
54 // The array of tests. Because camera capabilities don't change over the life |
|
55 // of a CameraControl object, they are only read once when the CameraControl is |
|
56 // created; so we have to call the 'prep' function first to set the fake |
|
57 // capability pref, before we call getCamera() and call 'test' to run the test. |
|
58 var tests = [ |
|
59 { |
|
60 key: "fake-zoom", |
|
61 prep: function setupFakeZoom(test) { |
|
62 test.setFakeParameters("zoom-ratios=100,150,200,300,400;max-zoom=4", function() { |
|
63 run(); |
|
64 }); |
|
65 }, |
|
66 test: function testFakeZoom(cam, cap) { |
|
67 ok(cap.zoomRatios.length == 5, "zoom ratios length = " + cap.zoomRatios.length); |
|
68 |
|
69 // test individual zoom ratios |
|
70 cap.zoomRatios.forEach(function(zoom, index) { |
|
71 cam.zoom = zoom; |
|
72 ok(cam.zoom === zoom, |
|
73 "zoom[" + index + "] = " + zoom + "x, cam.zoom = " + cam.zoom + "x"); |
|
74 }); |
|
75 |
|
76 // test below-lower-bound zoom ratio |
|
77 var zoom = cap.zoomRatios[0] - 0.1; |
|
78 cam.zoom = zoom; |
|
79 ok(cam.zoom === cap.zoomRatios[0], |
|
80 zoom + "x zoom clamps to minimum: " + |
|
81 cap.zoomRatios[0] + "x, cam.zoom = " + cam.zoom + "x"); |
|
82 |
|
83 // test above-upper-bound zoom ratio |
|
84 zoom = cap.zoomRatios.slice(-1)[0] + 1.0; |
|
85 cam.zoom = zoom; |
|
86 ok(cam.zoom === cap.zoomRatios.slice(-1)[0], |
|
87 zoom + "x zoom clamps to maximum: " + cap.zoomRatios.slice(-1)[0] + |
|
88 "x, cam.zoom = " + cam.zoom + "x"); |
|
89 |
|
90 // test snapping to supported zoom ratio |
|
91 if (cap.zoomRatios.length > 1) { |
|
92 zoom = (cap.zoomRatios[0] + cap.zoomRatios[1]) / 2; |
|
93 cam.zoom = zoom; |
|
94 ok(cam.zoom === cap.zoomRatios[0], |
|
95 zoom + "x zoom rounded down to: " + cap.zoomRatios[0] + |
|
96 "x, cam.zoom = " + cam.zoom + "x"); |
|
97 } |
|
98 |
|
99 next(); |
|
100 } |
|
101 }, |
|
102 { |
|
103 key: "fake-zoom-out-of-order", |
|
104 prep: function setupFakeZoomOutOfOrder(test) { |
|
105 // We expect the camera library to give us zoom ratios in order; if |
|
106 // it doesn't we ignore the list and just return 1x support. |
|
107 test.setFakeParameters("zoom-ratios=100,150,200,400,300;max-zoom=4", function () { |
|
108 run(); |
|
109 }); |
|
110 }, |
|
111 test: function testFakeZoomOutOfOrder(cam, cap) { |
|
112 ok(cap.zoomRatios.length == 1, "zoom ratios length = " + cap.zoomRatios.length); |
|
113 ok(cap.zoomRatios[0] == 1.0, "only supported zoom = " + cap.zoomRatios[0] + "x"); |
|
114 next(); |
|
115 } |
|
116 }, |
|
117 { |
|
118 key: "fake-iso", |
|
119 prep: function setupFakeIso(test) { |
|
120 // we should recognize 'auto', 'hjr', and numeric modes; anything else |
|
121 // from the driver is ignored, which this test also verifies. |
|
122 test.setFakeParameters( |
|
123 "iso=auto;iso-values=auto,ISO_HJR,ISO100,foo,ISObar,ISO200,ISO400,ISO800,ISO1600", |
|
124 function () { |
|
125 run(); |
|
126 }); |
|
127 }, |
|
128 test: function testFakeIso(cam, cap) { |
|
129 // values 'foo' and 'ISObar' should not be included in isoModes |
|
130 ok(cap.isoModes.length == 7, "ISO modes length = " + cap.isoModes.length); |
|
131 ok(cap.isoModes.indexOf("foo") == -1, "Unknown ISO mode 'foo' is ignored"); |
|
132 ok(cap.isoModes.indexOf("ISObar") == -1, "Unknown ISO mode 'ISObar' is ignored"); |
|
133 ok(cap.isoModes.indexOf("bar") == -1, "Unknown ISO mode 'bar' is ignored"); |
|
134 |
|
135 // test individual ISO modes |
|
136 cap.isoModes.forEach(function(iso, index) { |
|
137 cam.iso = iso; |
|
138 ok(cam.iso === iso, |
|
139 "ISO[" + index + "] = " + iso + ", cam.iso = " + cam.iso); |
|
140 }); |
|
141 |
|
142 next(); |
|
143 } |
|
144 }, |
|
145 ]; |
|
146 |
|
147 var testGenerator = function() { |
|
148 for (var i = 0; i < tests.length; ++i ) { |
|
149 yield tests[i]; |
|
150 } |
|
151 }(); |
|
152 |
|
153 window.addEventListener('beforeunload', function() { |
|
154 document.getElementById('viewfinder').mozSrcObject = null; |
|
155 if (cameraObj) { |
|
156 cameraObj.release(); |
|
157 cameraObj = null; |
|
158 } |
|
159 }); |
|
160 |
|
161 CameraTest.begin("hardware", function(test) { |
|
162 function onError(error) { |
|
163 ok(false, "getCamera() failed with: " + error); |
|
164 end(); |
|
165 } |
|
166 |
|
167 CameraTest.next = function() { |
|
168 try { |
|
169 var t = testGenerator.next(); |
|
170 info("test: " + t.key); |
|
171 function onSuccess(camera, config) { |
|
172 cameraObj = camera; |
|
173 document.getElementById('viewfinder').mozSrcObject = camera; |
|
174 camera.onPreviewStateChange = function (state) { |
|
175 if (state === "started") { |
|
176 t.test(camera, camera.capabilities); |
|
177 } else { |
|
178 ok(false, "preview started (state = '" + state + "')"); |
|
179 } |
|
180 camera.onPreviewStateChange = null; |
|
181 }; |
|
182 } |
|
183 CameraTest.run = function() { |
|
184 navigator.mozCameras.getCamera(whichCamera, initialConfig, onSuccess, onError); |
|
185 }; |
|
186 t.prep(test); |
|
187 } catch(e) { |
|
188 if (e instanceof StopIteration) { |
|
189 end(); |
|
190 } else { |
|
191 throw e; |
|
192 } |
|
193 } |
|
194 }; |
|
195 next(); |
|
196 }); |
|
197 |
|
198 </script> |
|
199 </body> |
|
200 |
|
201 </html> |