dom/camera/test/test_bug975472.html

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:cc782cd0f783
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Test for bug 975472</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 config = {
16 mode: 'picture',
17 recorderProfile: 'cif',
18 previewSize: {
19 width: 352,
20 height: 288
21 }
22 };
23 var options = {
24 rotation: 0,
25 position: {
26 latitude: 43.645687,
27 longitude: -79.393661
28 },
29 dateTime: Date.now()
30 };
31
32 function onError(e) {
33 ok(false, "Error" + JSON.stringify(e));
34 }
35 function next() {
36 Camera.nextTest();
37 }
38
39 // The array of tests
40 var tests = [
41 {
42 key: "release-after-release",
43 func: function testAutoFocus(camera) {
44 function onSuccess(success) {
45 ok(true, "release() succeeded");
46 next();
47 }
48 function onError(error) {
49 ok(false, "release() failed with: " + error);
50 }
51 camera.release(onSuccess, onError);
52 }
53 },
54 {
55 key: "set-picture-size-after-release",
56 func: function testSetPictureSize(camera) {
57 camera.pictureSize = { width: 0, height: 0 };
58 next();
59 }
60 },
61 {
62 key: "set-thumbnail-size-after-release",
63 func: function testSetThumbnailSize(camera) {
64 camera.thumbnailSize = { width: 0, height: 0 };
65 next();
66 }
67 },
68 {
69 key: "get-sensor-angle-after-release",
70 func: function testGetSensorAngle(camera) {
71 ok(camera.sensorAngle == 0, "camera.sensorAngle = " + camera.sensorAngle);
72 next();
73 }
74 },
75 {
76 key: "resume-preview-after-release",
77 func: function testResumePreview(camera) {
78 camera.resumePreview();
79 next();
80 }
81 },
82 {
83 key: "auto-focus-after-release",
84 func: function testAutoFocus(camera) {
85 function onSuccess(success) {
86 ok(false, "autoFocus() succeeded incorrectly");
87 }
88 function onError(error) {
89 ok(true, "autoFocus() failed correctly with: " + error);
90 next();
91 }
92 camera.autoFocus(onSuccess, onError);
93 }
94 },
95 {
96 key: "take-picture-after-release",
97 func: function testTakePicture(camera) {
98 function onSuccess(picture) {
99 ok(false, "takePicture() succeeded incorrectly");
100 }
101 function onError(error) {
102 ok(true, "takePicture() failed correctly with: " + error);
103 next();
104 }
105 camera.takePicture(null, onSuccess, onError);
106 }
107 },
108 {
109 key: "start-recording-after-release",
110 func: function testStartRecording(camera) {
111 function onSuccess(picture) {
112 ok(false, "startRecording() process succeeded incorrectly");
113 }
114 function onError(error) {
115 ok(true, "startRecording() process failed correctly with: " + error);
116 next();
117 }
118 var recordingOptions = {
119 profile: 'cif',
120 rotation: 0
121 };
122 camera.startRecording(recordingOptions,
123 navigator.getDeviceStorage('videos'),
124 'bug975472.mp4',
125 onSuccess, onError);
126 }
127 },
128 {
129 key: "stop-recording-after-release",
130 func: function testStopRecording(camera) {
131 camera.stopRecording();
132 next();
133 }
134 },
135 {
136 key: "set-configuration-after-release",
137 func: function testSetConfiguration(camera) {
138 function onSuccess(picture) {
139 ok(false, "setConfiguration() process succeeded incorrectly");
140 }
141 function onError(error) {
142 ok(true, "setConfiguration() process failed correctly with: " + error);
143 next();
144 }
145 camera.setConfiguration(config, onSuccess, onError);
146 }
147 },
148 ];
149
150 var testGenerator = function() {
151 for (var i = 0; i < tests.length; ++i ) {
152 yield tests[i];
153 }
154 }();
155
156 var Camera = {
157 cameraObj: null,
158 _otherPictureSize: null,
159 get viewfinder() {
160 return document.getElementById('viewfinder');
161 },
162 onCameraReady: function () {
163 Camera.nextTest = function() {
164 try {
165 var t = testGenerator.next();
166 info("test: " + t.key);
167 t.func(Camera.cameraObj);
168 } catch(e) {
169 if (e instanceof StopIteration) {
170 SimpleTest.finish();
171 } else {
172 throw e;
173 }
174 }
175 };
176 // Release the camera hardware, and call all of the asynchronous methods
177 // to make sure they properly handle being in this state.
178 Camera.cameraObj.release();
179 next();
180 },
181 release: function release() {
182 cameraObj = null;
183 },
184 start: function run_test() {
185 function onSuccess(camera, config) {
186 Camera.cameraObj = camera;
187 Camera.viewfinder.mozSrcObject = camera;
188 Camera.viewfinder.play();
189 ok(camera.capabilities.pictureSizes.length > 0,
190 "capabilities.pictureSizes.length = " +
191 camera.capabilities.pictureSizes.length);
192 Camera._otherPictureSize = camera.capabilities.pictureSizes.slice(-1)[0];
193 camera.pictureSize = camera.capabilities.pictureSizes[0];
194 options.pictureSize = Camera._otherPictureSize;
195 options.fileFormat = camera.capabilities.fileFormats[0];
196 info("getCamera callback, setting pictureSize = " + options.pictureSize.toSource());
197 Camera.cameraObj.onPreviewStateChange = function(state) {
198 if (state === 'started') {
199 info("viewfinder is ready and playing");
200 Camera.cameraObj.onPreviewStateChange = null;
201 Camera.onCameraReady();
202 }
203 };
204 };
205 navigator.mozCameras.getCamera(whichCamera, config, onSuccess, onError);
206 }
207 }
208
209 SimpleTest.waitForExplicitFinish();
210
211 window.addEventListener('beforeunload', function() {
212 Camera.viewfinder.mozSrcObject = null;
213 Camera.cameraObj.release();
214 Camera.cameraObj = null;
215 });
216
217 Camera.start();
218
219 </script>
220 </body>
221
222 </html>

mercurial