dom/camera/test/test_camera_fake_parameters.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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 CameraParameters we need to fake</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 <script type="text/javascript" src="camera_common.js"></script>
michael@0 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 9 </head>
michael@0 10 <body>
michael@0 11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=976802">Mozilla Bug 976802</a>
michael@0 12 <video id="viewfinder" width="200" height="200" autoplay></video>
michael@0 13 <img src="#" alt="This image is going to load" id="testimage"/>
michael@0 14
michael@0 15 <script class="testbody" type="text/javascript;version=1.7">
michael@0 16
michael@0 17 var whichCamera = navigator.mozCameras.getListOfCameras()[0];
michael@0 18 var initialConfig = {
michael@0 19 mode: 'picture',
michael@0 20 recorderProfile: 'cif',
michael@0 21 previewSize: {
michael@0 22 width: 352,
michael@0 23 height: 288
michael@0 24 }
michael@0 25 };
michael@0 26
michael@0 27 var cameraObj = null;
michael@0 28
michael@0 29 // Shorthand functions
michael@0 30 function onError(e) {
michael@0 31 ok(false, "Error" + JSON.stringify(e));
michael@0 32 }
michael@0 33
michael@0 34 function end() {
michael@0 35 CameraTest.end();
michael@0 36 }
michael@0 37 function next() {
michael@0 38 if (cameraObj) {
michael@0 39 cameraObj.release(
michael@0 40 function success() {
michael@0 41 CameraTest.next();
michael@0 42 },
michael@0 43 onError
michael@0 44 );
michael@0 45 cameraObj = null;
michael@0 46 } else {
michael@0 47 CameraTest.next();
michael@0 48 }
michael@0 49 }
michael@0 50 function run() {
michael@0 51 CameraTest.run();
michael@0 52 }
michael@0 53
michael@0 54 // The array of tests. Because camera capabilities don't change over the life
michael@0 55 // of a CameraControl object, they are only read once when the CameraControl is
michael@0 56 // created; so we have to call the 'prep' function first to set the fake
michael@0 57 // capability pref, before we call getCamera() and call 'test' to run the test.
michael@0 58 var tests = [
michael@0 59 {
michael@0 60 key: "fake-zoom",
michael@0 61 prep: function setupFakeZoom(test) {
michael@0 62 test.setFakeParameters("zoom-ratios=100,150,200,300,400;max-zoom=4", function() {
michael@0 63 run();
michael@0 64 });
michael@0 65 },
michael@0 66 test: function testFakeZoom(cam, cap) {
michael@0 67 ok(cap.zoomRatios.length == 5, "zoom ratios length = " + cap.zoomRatios.length);
michael@0 68
michael@0 69 // test individual zoom ratios
michael@0 70 cap.zoomRatios.forEach(function(zoom, index) {
michael@0 71 cam.zoom = zoom;
michael@0 72 ok(cam.zoom === zoom,
michael@0 73 "zoom[" + index + "] = " + zoom + "x, cam.zoom = " + cam.zoom + "x");
michael@0 74 });
michael@0 75
michael@0 76 // test below-lower-bound zoom ratio
michael@0 77 var zoom = cap.zoomRatios[0] - 0.1;
michael@0 78 cam.zoom = zoom;
michael@0 79 ok(cam.zoom === cap.zoomRatios[0],
michael@0 80 zoom + "x zoom clamps to minimum: " +
michael@0 81 cap.zoomRatios[0] + "x, cam.zoom = " + cam.zoom + "x");
michael@0 82
michael@0 83 // test above-upper-bound zoom ratio
michael@0 84 zoom = cap.zoomRatios.slice(-1)[0] + 1.0;
michael@0 85 cam.zoom = zoom;
michael@0 86 ok(cam.zoom === cap.zoomRatios.slice(-1)[0],
michael@0 87 zoom + "x zoom clamps to maximum: " + cap.zoomRatios.slice(-1)[0] +
michael@0 88 "x, cam.zoom = " + cam.zoom + "x");
michael@0 89
michael@0 90 // test snapping to supported zoom ratio
michael@0 91 if (cap.zoomRatios.length > 1) {
michael@0 92 zoom = (cap.zoomRatios[0] + cap.zoomRatios[1]) / 2;
michael@0 93 cam.zoom = zoom;
michael@0 94 ok(cam.zoom === cap.zoomRatios[0],
michael@0 95 zoom + "x zoom rounded down to: " + cap.zoomRatios[0] +
michael@0 96 "x, cam.zoom = " + cam.zoom + "x");
michael@0 97 }
michael@0 98
michael@0 99 next();
michael@0 100 }
michael@0 101 },
michael@0 102 {
michael@0 103 key: "fake-zoom-out-of-order",
michael@0 104 prep: function setupFakeZoomOutOfOrder(test) {
michael@0 105 // We expect the camera library to give us zoom ratios in order; if
michael@0 106 // it doesn't we ignore the list and just return 1x support.
michael@0 107 test.setFakeParameters("zoom-ratios=100,150,200,400,300;max-zoom=4", function () {
michael@0 108 run();
michael@0 109 });
michael@0 110 },
michael@0 111 test: function testFakeZoomOutOfOrder(cam, cap) {
michael@0 112 ok(cap.zoomRatios.length == 1, "zoom ratios length = " + cap.zoomRatios.length);
michael@0 113 ok(cap.zoomRatios[0] == 1.0, "only supported zoom = " + cap.zoomRatios[0] + "x");
michael@0 114 next();
michael@0 115 }
michael@0 116 },
michael@0 117 {
michael@0 118 key: "fake-iso",
michael@0 119 prep: function setupFakeIso(test) {
michael@0 120 // we should recognize 'auto', 'hjr', and numeric modes; anything else
michael@0 121 // from the driver is ignored, which this test also verifies.
michael@0 122 test.setFakeParameters(
michael@0 123 "iso=auto;iso-values=auto,ISO_HJR,ISO100,foo,ISObar,ISO200,ISO400,ISO800,ISO1600",
michael@0 124 function () {
michael@0 125 run();
michael@0 126 });
michael@0 127 },
michael@0 128 test: function testFakeIso(cam, cap) {
michael@0 129 // values 'foo' and 'ISObar' should not be included in isoModes
michael@0 130 ok(cap.isoModes.length == 7, "ISO modes length = " + cap.isoModes.length);
michael@0 131 ok(cap.isoModes.indexOf("foo") == -1, "Unknown ISO mode 'foo' is ignored");
michael@0 132 ok(cap.isoModes.indexOf("ISObar") == -1, "Unknown ISO mode 'ISObar' is ignored");
michael@0 133 ok(cap.isoModes.indexOf("bar") == -1, "Unknown ISO mode 'bar' is ignored");
michael@0 134
michael@0 135 // test individual ISO modes
michael@0 136 cap.isoModes.forEach(function(iso, index) {
michael@0 137 cam.iso = iso;
michael@0 138 ok(cam.iso === iso,
michael@0 139 "ISO[" + index + "] = " + iso + ", cam.iso = " + cam.iso);
michael@0 140 });
michael@0 141
michael@0 142 next();
michael@0 143 }
michael@0 144 },
michael@0 145 ];
michael@0 146
michael@0 147 var testGenerator = function() {
michael@0 148 for (var i = 0; i < tests.length; ++i ) {
michael@0 149 yield tests[i];
michael@0 150 }
michael@0 151 }();
michael@0 152
michael@0 153 window.addEventListener('beforeunload', function() {
michael@0 154 document.getElementById('viewfinder').mozSrcObject = null;
michael@0 155 if (cameraObj) {
michael@0 156 cameraObj.release();
michael@0 157 cameraObj = null;
michael@0 158 }
michael@0 159 });
michael@0 160
michael@0 161 CameraTest.begin("hardware", function(test) {
michael@0 162 function onError(error) {
michael@0 163 ok(false, "getCamera() failed with: " + error);
michael@0 164 end();
michael@0 165 }
michael@0 166
michael@0 167 CameraTest.next = function() {
michael@0 168 try {
michael@0 169 var t = testGenerator.next();
michael@0 170 info("test: " + t.key);
michael@0 171 function onSuccess(camera, config) {
michael@0 172 cameraObj = camera;
michael@0 173 document.getElementById('viewfinder').mozSrcObject = camera;
michael@0 174 camera.onPreviewStateChange = function (state) {
michael@0 175 if (state === "started") {
michael@0 176 t.test(camera, camera.capabilities);
michael@0 177 } else {
michael@0 178 ok(false, "preview started (state = '" + state + "')");
michael@0 179 }
michael@0 180 camera.onPreviewStateChange = null;
michael@0 181 };
michael@0 182 }
michael@0 183 CameraTest.run = function() {
michael@0 184 navigator.mozCameras.getCamera(whichCamera, initialConfig, onSuccess, onError);
michael@0 185 };
michael@0 186 t.prep(test);
michael@0 187 } catch(e) {
michael@0 188 if (e instanceof StopIteration) {
michael@0 189 end();
michael@0 190 } else {
michael@0 191 throw e;
michael@0 192 }
michael@0 193 }
michael@0 194 };
michael@0 195 next();
michael@0 196 });
michael@0 197
michael@0 198 </script>
michael@0 199 </body>
michael@0 200
michael@0 201 </html>

mercurial