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.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=965421
     5 -->
     6 <head>
     7   <title>Bug 965421 - Test camera hardware API for Auto focus moving Callback</title>
     8   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
     9   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    10   <script type="text/javascript" src="camera_common.js"></script>
    11   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    12 </head>
    13 <body>
    14   <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=965421">Mozilla Bug 965421</a>
    15   <video id="viewfinder" width = "200" height = "200" autoplay></video>
    16   <img src="#" alt="This image is going to load" id="testimage"/>
    18 <script class="testbody" type="text/javascript;version=1.7">
    20 var whichCamera = navigator.mozCameras.getListOfCameras()[0];
    21 var initialConfig = {
    22   mode: 'picture',
    23   recorderProfile: 'cif',
    24   previewSize: {
    25     width: 352,
    26     height: 288
    27   }
    28 };
    30 const PREF_AUTOFOCUSCALLBACK_ENABLED = "camera.control.autofocus_moving_callback.enabled";
    32 var cameraObj;
    33 var oldPref;
    35 // Shorthand functions
    36 function end() {
    37   function reallyEnd() {
    38     CameraTest.end();
    39   }
    40   if (oldPref) {
    41     SpecialPowers.pushPrefEnv(
    42       {'set': [[PREF_AUTOFOCUSCALLBACK_ENABLED, oldPref]]}, reallyEnd);
    43   } else {
    44     SpecialPowers.pushPrefEnv(
    45       {'clear': [[PREF_AUTOFOCUSCALLBACK_ENABLED]]}, reallyEnd);
    46   }
    47 }
    48 function next() {
    49   CameraTest.next();
    50 }
    52 var tests = [
    53   {
    54     key: "autofocus-moving-true",
    55     func: function testAutoFocusMovingIsTrue(camera) {
    56       camera.onAutoFocusMoving = function(aIsMoving) {
    57         ok(aIsMoving == true,"onAutoFocusMoving callback received true correctly");
    58         camera.focusMode = 'auto';
    59         next();
    60       }
    61       camera.focusMode = 'continuous-picture';
    62     }
    63   },
    64   {
    65     key: "autofocus-moving-false",
    66     func: function testAutoFocusMovingIsFalse(camera) {
    67       camera.onAutoFocusMoving = function(aIsMoving) {
    68         ok(aIsMoving == false, "onAutoFocusMoving callback received false correctly");
    69         camera.focusMode = 'auto';
    70         end();
    71       }
    72       camera.focusMode = 'continuous-video';
    73     }
    74   },
    75 ];
    77 var testGenerator = function() {
    78   for (var i = 0; i < tests.length; ++i ) {
    79     yield tests[i];
    80   }
    81 }();
    83 window.addEventListener('beforeunload', function() {
    84   document.getElementById('viewfinder').mozSrcObject = null;
    85   cameraObj.release();
    86   cameraObj = null;
    87 });
    89 // Must call CameraTest.begin() before any other async methods.
    90 CameraTest.begin("hardware", function(test) {
    91   // If the pref doesn't exist, this get will fail; catch it and continue.
    92   try {
    93     oldPref = SpecialPowers.getBoolPref(PREF_AUTOFOCUSCALLBACK_ENABLED);
    94   } catch(e) { }
    96   SpecialPowers.pushPrefEnv({'set': [[PREF_AUTOFOCUSCALLBACK_ENABLED, true]]}, function() {
    97     var enabled;
    98     try {
    99       enabled = SpecialPowers.getBoolPref(PREF_AUTOFOCUSCALLBACK_ENABLED);
   100     } catch(e) { }
   101     ok(enabled, PREF_AUTOFOCUSCALLBACK_ENABLED + " is " + enabled);
   103     function onSuccess(camera, config) {
   104       document.getElementById('viewfinder').mozSrcObject = camera;
   105       cameraObj = camera;
   106       CameraTest.next = function() {
   107         try {
   108           var t = testGenerator.next();
   109           test.set(t.key, t.func.bind(undefined, camera));
   110         } catch(e) {
   111           if (e instanceof StopIteration) {
   112             end();
   113           } else {
   114             throw e;
   115           }
   116         }
   117       };
   118       next();
   119     }
   120     function onError(error) {
   121       ok(false, "getCamera() failed with: " + error);
   122       end();
   123     }
   124     navigator.mozCameras.getCamera(whichCamera, initialConfig, onSuccess, onError);
   125   })
   126 });
   128 </script>
   129 </body>
   131 </html>

mercurial