зеркало из https://github.com/mozilla/gecko-dev.git
78 строки
2.1 KiB
HTML
78 строки
2.1 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<title>Test for multiple calls to mozCameras.getCamera()</title>
|
|
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
</head>
|
|
<body>
|
|
<video id="viewfinder" width="200" height="200" autoplay></video>
|
|
<img src="#" alt="This image is going to load" id="testimage"/>
|
|
<script class="testbody" type="text/javascript;version=1.7">
|
|
|
|
var whichCamera = navigator.mozCameras.getListOfCameras()[0];
|
|
var options = {
|
|
mode: 'picture',
|
|
recorderProfile: 'high',
|
|
previewSize: {
|
|
width: 352,
|
|
height: 288
|
|
}
|
|
};
|
|
|
|
function onError(e) {
|
|
ok(false, "Error " + e);
|
|
}
|
|
|
|
var Camera = {
|
|
cameraObj: null,
|
|
get viewfinder() {
|
|
return document.getElementById('viewfinder');
|
|
},
|
|
onReady: function take_two() {
|
|
function onSuccess(d) {
|
|
ok(false, "Unexpectedly got second camera instance: " + d.config.toSource);
|
|
}
|
|
function onFailure(error) {
|
|
ok(true, "Correctly failed to get camera again");
|
|
SimpleTest.finish();
|
|
}
|
|
navigator.mozCameras.getCamera(whichCamera, options).then(onSuccess, onFailure);
|
|
},
|
|
onPreviewStateChange: function onPreviewStateChange(e) {
|
|
if (e.newState === 'started') {
|
|
ok(true, "viewfinder is ready and playing");
|
|
Camera.cameraObj.removeEventListener('previewstatechange', Camera.onPreviewStateChange);
|
|
Camera.onReady();
|
|
}
|
|
},
|
|
release: function release() {
|
|
cameraObj = null;
|
|
},
|
|
start: function run_test() {
|
|
function onSuccess(d) {
|
|
Camera.cameraObj = d.camera;
|
|
Camera.cameraObj.addEventListener('previewstatechange', Camera.onPreviewStateChange);
|
|
Camera.viewfinder.mozSrcObject = d.camera;
|
|
Camera.viewfinder.play();
|
|
};
|
|
navigator.mozCameras.getCamera(whichCamera, options).then(onSuccess, onError);
|
|
}
|
|
}
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
window.addEventListener('beforeunload', function() {
|
|
Camera.viewfinder.mozSrcObject = null;
|
|
Camera.cameraObj.release();
|
|
Camera.cameraObj = null;
|
|
});
|
|
|
|
Camera.start();
|
|
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|