зеркало из https://github.com/mozilla/gecko-dev.git
89 строки
2.6 KiB
HTML
89 строки
2.6 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=940424
|
|
-->
|
|
<head>
|
|
<title>Bug 940424 - Test camera hardware init failure handling</title>
|
|
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<script type="text/javascript" src="camera_common.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
</head>
|
|
<body>
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=940424">Mozilla Bug 940424</a>
|
|
<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 suite = new CameraTestSuite();
|
|
|
|
suite.test('init-failure', function() {
|
|
var cameraManager = navigator.mozCameras;
|
|
var whichCamera = cameraManager.getListOfCameras()[0];
|
|
|
|
suite.hw.attach({
|
|
init: function() {
|
|
throw SpecialPowers.Cr.NS_ERROR_NOT_INITIALIZED;
|
|
}
|
|
});
|
|
|
|
function rejectGetCamera(e) {
|
|
ok(e.name === 'NS_ERROR_NOT_AVAILABLE', 'onError called correctly on getCamera init failure: ' + e);
|
|
// Let the next getCamera attempt succeed
|
|
suite.initJsHw();
|
|
return Promise.resolve();
|
|
}
|
|
|
|
function resolveGetCamera(p) {
|
|
ok(true, 'onSuccess called correctly for second getCamera request');
|
|
}
|
|
|
|
return cameraManager.getCamera(whichCamera)
|
|
.then(suite.expectedRejectGetCamera, rejectGetCamera)
|
|
.then(suite.getCamera)
|
|
.then(resolveGetCamera, suite.rejectGetCamera)
|
|
});
|
|
|
|
/* Test for bug 1099390 to make sure events related to the underlying
|
|
platform failing are generated and handled properly. */
|
|
suite.test('post-init-system-failure', function() {
|
|
function triggerSystemFailure(p) {
|
|
var sync = new Promise(function(resolve, reject) {
|
|
function onClosedEvent(e) {
|
|
suite.camera.removeEventListener('close', onClosedEvent);
|
|
ok(e.reason === 'SystemFailure', 'reason is: ' + e.reason);
|
|
resolve();
|
|
}
|
|
suite.camera.addEventListener('close', onClosedEvent);
|
|
});
|
|
|
|
suite.hw.fireSystemError();
|
|
return sync;
|
|
}
|
|
|
|
function releaseCamera(p) {
|
|
var camera = suite.camera;
|
|
suite.camera = null;
|
|
return camera.release();
|
|
}
|
|
|
|
function releasedCamera(p) {
|
|
ok(true, 'camera released after system failure');
|
|
}
|
|
|
|
return suite.getCamera()
|
|
.then(triggerSystemFailure, suite.rejectGetCamera)
|
|
.then(releaseCamera)
|
|
.then(releasedCamera, suite.rejectRelease);
|
|
});
|
|
|
|
suite.setup()
|
|
.then(suite.run);
|
|
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|