dom/camera/test/test_camera_hardware_auto_focus_moving_cb.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=965421
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Bug 965421 - Test camera hardware API for Auto focus moving Callback</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=965421">Mozilla Bug 965421</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 const PREF_AUTOFOCUSCALLBACK_ENABLED = "camera.control.autofocus_moving_callback.enabled";
michael@0 31
michael@0 32 var cameraObj;
michael@0 33 var oldPref;
michael@0 34
michael@0 35 // Shorthand functions
michael@0 36 function end() {
michael@0 37 function reallyEnd() {
michael@0 38 CameraTest.end();
michael@0 39 }
michael@0 40 if (oldPref) {
michael@0 41 SpecialPowers.pushPrefEnv(
michael@0 42 {'set': [[PREF_AUTOFOCUSCALLBACK_ENABLED, oldPref]]}, reallyEnd);
michael@0 43 } else {
michael@0 44 SpecialPowers.pushPrefEnv(
michael@0 45 {'clear': [[PREF_AUTOFOCUSCALLBACK_ENABLED]]}, reallyEnd);
michael@0 46 }
michael@0 47 }
michael@0 48 function next() {
michael@0 49 CameraTest.next();
michael@0 50 }
michael@0 51
michael@0 52 var tests = [
michael@0 53 {
michael@0 54 key: "autofocus-moving-true",
michael@0 55 func: function testAutoFocusMovingIsTrue(camera) {
michael@0 56 camera.onAutoFocusMoving = function(aIsMoving) {
michael@0 57 ok(aIsMoving == true,"onAutoFocusMoving callback received true correctly");
michael@0 58 camera.focusMode = 'auto';
michael@0 59 next();
michael@0 60 }
michael@0 61 camera.focusMode = 'continuous-picture';
michael@0 62 }
michael@0 63 },
michael@0 64 {
michael@0 65 key: "autofocus-moving-false",
michael@0 66 func: function testAutoFocusMovingIsFalse(camera) {
michael@0 67 camera.onAutoFocusMoving = function(aIsMoving) {
michael@0 68 ok(aIsMoving == false, "onAutoFocusMoving callback received false correctly");
michael@0 69 camera.focusMode = 'auto';
michael@0 70 end();
michael@0 71 }
michael@0 72 camera.focusMode = 'continuous-video';
michael@0 73 }
michael@0 74 },
michael@0 75 ];
michael@0 76
michael@0 77 var testGenerator = function() {
michael@0 78 for (var i = 0; i < tests.length; ++i ) {
michael@0 79 yield tests[i];
michael@0 80 }
michael@0 81 }();
michael@0 82
michael@0 83 window.addEventListener('beforeunload', function() {
michael@0 84 document.getElementById('viewfinder').mozSrcObject = null;
michael@0 85 cameraObj.release();
michael@0 86 cameraObj = null;
michael@0 87 });
michael@0 88
michael@0 89 // Must call CameraTest.begin() before any other async methods.
michael@0 90 CameraTest.begin("hardware", function(test) {
michael@0 91 // If the pref doesn't exist, this get will fail; catch it and continue.
michael@0 92 try {
michael@0 93 oldPref = SpecialPowers.getBoolPref(PREF_AUTOFOCUSCALLBACK_ENABLED);
michael@0 94 } catch(e) { }
michael@0 95
michael@0 96 SpecialPowers.pushPrefEnv({'set': [[PREF_AUTOFOCUSCALLBACK_ENABLED, true]]}, function() {
michael@0 97 var enabled;
michael@0 98 try {
michael@0 99 enabled = SpecialPowers.getBoolPref(PREF_AUTOFOCUSCALLBACK_ENABLED);
michael@0 100 } catch(e) { }
michael@0 101 ok(enabled, PREF_AUTOFOCUSCALLBACK_ENABLED + " is " + enabled);
michael@0 102
michael@0 103 function onSuccess(camera, config) {
michael@0 104 document.getElementById('viewfinder').mozSrcObject = camera;
michael@0 105 cameraObj = camera;
michael@0 106 CameraTest.next = function() {
michael@0 107 try {
michael@0 108 var t = testGenerator.next();
michael@0 109 test.set(t.key, t.func.bind(undefined, camera));
michael@0 110 } catch(e) {
michael@0 111 if (e instanceof StopIteration) {
michael@0 112 end();
michael@0 113 } else {
michael@0 114 throw e;
michael@0 115 }
michael@0 116 }
michael@0 117 };
michael@0 118 next();
michael@0 119 }
michael@0 120 function onError(error) {
michael@0 121 ok(false, "getCamera() failed with: " + error);
michael@0 122 end();
michael@0 123 }
michael@0 124 navigator.mozCameras.getCamera(whichCamera, initialConfig, onSuccess, onError);
michael@0 125 })
michael@0 126 });
michael@0 127
michael@0 128 </script>
michael@0 129 </body>
michael@0 130
michael@0 131 </html>

mercurial