Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test for mozCameras.getCamera() using an initial configuration</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']; |
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 | _testsCompleted: 0, |
michael@0 | 53 | _shutter: 0, |
michael@0 | 54 | _config: { |
michael@0 | 55 | dateTime: Date.now() / 1000, |
michael@0 | 56 | pictureSize: null, |
michael@0 | 57 | fileFormat: 'jpeg', |
michael@0 | 58 | rotation: 90 |
michael@0 | 59 | }, |
michael@0 | 60 | _tests: null, |
michael@0 | 61 | get viewfinder() { |
michael@0 | 62 | return document.getElementById('viewfinder'); |
michael@0 | 63 | }, |
michael@0 | 64 | setFlashMode: function camera_setFlash(mode) { |
michael@0 | 65 | this.cameraObj.flashMode = mode; |
michael@0 | 66 | }, |
michael@0 | 67 | setFocus: function camera_setfocus(mode) { |
michael@0 | 68 | this.cameraObj.focus = mode; |
michael@0 | 69 | }, |
michael@0 | 70 | getFileFormats: function camera_formats() { |
michael@0 | 71 | this._fileFormats = this.cameraObj.capabilities.fileFormats; |
michael@0 | 72 | }, |
michael@0 | 73 | getFlashModes: function camera_getFlash() { |
michael@0 | 74 | this._flashmodes = this.cameraObj.capabilities.flashModes; |
michael@0 | 75 | }, |
michael@0 | 76 | getFocusModes: function camera_getFocus() { |
michael@0 | 77 | this._focusModes = this.cameraObj.capabilities.focusModes; |
michael@0 | 78 | }, |
michael@0 | 79 | getSceneModes: function camera_getScene() { |
michael@0 | 80 | this._sceneModes = this.cameraObj.capabilities.sceneModes; |
michael@0 | 81 | }, |
michael@0 | 82 | getZoomRatios: function camera_getZoom() { |
michael@0 | 83 | this._zoomRatios = this.cameraObj.capabilities.zoomRatios; |
michael@0 | 84 | }, |
michael@0 | 85 | getWhiteBalance: function camera_white() { |
michael@0 | 86 | this._whitebalanceModes = this.cameraObj.capabilities.whiteBalanceModes; |
michael@0 | 87 | }, |
michael@0 | 88 | getPictureSizes: function camera_sizes() { |
michael@0 | 89 | this._pictureSizes = this.cameraObj.capabilities.pictureSizes; |
michael@0 | 90 | }, |
michael@0 | 91 | getPreviewSizes: function camera_preview() { |
michael@0 | 92 | this._previewSizes = this.cameraObj.capabilities.previewSizes; |
michael@0 | 93 | }, |
michael@0 | 94 | takePictureSuccess: function taken_foto(blob) { |
michael@0 | 95 | var img = new Image(); |
michael@0 | 96 | var test = this._currentTest; |
michael@0 | 97 | img.onload = function Imgsize() { |
michael@0 | 98 | ok(this.width == test.pictureSize.width, "The image taken has the width " + |
michael@0 | 99 | this.width + " pictureSize width = " + test.pictureSize.width); |
michael@0 | 100 | ok(this.height == test.pictureSize.height, "The image taken has the height " + |
michael@0 | 101 | this.height + " picturesize height = " + test.pictureSize.height); |
michael@0 | 102 | Camera._testsCompleted++; |
michael@0 | 103 | if(Camera._testsCompleted == Camera._tests.length) { |
michael@0 | 104 | ok(true, "test finishing"); |
michael@0 | 105 | SimpleTest.finish(); |
michael@0 | 106 | } else { |
michael@0 | 107 | Camera.runTests(); |
michael@0 | 108 | } |
michael@0 | 109 | } |
michael@0 | 110 | ok(blob.size > 100 , "Blob Size Gathered = " + blob.size); |
michael@0 | 111 | ok("image/" + test.fileFormat == blob.type, "Blob Type = " + blob.type); |
michael@0 | 112 | img.src = window.URL.createObjectURL(blob); |
michael@0 | 113 | }, |
michael@0 | 114 | shutter: function onShutter () { |
michael@0 | 115 | Camera._shutter++; |
michael@0 | 116 | |
michael@0 | 117 | ok(Camera._shutter == (Camera._testsCompleted + 1), "on Shutter has been called " + |
michael@0 | 118 | Camera._shutter + " times"); |
michael@0 | 119 | |
michael@0 | 120 | }, |
michael@0 | 121 | onReady: function onReady() { |
michael@0 | 122 | var camcap = Camera.cameraObj.capabilities; |
michael@0 | 123 | var tests = {}; |
michael@0 | 124 | for (var prop in capabilities) { |
michael@0 | 125 | prop = capabilities[prop]; |
michael@0 | 126 | ok(camcap[prop] || isFinite(camcap[prop]) || camcap[prop] == null, "Camera Capability: " + |
michael@0 | 127 | prop + " is exposed, value = " + JSON.stringify(camcap[prop])); |
michael@0 | 128 | } |
michael@0 | 129 | for (var prop in camcap) { |
michael@0 | 130 | if(camcap[prop] && camcap[prop].length > 1) { |
michael@0 | 131 | tests[prop] = camcap[prop]; |
michael@0 | 132 | } |
michael@0 | 133 | } |
michael@0 | 134 | Camera.getPictureSizes(); |
michael@0 | 135 | Camera.getPreviewSizes(); |
michael@0 | 136 | Camera.getFileFormats(); |
michael@0 | 137 | Camera.getFocusModes(); |
michael@0 | 138 | ok(Camera._previewSizes.length > 0, "previewSizes length = " + Camera._previewSizes.length); |
michael@0 | 139 | ok(Camera._pictureSizes.length > 0, "picturesizes length = " + Camera._pictureSizes.length); |
michael@0 | 140 | ok(Camera._fileFormats.length > 0, "file formats length = " + Camera._fileFormats.length); |
michael@0 | 141 | Camera._tests = new Array(); |
michael@0 | 142 | for (var i in Camera._pictureSizes) { |
michael@0 | 143 | for (var l in Camera._fileFormats) { |
michael@0 | 144 | var config = { |
michael@0 | 145 | pictureSize: Camera._pictureSizes[i], |
michael@0 | 146 | fileFormat: Camera._fileFormats[l] |
michael@0 | 147 | }; |
michael@0 | 148 | Camera._tests.push(config); |
michael@0 | 149 | } |
michael@0 | 150 | } |
michael@0 | 151 | Camera.runTests(); |
michael@0 | 152 | }, |
michael@0 | 153 | runTests: function run_tests() { |
michael@0 | 154 | var test = this._tests[this._testsCompleted]; |
michael@0 | 155 | this._currentTest = test; |
michael@0 | 156 | Camera.setFlashMode(test.flashMode); |
michael@0 | 157 | config.fileFormat = test.fileFormat; |
michael@0 | 158 | config.pictureSize = test.pictureSize; |
michael@0 | 159 | ok(true, "testing picture size " + JSON.stringify(config.pictureSize)); |
michael@0 | 160 | Camera.cameraObj.takePicture(config, this.takePictureSuccess.bind(this), onError); |
michael@0 | 161 | }, |
michael@0 | 162 | setUp: function setup_tests() { |
michael@0 | 163 | function onSuccess(camera, config) { |
michael@0 | 164 | ok(true, "Camera Control object has been successfully initialized"); |
michael@0 | 165 | ok(config.mode === options.mode, "configuration mode = " + config.mode); |
michael@0 | 166 | ok(config.recorderProfile === options.recorderProfile, "recorder profile = " + config.recorderProfile); |
michael@0 | 167 | ok(config.previewSize.width === options.previewSize.width && |
michael@0 | 168 | config.previewSize.height === options.previewSize.height, |
michael@0 | 169 | "preview size (w x h) = " + config.previewSize.width + " x " + config.previewSize.height); |
michael@0 | 170 | Camera.cameraObj = camera; |
michael@0 | 171 | Camera.viewfinder.mozSrcObject = camera; |
michael@0 | 172 | Camera.viewfinder.play(); |
michael@0 | 173 | Camera.cameraObj.onPreviewStateChange = function(state) { |
michael@0 | 174 | if (state === 'started') { |
michael@0 | 175 | ok(true, "viewfinder is ready and playing"); |
michael@0 | 176 | Camera.cameraObj.onPreviewStateChange = null; |
michael@0 | 177 | Camera.onReady(); |
michael@0 | 178 | } |
michael@0 | 179 | }; |
michael@0 | 180 | SimpleTest.expectAssertions(0); |
michael@0 | 181 | Camera.cameraObj.onShutter = Camera.shutter; |
michael@0 | 182 | }; |
michael@0 | 183 | navigator.mozCameras.getCamera(whichCamera, options, onSuccess, onError); |
michael@0 | 184 | } |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 188 | |
michael@0 | 189 | window.addEventListener('beforeunload', function() { |
michael@0 | 190 | Camera.viewfinder.mozSrcObject = null; |
michael@0 | 191 | Camera.cameraObj.release(); |
michael@0 | 192 | Camera.cameraObj = null; |
michael@0 | 193 | }); |
michael@0 | 194 | |
michael@0 | 195 | Camera.setUp(); |
michael@0 | 196 | |
michael@0 | 197 | </script> |
michael@0 | 198 | </body> |
michael@0 | 199 | |
michael@0 | 200 | </html> |