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