1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/camera/test/test_camera_3.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test for multiple calls to mozCameras.getCamera()</title> 1.8 + <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> 1.9 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.10 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.11 +</head> 1.12 +<body> 1.13 +<video id="viewfinder" width="200" height="200" autoplay></video> 1.14 +<img src="#" alt="This image is going to load" id="testimage"/> 1.15 +<script class="testbody" type="text/javascript;version=1.7"> 1.16 + 1.17 +var whichCamera = navigator.mozCameras.getListOfCameras()[0]; 1.18 +var options = { 1.19 + mode: 'picture', 1.20 + recorderProfile: 'cif', 1.21 + previewSize: { 1.22 + width: 352, 1.23 + height: 288 1.24 + } 1.25 +}; 1.26 + 1.27 +function onError(e) { 1.28 + ok(false, "Error" + JSON.stringify(e)); 1.29 +} 1.30 + 1.31 +var Camera = { 1.32 + cameraObj: null, 1.33 + get viewfinder() { 1.34 + return document.getElementById('viewfinder'); 1.35 + }, 1.36 + onReady: function take_two() { 1.37 + function onSuccess(camera, config) { 1.38 + ok(false, "Unexpectedly got second camera instance: " + config.toSource); 1.39 + } 1.40 + function onFailure(error) { 1.41 + ok(true, "Correctly failed to get camera again"); 1.42 + SimpleTest.finish(); 1.43 + } 1.44 + navigator.mozCameras.getCamera(whichCamera, options, onSuccess, onFailure); 1.45 + }, 1.46 + release: function release() { 1.47 + cameraObj = null; 1.48 + }, 1.49 + start: function run_test() { 1.50 + function onSuccess(camera, config) { 1.51 + Camera.cameraObj = camera; 1.52 + Camera.viewfinder.mozSrcObject = camera; 1.53 + Camera.viewfinder.play(); 1.54 + Camera.cameraObj.onPreviewStateChange = function(state) { 1.55 + if (state === 'started') { 1.56 + ok(true, "viewfinder is ready and playing"); 1.57 + Camera.cameraObj.onPreviewStateChange = null; 1.58 + Camera.onReady(); 1.59 + } 1.60 + }; 1.61 + }; 1.62 + navigator.mozCameras.getCamera(whichCamera, options, onSuccess, onError); 1.63 + } 1.64 +} 1.65 + 1.66 +SimpleTest.waitForExplicitFinish(); 1.67 + 1.68 +window.addEventListener('beforeunload', function() { 1.69 + Camera.viewfinder.mozSrcObject = null; 1.70 + Camera.cameraObj.release(); 1.71 + Camera.cameraObj = null; 1.72 +}); 1.73 + 1.74 +Camera.start(); 1.75 + 1.76 +</script> 1.77 +</body> 1.78 + 1.79 +</html>