|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test for mozCameras.getCamera() with separate .setConfiguration() call</title> |
|
5 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> |
|
6 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
8 </head> |
|
9 <body> |
|
10 <video id="viewfinder" width="200" height="200" autoplay></video> |
|
11 <img src="#" alt="This image is going to load" id="testimage"/> |
|
12 <script class="testbody" type="text/javascript;version=1.7"> |
|
13 |
|
14 var whichCamera = navigator.mozCameras.getListOfCameras()[0]; |
|
15 var options = { |
|
16 mode: 'picture', |
|
17 recorderProfile: 'cif', |
|
18 previewSize: { |
|
19 width: 352, |
|
20 height: 288 |
|
21 } |
|
22 }; |
|
23 |
|
24 var config = { |
|
25 dateTime: Date.now() / 1000, |
|
26 pictureSize: null, |
|
27 fileFormat: 'jpeg', |
|
28 rotation: 90 |
|
29 }; |
|
30 |
|
31 function onError(e) { |
|
32 ok(false, "Error" + JSON.stringify(e)); |
|
33 } |
|
34 |
|
35 var capabilities = [ 'previewSizes', 'pictureSizes', 'fileFormats', 'maxFocusAreas', 'minExposureCompensation', |
|
36 'maxExposureCompensation', 'stepExposureCompensation', 'maxMeteringAreas', 'videoSizes', |
|
37 'recorderProfiles', 'zoomRatios', 'isoModes']; |
|
38 |
|
39 var Camera = { |
|
40 cameraObj: null, |
|
41 _recording: false, |
|
42 _currentTest: null, |
|
43 _autoFocusSupported: 0, |
|
44 _manuallyFocused: false, |
|
45 _flashmodes: null, |
|
46 _pictureSizes: null, |
|
47 _previewSizes: null, |
|
48 _whiteBalanceModes: null, |
|
49 _zoomRatios: null, |
|
50 _sceneModes: null, |
|
51 _focusModes: null, |
|
52 _zoomRatios: null, |
|
53 _testsCompleted: 0, |
|
54 _shutter: 0, |
|
55 _config: { |
|
56 dateTime: Date.now() / 1000, |
|
57 pictureSize: null, |
|
58 fileFormat: 'jpeg', |
|
59 rotation: 90 |
|
60 }, |
|
61 _tests: null, |
|
62 get viewfinder() { |
|
63 return document.getElementById('viewfinder'); |
|
64 }, |
|
65 setFlashMode: function camera_setFlash(mode) { |
|
66 this.cameraObj.flashMode = mode; |
|
67 }, |
|
68 setFocus: function camera_setfocus(mode) { |
|
69 this.cameraObj.focus = mode; |
|
70 }, |
|
71 setZoom: function camera_setZoom(zoom) { |
|
72 this.cameraObj.zoom = zoom; |
|
73 }, |
|
74 getZoom: function camera_getZoom() { |
|
75 return this.cameraObj.zoom; |
|
76 }, |
|
77 getFileFormats: function camera_formats() { |
|
78 this._fileFormats = this.cameraObj.capabilities.fileFormats; |
|
79 }, |
|
80 getFlashModes: function camera_getFlash() { |
|
81 this._flashmodes = this.cameraObj.capabilities.flashModes; |
|
82 }, |
|
83 getFocusModes: function camera_getFocus() { |
|
84 this._focusModes = this.cameraObj.capabilities.focusModes; |
|
85 }, |
|
86 getSceneModes: function camera_getScene() { |
|
87 this._sceneModes = this.cameraObj.capabilities.sceneModes; |
|
88 }, |
|
89 getZoomRatios: function camera_getZoom() { |
|
90 this._zoomRatios = this.cameraObj.capabilities.zoomRatios; |
|
91 }, |
|
92 getWhiteBalance: function camera_white() { |
|
93 this._whitebalanceModes = this.cameraObj.capabilities.whiteBalanceModes; |
|
94 }, |
|
95 getPictureSizes: function camera_sizes() { |
|
96 this._pictureSizes = this.cameraObj.capabilities.pictureSizes; |
|
97 }, |
|
98 getPreviewSizes: function camera_preview() { |
|
99 this._previewSizes = this.cameraObj.capabilities.previewSizes; |
|
100 }, |
|
101 getZoomRatios: function camera_preview() { |
|
102 this._zoomRatios = this.cameraObj.capabilities.zoomRatios; |
|
103 }, |
|
104 takePictureSuccess: function taken_foto(blob) { |
|
105 var img = new Image(); |
|
106 var test = this._currentTest; |
|
107 img.onload = function Imgsize() { |
|
108 ok(this.width == test.pictureSize.width, "The image taken has the width " + |
|
109 this.width + " pictureSize width = " + test.pictureSize.width); |
|
110 ok(this.height == test.pictureSize.height, "The image taken has the height " + |
|
111 this.height + " picturesize height = " + test.pictureSize.height); |
|
112 Camera._testsCompleted++; |
|
113 if(Camera._testsCompleted == Camera._tests.length) { |
|
114 ok(true, "test finishing"); |
|
115 SimpleTest.finish(); |
|
116 } else { |
|
117 Camera.runTests(); |
|
118 } |
|
119 } |
|
120 ok(blob.size > 100 , "Blob Size Gathered = " + blob.size); |
|
121 ok("image/" + test.fileFormat == blob.type, "Blob Type = " + blob.type); |
|
122 img.src = window.URL.createObjectURL(blob); |
|
123 }, |
|
124 shutter: function onShutter () { |
|
125 Camera._shutter++; |
|
126 |
|
127 ok(Camera._shutter == (Camera._testsCompleted + 1), "on Shutter has been called " + |
|
128 Camera._shutter + " times"); |
|
129 |
|
130 }, |
|
131 onReady: function onReady() { |
|
132 var camcap = Camera.cameraObj.capabilities; |
|
133 var tests = {}; |
|
134 for (var prop in capabilities) { |
|
135 prop = capabilities[prop]; |
|
136 ok(camcap[prop] || isFinite(camcap[prop]) || camcap[prop] == null, "Camera Capability: " + |
|
137 prop + " is exposed, value = " + JSON.stringify(camcap[prop])); |
|
138 } |
|
139 ok(camcap.maxMeteringAreas >= 0, "maxMeteringAreas = " + camcap.maxMeteringAreas); |
|
140 ok(camcap.maxFocusAreas >= 0, "maxFocusAreas = " + camcap.maxFocusAreas); |
|
141 for (var prop in camcap) { |
|
142 if(camcap[prop] && camcap[prop].length > 1) { |
|
143 tests[prop] = camcap[prop]; |
|
144 } |
|
145 } |
|
146 Camera.getPictureSizes(); |
|
147 Camera.getPreviewSizes(); |
|
148 Camera.getFileFormats(); |
|
149 Camera.getFocusModes(); |
|
150 Camera.getZoomRatios(); |
|
151 ok(Camera._previewSizes.length > 0, "previewSizes length = " + Camera._previewSizes.length); |
|
152 ok(Camera._pictureSizes.length > 0, "picturesizes length = " + Camera._pictureSizes.length); |
|
153 ok(Camera._fileFormats.length > 0, "file formats length = " + Camera._fileFormats.length); |
|
154 ok(camcap.isoModes.length == 0, "ISO modes length = " + camcap.isoModes.length); |
|
155 |
|
156 // The emulator doesn't support zoom, so these parameters will be very constrained |
|
157 // For more ambitious tests, see test_camera_fake_parameters.html |
|
158 ok(Camera._zoomRatios.length == 1, "zoom ratios length = " + Camera._zoomRatios.length); |
|
159 ok(Camera.cameraObj.zoom == 1.0, "zoom = " + Camera.cameraObj.zoom); |
|
160 // Test snapping to supported values |
|
161 Camera.cameraObj.zoom = 0.9; |
|
162 ok(Camera.cameraObj.zoom == 1.0, "zoom = " + Camera.cameraObj.zoom); |
|
163 Camera.cameraObj.zoom = 1.1; |
|
164 ok(Camera.cameraObj.zoom == 1.0, "zoom = " + Camera.cameraObj.zoom); |
|
165 |
|
166 Camera._tests = new Array(); |
|
167 for (var i in Camera._pictureSizes) { |
|
168 for (var l in Camera._fileFormats) { |
|
169 var config = { |
|
170 pictureSize: Camera._pictureSizes[i], |
|
171 fileFormat: Camera._fileFormats[l] |
|
172 }; |
|
173 Camera._tests.push(config); |
|
174 } |
|
175 } |
|
176 Camera.runTests(); |
|
177 }, |
|
178 runTests: function run_tests() { |
|
179 var test = this._tests[this._testsCompleted]; |
|
180 this._currentTest = test; |
|
181 Camera.setFlashMode(test.flashMode); |
|
182 config.fileFormat = test.fileFormat; |
|
183 config.pictureSize = test.pictureSize; |
|
184 ok(true, "testing picture size " + JSON.stringify(config.pictureSize)); |
|
185 Camera.cameraObj.takePicture(config, this.takePictureSuccess.bind(this), onError); |
|
186 }, |
|
187 onConfigChange: function onConfigChange(config) { |
|
188 ok(config.mode === options.mode, "configuration mode = " + config.mode); |
|
189 ok(config.recorderProfile === options.recorderProfile, "recorder profile = " + config.recorderProfile); |
|
190 ok(config.previewSize.width === options.previewSize.width && |
|
191 config.previewSize.height === options.previewSize.height, |
|
192 "preview size (w x h) = " + config.previewSize.width + " x " + config.previewSize.height); |
|
193 }, |
|
194 setUp: function setup_tests() { |
|
195 function onSuccess(camera) { |
|
196 Camera.cameraObj = camera; |
|
197 Camera.viewfinder.mozSrcObject = camera; |
|
198 Camera.viewfinder.play(); |
|
199 Camera.cameraObj.onPreviewStateChange = function(state) { |
|
200 if (state === 'started') { |
|
201 ok(true, "viewfinder is ready and playing"); |
|
202 Camera.cameraObj.onPreviewStateChange = null; |
|
203 Camera.onReady(); |
|
204 } |
|
205 }; |
|
206 SimpleTest.expectAssertions(0); |
|
207 ok(true, "Camera Control object has been successfully initialized"); |
|
208 Camera.cameraObj.setConfiguration(options, Camera.onConfigChange, onError); |
|
209 Camera.cameraObj.onShutter = Camera.shutter; |
|
210 }; |
|
211 navigator.mozCameras.getCamera(whichCamera, null, onSuccess, onError); |
|
212 } |
|
213 } |
|
214 |
|
215 SimpleTest.waitForExplicitFinish(); |
|
216 |
|
217 window.addEventListener('beforeunload', function() { |
|
218 Camera.viewfinder.mozSrcObject = null; |
|
219 Camera.cameraObj.release(); |
|
220 Camera.cameraObj = null; |
|
221 }); |
|
222 |
|
223 Camera.setUp(); |
|
224 |
|
225 </script> |
|
226 </body> |
|
227 |
|
228 </html> |