1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/camera/test/test_camera_hardware_auto_focus_moving_cb.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,131 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=965421 1.8 +--> 1.9 +<head> 1.10 + <title>Bug 965421 - Test camera hardware API for Auto focus moving Callback</title> 1.11 + <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> 1.12 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <script type="text/javascript" src="camera_common.js"></script> 1.14 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.15 +</head> 1.16 +<body> 1.17 + <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=965421">Mozilla Bug 965421</a> 1.18 + <video id="viewfinder" width = "200" height = "200" autoplay></video> 1.19 + <img src="#" alt="This image is going to load" id="testimage"/> 1.20 + 1.21 +<script class="testbody" type="text/javascript;version=1.7"> 1.22 + 1.23 +var whichCamera = navigator.mozCameras.getListOfCameras()[0]; 1.24 +var initialConfig = { 1.25 + mode: 'picture', 1.26 + recorderProfile: 'cif', 1.27 + previewSize: { 1.28 + width: 352, 1.29 + height: 288 1.30 + } 1.31 +}; 1.32 + 1.33 +const PREF_AUTOFOCUSCALLBACK_ENABLED = "camera.control.autofocus_moving_callback.enabled"; 1.34 + 1.35 +var cameraObj; 1.36 +var oldPref; 1.37 + 1.38 +// Shorthand functions 1.39 +function end() { 1.40 + function reallyEnd() { 1.41 + CameraTest.end(); 1.42 + } 1.43 + if (oldPref) { 1.44 + SpecialPowers.pushPrefEnv( 1.45 + {'set': [[PREF_AUTOFOCUSCALLBACK_ENABLED, oldPref]]}, reallyEnd); 1.46 + } else { 1.47 + SpecialPowers.pushPrefEnv( 1.48 + {'clear': [[PREF_AUTOFOCUSCALLBACK_ENABLED]]}, reallyEnd); 1.49 + } 1.50 +} 1.51 +function next() { 1.52 + CameraTest.next(); 1.53 +} 1.54 + 1.55 +var tests = [ 1.56 + { 1.57 + key: "autofocus-moving-true", 1.58 + func: function testAutoFocusMovingIsTrue(camera) { 1.59 + camera.onAutoFocusMoving = function(aIsMoving) { 1.60 + ok(aIsMoving == true,"onAutoFocusMoving callback received true correctly"); 1.61 + camera.focusMode = 'auto'; 1.62 + next(); 1.63 + } 1.64 + camera.focusMode = 'continuous-picture'; 1.65 + } 1.66 + }, 1.67 + { 1.68 + key: "autofocus-moving-false", 1.69 + func: function testAutoFocusMovingIsFalse(camera) { 1.70 + camera.onAutoFocusMoving = function(aIsMoving) { 1.71 + ok(aIsMoving == false, "onAutoFocusMoving callback received false correctly"); 1.72 + camera.focusMode = 'auto'; 1.73 + end(); 1.74 + } 1.75 + camera.focusMode = 'continuous-video'; 1.76 + } 1.77 + }, 1.78 +]; 1.79 + 1.80 +var testGenerator = function() { 1.81 + for (var i = 0; i < tests.length; ++i ) { 1.82 + yield tests[i]; 1.83 + } 1.84 +}(); 1.85 + 1.86 +window.addEventListener('beforeunload', function() { 1.87 + document.getElementById('viewfinder').mozSrcObject = null; 1.88 + cameraObj.release(); 1.89 + cameraObj = null; 1.90 +}); 1.91 + 1.92 +// Must call CameraTest.begin() before any other async methods. 1.93 +CameraTest.begin("hardware", function(test) { 1.94 + // If the pref doesn't exist, this get will fail; catch it and continue. 1.95 + try { 1.96 + oldPref = SpecialPowers.getBoolPref(PREF_AUTOFOCUSCALLBACK_ENABLED); 1.97 + } catch(e) { } 1.98 + 1.99 + SpecialPowers.pushPrefEnv({'set': [[PREF_AUTOFOCUSCALLBACK_ENABLED, true]]}, function() { 1.100 + var enabled; 1.101 + try { 1.102 + enabled = SpecialPowers.getBoolPref(PREF_AUTOFOCUSCALLBACK_ENABLED); 1.103 + } catch(e) { } 1.104 + ok(enabled, PREF_AUTOFOCUSCALLBACK_ENABLED + " is " + enabled); 1.105 + 1.106 + function onSuccess(camera, config) { 1.107 + document.getElementById('viewfinder').mozSrcObject = camera; 1.108 + cameraObj = camera; 1.109 + CameraTest.next = function() { 1.110 + try { 1.111 + var t = testGenerator.next(); 1.112 + test.set(t.key, t.func.bind(undefined, camera)); 1.113 + } catch(e) { 1.114 + if (e instanceof StopIteration) { 1.115 + end(); 1.116 + } else { 1.117 + throw e; 1.118 + } 1.119 + } 1.120 + }; 1.121 + next(); 1.122 + } 1.123 + function onError(error) { 1.124 + ok(false, "getCamera() failed with: " + error); 1.125 + end(); 1.126 + } 1.127 + navigator.mozCameras.getCamera(whichCamera, initialConfig, onSuccess, onError); 1.128 + }) 1.129 +}); 1.130 + 1.131 +</script> 1.132 +</body> 1.133 + 1.134 +</html>