dom/camera/test/test_camera_hardware_failures.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 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=940424
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Bug 940424 - Test camera hardware API failure handling</title>
michael@0 8 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
michael@0 9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <script type="text/javascript" src="camera_common.js"></script>
michael@0 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 12 </head>
michael@0 13 <body>
michael@0 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=940424">Mozilla Bug 940424</a>
michael@0 15 <video id="viewfinder" width = "200" height = "200" autoplay></video>
michael@0 16 <img src="#" alt="This image is going to load" id="testimage"/>
michael@0 17
michael@0 18 <script class="testbody" type="text/javascript;version=1.7">
michael@0 19
michael@0 20 var whichCamera = navigator.mozCameras.getListOfCameras()[0];
michael@0 21 var initialConfig = {
michael@0 22 mode: 'picture',
michael@0 23 recorderProfile: 'cif',
michael@0 24 previewSize: {
michael@0 25 width: 352,
michael@0 26 height: 288
michael@0 27 }
michael@0 28 };
michael@0 29
michael@0 30 var cameraObj;
michael@0 31
michael@0 32 // Shorthand functions
michael@0 33 function end() {
michael@0 34 CameraTest.end();
michael@0 35 }
michael@0 36 function next() {
michael@0 37 CameraTest.next();
michael@0 38 }
michael@0 39
michael@0 40 // The array of tests
michael@0 41 var tests = [
michael@0 42 {
michael@0 43 key: "auto-focus-failure",
michael@0 44 func: function testAutoFocusApiFailure(camera) {
michael@0 45 function onSuccess(success) {
michael@0 46 ok(false, "autoFocus() succeeded incorrectly");
michael@0 47 end();
michael@0 48 }
michael@0 49 function onError(error) {
michael@0 50 ok(true, "autoFocus() failed correctly with: " + error);
michael@0 51 next();
michael@0 52 }
michael@0 53 camera.autoFocus(onSuccess, onError);
michael@0 54 }
michael@0 55 },
michael@0 56 {
michael@0 57 key: "auto-focus-process-failure",
michael@0 58 func: function testAutoFocusProcessFailure(camera) {
michael@0 59 function onSuccess(success) {
michael@0 60 if (success) {
michael@0 61 ok(false, "autoFocus() process succeeded incorrectly");
michael@0 62 end();
michael@0 63 } else {
michael@0 64 ok(true, "autoFocus() process failed correctly");
michael@0 65 next();
michael@0 66 }
michael@0 67 }
michael@0 68 function onError(error) {
michael@0 69 ok(false, "autoFocus() process failed incorrectly with: " + error);
michael@0 70 end();
michael@0 71 }
michael@0 72 camera.autoFocus(onSuccess, onError);
michael@0 73 }
michael@0 74 },
michael@0 75 {
michael@0 76 key: "take-picture-failure",
michael@0 77 func: function testTakePictureApiFailure(camera) {
michael@0 78 function onSuccess(picture) {
michael@0 79 ok(false, "takePicture() succeeded incorrectly");
michael@0 80 end();
michael@0 81 }
michael@0 82 function onError(error) {
michael@0 83 ok(true, "takePicture() failed correctly with: " + error);
michael@0 84 next();
michael@0 85 }
michael@0 86 camera.takePicture(null, onSuccess, onError);
michael@0 87 }
michael@0 88 },
michael@0 89 {
michael@0 90 key: "take-picture-process-failure",
michael@0 91 func: function testTakePictureProcessFailure(camera) {
michael@0 92 function onSuccess(picture) {
michael@0 93 ok(false, "takePicture() process succeeded incorrectly");
michael@0 94 end();
michael@0 95 }
michael@0 96 function onError(error) {
michael@0 97 ok(true, "takePicture() process failed correctly with: " + error);
michael@0 98 next();
michael@0 99 }
michael@0 100 camera.takePicture(null, onSuccess, onError);
michael@0 101 }
michael@0 102 },
michael@0 103 ];
michael@0 104
michael@0 105 var testGenerator = function() {
michael@0 106 for (var i = 0; i < tests.length; ++i ) {
michael@0 107 yield tests[i];
michael@0 108 }
michael@0 109 }();
michael@0 110
michael@0 111 window.addEventListener('beforeunload', function() {
michael@0 112 document.getElementById('viewfinder').mozSrcObject = null;
michael@0 113 cameraObj.release();
michael@0 114 cameraObj = null;
michael@0 115 });
michael@0 116
michael@0 117 CameraTest.begin("hardware", function(test) {
michael@0 118 function onSuccess(camera, config) {
michael@0 119 document.getElementById('viewfinder').mozSrcObject = camera;
michael@0 120 cameraObj = camera;
michael@0 121 CameraTest.next = function() {
michael@0 122 try {
michael@0 123 var t = testGenerator.next();
michael@0 124 test.set(t.key, t.func.bind(undefined, camera));
michael@0 125 } catch(e) {
michael@0 126 if (e instanceof StopIteration) {
michael@0 127 end();
michael@0 128 } else {
michael@0 129 throw e;
michael@0 130 }
michael@0 131 }
michael@0 132 };
michael@0 133 next();
michael@0 134 }
michael@0 135 function onError(error) {
michael@0 136 ok(false, "getCamera() failed with: " + error);
michael@0 137 end();
michael@0 138 }
michael@0 139 navigator.mozCameras.getCamera(whichCamera, initialConfig, onSuccess, onError);
michael@0 140 });
michael@0 141
michael@0 142 </script>
michael@0 143 </body>
michael@0 144
michael@0 145 </html>

mercurial