1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/camera/test/test_camera_fake_parameters.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,201 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test for CameraParameters we need to fake</title> 1.8 + <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> 1.9 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.10 + <script type="text/javascript" src="camera_common.js"></script> 1.11 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.12 +</head> 1.13 +<body> 1.14 + <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=976802">Mozilla Bug 976802</a> 1.15 + <video id="viewfinder" width="200" height="200" autoplay></video> 1.16 + <img src="#" alt="This image is going to load" id="testimage"/> 1.17 + 1.18 +<script class="testbody" type="text/javascript;version=1.7"> 1.19 + 1.20 +var whichCamera = navigator.mozCameras.getListOfCameras()[0]; 1.21 +var initialConfig = { 1.22 + mode: 'picture', 1.23 + recorderProfile: 'cif', 1.24 + previewSize: { 1.25 + width: 352, 1.26 + height: 288 1.27 + } 1.28 +}; 1.29 + 1.30 +var cameraObj = null; 1.31 + 1.32 +// Shorthand functions 1.33 +function onError(e) { 1.34 + ok(false, "Error" + JSON.stringify(e)); 1.35 +} 1.36 + 1.37 +function end() { 1.38 + CameraTest.end(); 1.39 +} 1.40 +function next() { 1.41 + if (cameraObj) { 1.42 + cameraObj.release( 1.43 + function success() { 1.44 + CameraTest.next(); 1.45 + }, 1.46 + onError 1.47 + ); 1.48 + cameraObj = null; 1.49 + } else { 1.50 + CameraTest.next(); 1.51 + } 1.52 +} 1.53 +function run() { 1.54 + CameraTest.run(); 1.55 +} 1.56 + 1.57 +// The array of tests. Because camera capabilities don't change over the life 1.58 +// of a CameraControl object, they are only read once when the CameraControl is 1.59 +// created; so we have to call the 'prep' function first to set the fake 1.60 +// capability pref, before we call getCamera() and call 'test' to run the test. 1.61 +var tests = [ 1.62 + { 1.63 + key: "fake-zoom", 1.64 + prep: function setupFakeZoom(test) { 1.65 + test.setFakeParameters("zoom-ratios=100,150,200,300,400;max-zoom=4", function() { 1.66 + run(); 1.67 + }); 1.68 + }, 1.69 + test: function testFakeZoom(cam, cap) { 1.70 + ok(cap.zoomRatios.length == 5, "zoom ratios length = " + cap.zoomRatios.length); 1.71 + 1.72 + // test individual zoom ratios 1.73 + cap.zoomRatios.forEach(function(zoom, index) { 1.74 + cam.zoom = zoom; 1.75 + ok(cam.zoom === zoom, 1.76 + "zoom[" + index + "] = " + zoom + "x, cam.zoom = " + cam.zoom + "x"); 1.77 + }); 1.78 + 1.79 + // test below-lower-bound zoom ratio 1.80 + var zoom = cap.zoomRatios[0] - 0.1; 1.81 + cam.zoom = zoom; 1.82 + ok(cam.zoom === cap.zoomRatios[0], 1.83 + zoom + "x zoom clamps to minimum: " + 1.84 + cap.zoomRatios[0] + "x, cam.zoom = " + cam.zoom + "x"); 1.85 + 1.86 + // test above-upper-bound zoom ratio 1.87 + zoom = cap.zoomRatios.slice(-1)[0] + 1.0; 1.88 + cam.zoom = zoom; 1.89 + ok(cam.zoom === cap.zoomRatios.slice(-1)[0], 1.90 + zoom + "x zoom clamps to maximum: " + cap.zoomRatios.slice(-1)[0] + 1.91 + "x, cam.zoom = " + cam.zoom + "x"); 1.92 + 1.93 + // test snapping to supported zoom ratio 1.94 + if (cap.zoomRatios.length > 1) { 1.95 + zoom = (cap.zoomRatios[0] + cap.zoomRatios[1]) / 2; 1.96 + cam.zoom = zoom; 1.97 + ok(cam.zoom === cap.zoomRatios[0], 1.98 + zoom + "x zoom rounded down to: " + cap.zoomRatios[0] + 1.99 + "x, cam.zoom = " + cam.zoom + "x"); 1.100 + } 1.101 + 1.102 + next(); 1.103 + } 1.104 + }, 1.105 + { 1.106 + key: "fake-zoom-out-of-order", 1.107 + prep: function setupFakeZoomOutOfOrder(test) { 1.108 + // We expect the camera library to give us zoom ratios in order; if 1.109 + // it doesn't we ignore the list and just return 1x support. 1.110 + test.setFakeParameters("zoom-ratios=100,150,200,400,300;max-zoom=4", function () { 1.111 + run(); 1.112 + }); 1.113 + }, 1.114 + test: function testFakeZoomOutOfOrder(cam, cap) { 1.115 + ok(cap.zoomRatios.length == 1, "zoom ratios length = " + cap.zoomRatios.length); 1.116 + ok(cap.zoomRatios[0] == 1.0, "only supported zoom = " + cap.zoomRatios[0] + "x"); 1.117 + next(); 1.118 + } 1.119 + }, 1.120 + { 1.121 + key: "fake-iso", 1.122 + prep: function setupFakeIso(test) { 1.123 + // we should recognize 'auto', 'hjr', and numeric modes; anything else 1.124 + // from the driver is ignored, which this test also verifies. 1.125 + test.setFakeParameters( 1.126 + "iso=auto;iso-values=auto,ISO_HJR,ISO100,foo,ISObar,ISO200,ISO400,ISO800,ISO1600", 1.127 + function () { 1.128 + run(); 1.129 + }); 1.130 + }, 1.131 + test: function testFakeIso(cam, cap) { 1.132 + // values 'foo' and 'ISObar' should not be included in isoModes 1.133 + ok(cap.isoModes.length == 7, "ISO modes length = " + cap.isoModes.length); 1.134 + ok(cap.isoModes.indexOf("foo") == -1, "Unknown ISO mode 'foo' is ignored"); 1.135 + ok(cap.isoModes.indexOf("ISObar") == -1, "Unknown ISO mode 'ISObar' is ignored"); 1.136 + ok(cap.isoModes.indexOf("bar") == -1, "Unknown ISO mode 'bar' is ignored"); 1.137 + 1.138 + // test individual ISO modes 1.139 + cap.isoModes.forEach(function(iso, index) { 1.140 + cam.iso = iso; 1.141 + ok(cam.iso === iso, 1.142 + "ISO[" + index + "] = " + iso + ", cam.iso = " + cam.iso); 1.143 + }); 1.144 + 1.145 + next(); 1.146 + } 1.147 + }, 1.148 +]; 1.149 + 1.150 +var testGenerator = function() { 1.151 + for (var i = 0; i < tests.length; ++i ) { 1.152 + yield tests[i]; 1.153 + } 1.154 +}(); 1.155 + 1.156 +window.addEventListener('beforeunload', function() { 1.157 + document.getElementById('viewfinder').mozSrcObject = null; 1.158 + if (cameraObj) { 1.159 + cameraObj.release(); 1.160 + cameraObj = null; 1.161 + } 1.162 +}); 1.163 + 1.164 +CameraTest.begin("hardware", function(test) { 1.165 + function onError(error) { 1.166 + ok(false, "getCamera() failed with: " + error); 1.167 + end(); 1.168 + } 1.169 + 1.170 + CameraTest.next = function() { 1.171 + try { 1.172 + var t = testGenerator.next(); 1.173 + info("test: " + t.key); 1.174 + function onSuccess(camera, config) { 1.175 + cameraObj = camera; 1.176 + document.getElementById('viewfinder').mozSrcObject = camera; 1.177 + camera.onPreviewStateChange = function (state) { 1.178 + if (state === "started") { 1.179 + t.test(camera, camera.capabilities); 1.180 + } else { 1.181 + ok(false, "preview started (state = '" + state + "')"); 1.182 + } 1.183 + camera.onPreviewStateChange = null; 1.184 + }; 1.185 + } 1.186 + CameraTest.run = function() { 1.187 + navigator.mozCameras.getCamera(whichCamera, initialConfig, onSuccess, onError); 1.188 + }; 1.189 + t.prep(test); 1.190 + } catch(e) { 1.191 + if (e instanceof StopIteration) { 1.192 + end(); 1.193 + } else { 1.194 + throw e; 1.195 + } 1.196 + } 1.197 + }; 1.198 + next(); 1.199 +}); 1.200 + 1.201 +</script> 1.202 +</body> 1.203 + 1.204 +</html>