1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/camera/test/test_camera_2.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,200 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test for mozCameras.getCamera() using an initial configuration</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 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.11 +</head> 1.12 +<body> 1.13 +<video id="viewfinder" width="200" height="200" autoplay></video> 1.14 +<img src="#" alt="This image is going to load" id="testimage"/> 1.15 +<script class="testbody" type="text/javascript;version=1.7"> 1.16 + 1.17 +var whichCamera = navigator.mozCameras.getListOfCameras()[0]; 1.18 +var options = { 1.19 + mode: 'picture', 1.20 + recorderProfile: 'cif', 1.21 + previewSize: { 1.22 + width: 352, 1.23 + height: 288 1.24 + } 1.25 +}; 1.26 + 1.27 +var config = { 1.28 + dateTime: Date.now() / 1000, 1.29 + pictureSize: null, 1.30 + fileFormat: 'jpeg', 1.31 + rotation: 90 1.32 +}; 1.33 + 1.34 +function onError(e) { 1.35 + ok(false, "Error" + JSON.stringify(e)); 1.36 +} 1.37 + 1.38 +var capabilities = [ 'previewSizes', 'pictureSizes', 'fileFormats', 'maxFocusAreas', 'minExposureCompensation', 1.39 + 'maxExposureCompensation', 'stepExposureCompensation', 'maxMeteringAreas', 'videoSizes', 1.40 + 'recorderProfiles']; 1.41 + 1.42 +var Camera = { 1.43 + cameraObj: null, 1.44 + _recording: false, 1.45 + _currentTest: null, 1.46 + _autoFocusSupported: 0, 1.47 + _manuallyFocused: false, 1.48 + _flashmodes: null, 1.49 + _pictureSizes: null, 1.50 + _previewSizes: null, 1.51 + _whiteBalanceModes: null, 1.52 + _zoomRatios: null, 1.53 + _sceneModes: null, 1.54 + _focusModes: null, 1.55 + _testsCompleted: 0, 1.56 + _shutter: 0, 1.57 + _config: { 1.58 + dateTime: Date.now() / 1000, 1.59 + pictureSize: null, 1.60 + fileFormat: 'jpeg', 1.61 + rotation: 90 1.62 + }, 1.63 + _tests: null, 1.64 + get viewfinder() { 1.65 + return document.getElementById('viewfinder'); 1.66 + }, 1.67 + setFlashMode: function camera_setFlash(mode) { 1.68 + this.cameraObj.flashMode = mode; 1.69 + }, 1.70 + setFocus: function camera_setfocus(mode) { 1.71 + this.cameraObj.focus = mode; 1.72 + }, 1.73 + getFileFormats: function camera_formats() { 1.74 + this._fileFormats = this.cameraObj.capabilities.fileFormats; 1.75 + }, 1.76 + getFlashModes: function camera_getFlash() { 1.77 + this._flashmodes = this.cameraObj.capabilities.flashModes; 1.78 + }, 1.79 + getFocusModes: function camera_getFocus() { 1.80 + this._focusModes = this.cameraObj.capabilities.focusModes; 1.81 + }, 1.82 + getSceneModes: function camera_getScene() { 1.83 + this._sceneModes = this.cameraObj.capabilities.sceneModes; 1.84 + }, 1.85 + getZoomRatios: function camera_getZoom() { 1.86 + this._zoomRatios = this.cameraObj.capabilities.zoomRatios; 1.87 + }, 1.88 + getWhiteBalance: function camera_white() { 1.89 + this._whitebalanceModes = this.cameraObj.capabilities.whiteBalanceModes; 1.90 + }, 1.91 + getPictureSizes: function camera_sizes() { 1.92 + this._pictureSizes = this.cameraObj.capabilities.pictureSizes; 1.93 + }, 1.94 + getPreviewSizes: function camera_preview() { 1.95 + this._previewSizes = this.cameraObj.capabilities.previewSizes; 1.96 + }, 1.97 + takePictureSuccess: function taken_foto(blob) { 1.98 + var img = new Image(); 1.99 + var test = this._currentTest; 1.100 + img.onload = function Imgsize() { 1.101 + ok(this.width == test.pictureSize.width, "The image taken has the width " + 1.102 + this.width + " pictureSize width = " + test.pictureSize.width); 1.103 + ok(this.height == test.pictureSize.height, "The image taken has the height " + 1.104 + this.height + " picturesize height = " + test.pictureSize.height); 1.105 + Camera._testsCompleted++; 1.106 + if(Camera._testsCompleted == Camera._tests.length) { 1.107 + ok(true, "test finishing"); 1.108 + SimpleTest.finish(); 1.109 + } else { 1.110 + Camera.runTests(); 1.111 + } 1.112 + } 1.113 + ok(blob.size > 100 , "Blob Size Gathered = " + blob.size); 1.114 + ok("image/" + test.fileFormat == blob.type, "Blob Type = " + blob.type); 1.115 + img.src = window.URL.createObjectURL(blob); 1.116 + }, 1.117 + shutter: function onShutter () { 1.118 + Camera._shutter++; 1.119 + 1.120 + ok(Camera._shutter == (Camera._testsCompleted + 1), "on Shutter has been called " + 1.121 + Camera._shutter + " times"); 1.122 + 1.123 + }, 1.124 + onReady: function onReady() { 1.125 + var camcap = Camera.cameraObj.capabilities; 1.126 + var tests = {}; 1.127 + for (var prop in capabilities) { 1.128 + prop = capabilities[prop]; 1.129 + ok(camcap[prop] || isFinite(camcap[prop]) || camcap[prop] == null, "Camera Capability: " + 1.130 + prop + " is exposed, value = " + JSON.stringify(camcap[prop])); 1.131 + } 1.132 + for (var prop in camcap) { 1.133 + if(camcap[prop] && camcap[prop].length > 1) { 1.134 + tests[prop] = camcap[prop]; 1.135 + } 1.136 + } 1.137 + Camera.getPictureSizes(); 1.138 + Camera.getPreviewSizes(); 1.139 + Camera.getFileFormats(); 1.140 + Camera.getFocusModes(); 1.141 + ok(Camera._previewSizes.length > 0, "previewSizes length = " + Camera._previewSizes.length); 1.142 + ok(Camera._pictureSizes.length > 0, "picturesizes length = " + Camera._pictureSizes.length); 1.143 + ok(Camera._fileFormats.length > 0, "file formats length = " + Camera._fileFormats.length); 1.144 + Camera._tests = new Array(); 1.145 + for (var i in Camera._pictureSizes) { 1.146 + for (var l in Camera._fileFormats) { 1.147 + var config = { 1.148 + pictureSize: Camera._pictureSizes[i], 1.149 + fileFormat: Camera._fileFormats[l] 1.150 + }; 1.151 + Camera._tests.push(config); 1.152 + } 1.153 + } 1.154 + Camera.runTests(); 1.155 + }, 1.156 + runTests: function run_tests() { 1.157 + var test = this._tests[this._testsCompleted]; 1.158 + this._currentTest = test; 1.159 + Camera.setFlashMode(test.flashMode); 1.160 + config.fileFormat = test.fileFormat; 1.161 + config.pictureSize = test.pictureSize; 1.162 + ok(true, "testing picture size " + JSON.stringify(config.pictureSize)); 1.163 + Camera.cameraObj.takePicture(config, this.takePictureSuccess.bind(this), onError); 1.164 + }, 1.165 + setUp: function setup_tests() { 1.166 + function onSuccess(camera, config) { 1.167 + ok(true, "Camera Control object has been successfully initialized"); 1.168 + ok(config.mode === options.mode, "configuration mode = " + config.mode); 1.169 + ok(config.recorderProfile === options.recorderProfile, "recorder profile = " + config.recorderProfile); 1.170 + ok(config.previewSize.width === options.previewSize.width && 1.171 + config.previewSize.height === options.previewSize.height, 1.172 + "preview size (w x h) = " + config.previewSize.width + " x " + config.previewSize.height); 1.173 + Camera.cameraObj = camera; 1.174 + Camera.viewfinder.mozSrcObject = camera; 1.175 + Camera.viewfinder.play(); 1.176 + Camera.cameraObj.onPreviewStateChange = function(state) { 1.177 + if (state === 'started') { 1.178 + ok(true, "viewfinder is ready and playing"); 1.179 + Camera.cameraObj.onPreviewStateChange = null; 1.180 + Camera.onReady(); 1.181 + } 1.182 + }; 1.183 + SimpleTest.expectAssertions(0); 1.184 + Camera.cameraObj.onShutter = Camera.shutter; 1.185 + }; 1.186 + navigator.mozCameras.getCamera(whichCamera, options, onSuccess, onError); 1.187 + } 1.188 +} 1.189 + 1.190 +SimpleTest.waitForExplicitFinish(); 1.191 + 1.192 +window.addEventListener('beforeunload', function() { 1.193 + Camera.viewfinder.mozSrcObject = null; 1.194 + Camera.cameraObj.release(); 1.195 + Camera.cameraObj = null; 1.196 +}); 1.197 + 1.198 +Camera.setUp(); 1.199 + 1.200 +</script> 1.201 +</body> 1.202 + 1.203 +</html>