|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test for mozCameras.getCamera() using an initial configuration</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']; |
|
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 _testsCompleted: 0, |
|
53 _shutter: 0, |
|
54 _config: { |
|
55 dateTime: Date.now() / 1000, |
|
56 pictureSize: null, |
|
57 fileFormat: 'jpeg', |
|
58 rotation: 90 |
|
59 }, |
|
60 _tests: null, |
|
61 get viewfinder() { |
|
62 return document.getElementById('viewfinder'); |
|
63 }, |
|
64 setFlashMode: function camera_setFlash(mode) { |
|
65 this.cameraObj.flashMode = mode; |
|
66 }, |
|
67 setFocus: function camera_setfocus(mode) { |
|
68 this.cameraObj.focus = mode; |
|
69 }, |
|
70 getFileFormats: function camera_formats() { |
|
71 this._fileFormats = this.cameraObj.capabilities.fileFormats; |
|
72 }, |
|
73 getFlashModes: function camera_getFlash() { |
|
74 this._flashmodes = this.cameraObj.capabilities.flashModes; |
|
75 }, |
|
76 getFocusModes: function camera_getFocus() { |
|
77 this._focusModes = this.cameraObj.capabilities.focusModes; |
|
78 }, |
|
79 getSceneModes: function camera_getScene() { |
|
80 this._sceneModes = this.cameraObj.capabilities.sceneModes; |
|
81 }, |
|
82 getZoomRatios: function camera_getZoom() { |
|
83 this._zoomRatios = this.cameraObj.capabilities.zoomRatios; |
|
84 }, |
|
85 getWhiteBalance: function camera_white() { |
|
86 this._whitebalanceModes = this.cameraObj.capabilities.whiteBalanceModes; |
|
87 }, |
|
88 getPictureSizes: function camera_sizes() { |
|
89 this._pictureSizes = this.cameraObj.capabilities.pictureSizes; |
|
90 }, |
|
91 getPreviewSizes: function camera_preview() { |
|
92 this._previewSizes = this.cameraObj.capabilities.previewSizes; |
|
93 }, |
|
94 takePictureSuccess: function taken_foto(blob) { |
|
95 var img = new Image(); |
|
96 var test = this._currentTest; |
|
97 img.onload = function Imgsize() { |
|
98 ok(this.width == test.pictureSize.width, "The image taken has the width " + |
|
99 this.width + " pictureSize width = " + test.pictureSize.width); |
|
100 ok(this.height == test.pictureSize.height, "The image taken has the height " + |
|
101 this.height + " picturesize height = " + test.pictureSize.height); |
|
102 Camera._testsCompleted++; |
|
103 if(Camera._testsCompleted == Camera._tests.length) { |
|
104 ok(true, "test finishing"); |
|
105 SimpleTest.finish(); |
|
106 } else { |
|
107 Camera.runTests(); |
|
108 } |
|
109 } |
|
110 ok(blob.size > 100 , "Blob Size Gathered = " + blob.size); |
|
111 ok("image/" + test.fileFormat == blob.type, "Blob Type = " + blob.type); |
|
112 img.src = window.URL.createObjectURL(blob); |
|
113 }, |
|
114 shutter: function onShutter () { |
|
115 Camera._shutter++; |
|
116 |
|
117 ok(Camera._shutter == (Camera._testsCompleted + 1), "on Shutter has been called " + |
|
118 Camera._shutter + " times"); |
|
119 |
|
120 }, |
|
121 onReady: function onReady() { |
|
122 var camcap = Camera.cameraObj.capabilities; |
|
123 var tests = {}; |
|
124 for (var prop in capabilities) { |
|
125 prop = capabilities[prop]; |
|
126 ok(camcap[prop] || isFinite(camcap[prop]) || camcap[prop] == null, "Camera Capability: " + |
|
127 prop + " is exposed, value = " + JSON.stringify(camcap[prop])); |
|
128 } |
|
129 for (var prop in camcap) { |
|
130 if(camcap[prop] && camcap[prop].length > 1) { |
|
131 tests[prop] = camcap[prop]; |
|
132 } |
|
133 } |
|
134 Camera.getPictureSizes(); |
|
135 Camera.getPreviewSizes(); |
|
136 Camera.getFileFormats(); |
|
137 Camera.getFocusModes(); |
|
138 ok(Camera._previewSizes.length > 0, "previewSizes length = " + Camera._previewSizes.length); |
|
139 ok(Camera._pictureSizes.length > 0, "picturesizes length = " + Camera._pictureSizes.length); |
|
140 ok(Camera._fileFormats.length > 0, "file formats length = " + Camera._fileFormats.length); |
|
141 Camera._tests = new Array(); |
|
142 for (var i in Camera._pictureSizes) { |
|
143 for (var l in Camera._fileFormats) { |
|
144 var config = { |
|
145 pictureSize: Camera._pictureSizes[i], |
|
146 fileFormat: Camera._fileFormats[l] |
|
147 }; |
|
148 Camera._tests.push(config); |
|
149 } |
|
150 } |
|
151 Camera.runTests(); |
|
152 }, |
|
153 runTests: function run_tests() { |
|
154 var test = this._tests[this._testsCompleted]; |
|
155 this._currentTest = test; |
|
156 Camera.setFlashMode(test.flashMode); |
|
157 config.fileFormat = test.fileFormat; |
|
158 config.pictureSize = test.pictureSize; |
|
159 ok(true, "testing picture size " + JSON.stringify(config.pictureSize)); |
|
160 Camera.cameraObj.takePicture(config, this.takePictureSuccess.bind(this), onError); |
|
161 }, |
|
162 setUp: function setup_tests() { |
|
163 function onSuccess(camera, config) { |
|
164 ok(true, "Camera Control object has been successfully initialized"); |
|
165 ok(config.mode === options.mode, "configuration mode = " + config.mode); |
|
166 ok(config.recorderProfile === options.recorderProfile, "recorder profile = " + config.recorderProfile); |
|
167 ok(config.previewSize.width === options.previewSize.width && |
|
168 config.previewSize.height === options.previewSize.height, |
|
169 "preview size (w x h) = " + config.previewSize.width + " x " + config.previewSize.height); |
|
170 Camera.cameraObj = camera; |
|
171 Camera.viewfinder.mozSrcObject = camera; |
|
172 Camera.viewfinder.play(); |
|
173 Camera.cameraObj.onPreviewStateChange = function(state) { |
|
174 if (state === 'started') { |
|
175 ok(true, "viewfinder is ready and playing"); |
|
176 Camera.cameraObj.onPreviewStateChange = null; |
|
177 Camera.onReady(); |
|
178 } |
|
179 }; |
|
180 SimpleTest.expectAssertions(0); |
|
181 Camera.cameraObj.onShutter = Camera.shutter; |
|
182 }; |
|
183 navigator.mozCameras.getCamera(whichCamera, options, onSuccess, onError); |
|
184 } |
|
185 } |
|
186 |
|
187 SimpleTest.waitForExplicitFinish(); |
|
188 |
|
189 window.addEventListener('beforeunload', function() { |
|
190 Camera.viewfinder.mozSrcObject = null; |
|
191 Camera.cameraObj.release(); |
|
192 Camera.cameraObj = null; |
|
193 }); |
|
194 |
|
195 Camera.setUp(); |
|
196 |
|
197 </script> |
|
198 </body> |
|
199 |
|
200 </html> |