|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=940424 |
|
5 --> |
|
6 <head> |
|
7 <title>Bug 940424 - Test camera hardware API failure handling</title> |
|
8 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> |
|
9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
10 <script type="text/javascript" src="camera_common.js"></script> |
|
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
12 </head> |
|
13 <body> |
|
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=940424">Mozilla Bug 940424</a> |
|
15 <video id="viewfinder" width = "200" height = "200" autoplay></video> |
|
16 <img src="#" alt="This image is going to load" id="testimage"/> |
|
17 |
|
18 <script class="testbody" type="text/javascript;version=1.7"> |
|
19 |
|
20 var whichCamera = navigator.mozCameras.getListOfCameras()[0]; |
|
21 var initialConfig = { |
|
22 mode: 'picture', |
|
23 recorderProfile: 'cif', |
|
24 previewSize: { |
|
25 width: 352, |
|
26 height: 288 |
|
27 } |
|
28 }; |
|
29 |
|
30 var cameraObj; |
|
31 |
|
32 // Shorthand functions |
|
33 function end() { |
|
34 CameraTest.end(); |
|
35 } |
|
36 function next() { |
|
37 CameraTest.next(); |
|
38 } |
|
39 |
|
40 // The array of tests |
|
41 var tests = [ |
|
42 { |
|
43 key: "auto-focus-failure", |
|
44 func: function testAutoFocusApiFailure(camera) { |
|
45 function onSuccess(success) { |
|
46 ok(false, "autoFocus() succeeded incorrectly"); |
|
47 end(); |
|
48 } |
|
49 function onError(error) { |
|
50 ok(true, "autoFocus() failed correctly with: " + error); |
|
51 next(); |
|
52 } |
|
53 camera.autoFocus(onSuccess, onError); |
|
54 } |
|
55 }, |
|
56 { |
|
57 key: "auto-focus-process-failure", |
|
58 func: function testAutoFocusProcessFailure(camera) { |
|
59 function onSuccess(success) { |
|
60 if (success) { |
|
61 ok(false, "autoFocus() process succeeded incorrectly"); |
|
62 end(); |
|
63 } else { |
|
64 ok(true, "autoFocus() process failed correctly"); |
|
65 next(); |
|
66 } |
|
67 } |
|
68 function onError(error) { |
|
69 ok(false, "autoFocus() process failed incorrectly with: " + error); |
|
70 end(); |
|
71 } |
|
72 camera.autoFocus(onSuccess, onError); |
|
73 } |
|
74 }, |
|
75 { |
|
76 key: "take-picture-failure", |
|
77 func: function testTakePictureApiFailure(camera) { |
|
78 function onSuccess(picture) { |
|
79 ok(false, "takePicture() succeeded incorrectly"); |
|
80 end(); |
|
81 } |
|
82 function onError(error) { |
|
83 ok(true, "takePicture() failed correctly with: " + error); |
|
84 next(); |
|
85 } |
|
86 camera.takePicture(null, onSuccess, onError); |
|
87 } |
|
88 }, |
|
89 { |
|
90 key: "take-picture-process-failure", |
|
91 func: function testTakePictureProcessFailure(camera) { |
|
92 function onSuccess(picture) { |
|
93 ok(false, "takePicture() process succeeded incorrectly"); |
|
94 end(); |
|
95 } |
|
96 function onError(error) { |
|
97 ok(true, "takePicture() process failed correctly with: " + error); |
|
98 next(); |
|
99 } |
|
100 camera.takePicture(null, onSuccess, onError); |
|
101 } |
|
102 }, |
|
103 ]; |
|
104 |
|
105 var testGenerator = function() { |
|
106 for (var i = 0; i < tests.length; ++i ) { |
|
107 yield tests[i]; |
|
108 } |
|
109 }(); |
|
110 |
|
111 window.addEventListener('beforeunload', function() { |
|
112 document.getElementById('viewfinder').mozSrcObject = null; |
|
113 cameraObj.release(); |
|
114 cameraObj = null; |
|
115 }); |
|
116 |
|
117 CameraTest.begin("hardware", function(test) { |
|
118 function onSuccess(camera, config) { |
|
119 document.getElementById('viewfinder').mozSrcObject = camera; |
|
120 cameraObj = camera; |
|
121 CameraTest.next = function() { |
|
122 try { |
|
123 var t = testGenerator.next(); |
|
124 test.set(t.key, t.func.bind(undefined, camera)); |
|
125 } catch(e) { |
|
126 if (e instanceof StopIteration) { |
|
127 end(); |
|
128 } else { |
|
129 throw e; |
|
130 } |
|
131 } |
|
132 }; |
|
133 next(); |
|
134 } |
|
135 function onError(error) { |
|
136 ok(false, "getCamera() failed with: " + error); |
|
137 end(); |
|
138 } |
|
139 navigator.mozCameras.getCamera(whichCamera, initialConfig, onSuccess, onError); |
|
140 }); |
|
141 |
|
142 </script> |
|
143 </body> |
|
144 |
|
145 </html> |