gecko-dev/dom/camera/test/test_bug975472.html

184 lines
5.1 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test for bug 975472</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>
<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();
function cameraRelease(p) {
return suite.camera.release();
}
suite.test('release-after-release', function() {
return suite.getCamera()
.then(cameraRelease, suite.rejectGetCamera)
.then(cameraRelease, suite.rejectRelease)
.catch(suite.rejectRelease);
});
suite.test('set-picture-size-after-release', function() {
function setPictureSize(p) {
try {
suite.camera.setPictureSize({ width: 0, height: 0 });
ok(false, "SetPictureSize() should have failed");
} catch(e) {
ok(e.result === SpecialPowers.Cr.NS_ERROR_NOT_AVAILABLE,
"setPictureSize() failed with: " + e.name);
}
}
return suite.getCamera()
.then(cameraRelease, suite.rejectGetCamera)
.then(setPictureSize, suite.rejectRelease);
});
suite.test('set-thumbnail-size-after-release', function() {
function setThumbnailSize(p) {
try {
suite.camera.setThumbnailSize({ width: 0, height: 0 });
ok(false, "SetThumbnailSize() should have failed");
} catch(e) {
ok(e.result === SpecialPowers.Cr.NS_ERROR_NOT_AVAILABLE,
"setThumbnailSize() failed with: " + e.name);
}
}
return suite.getCamera()
.then(cameraRelease, suite.rejectGetCamera)
.then(setThumbnailSize, suite.rejectRelease);
});
suite.test('get-sensor-angle-after-release', function() {
function getSensorAngle(p) {
ok(suite.camera.sensorAngle == 0, "camera.sensorAngle = " + suite.camera.sensorAngle);
}
return suite.getCamera()
.then(cameraRelease, suite.rejectGetCamera)
.then(getSensorAngle, suite.rejectRelease);
});
suite.test('resume-preview-after-release', function() {
function resumePreview(p) {
try {
suite.camera.resumePreview();
ok(false, "resumePreview() should have failed");
} catch(e) {
ok(e.result === SpecialPowers.Cr.NS_ERROR_NOT_AVAILABLE,
"resumePreview() failed with: " + e.name);
}
}
return suite.getCamera()
.then(cameraRelease, suite.rejectGetCamera)
.then(resumePreview, suite.rejectRelease);
});
suite.test('auto-focus-after-release', function() {
function autoFocus(p) {
return suite.camera.autoFocus();
}
function rejectAutoFocus(error) {
ok(error.name === "NS_ERROR_NOT_AVAILABLE",
"autoFocus() failed with: " + error.name);
return Promise.resolve();
}
return suite.getCamera()
.then(cameraRelease, suite.rejectGetCamera)
.then(autoFocus, suite.rejectRelease)
.then(suite.expectedRejectAutoFocus, rejectAutoFocus);
});
suite.test('take-picture-after-release', function() {
function takePicture(p) {
return suite.camera.takePicture(null);
}
function rejectTakePicture(error) {
ok(error.name === "NS_ERROR_NOT_AVAILABLE",
"takePicture() failed with: " + error.name);
return Promise.resolve();
}
return suite.getCamera()
.then(cameraRelease, suite.rejectGetCamera)
.then(takePicture, suite.rejectRelease)
.then(suite.expectedRejectTakePicture, rejectTakePicture);
});
suite.test('start-recording-after-release', function() {
function startRecording(p) {
return suite.camera.startRecording(
{
profile: 'high',
rotation: 0
},
navigator.getDeviceStorage('videos'),
'bug975472.mp4'
);
}
function rejectStartRecording(error) {
ok(error.name === "NS_ERROR_NOT_AVAILABLE",
"takePicture() failed with: " + error.name);
return Promise.resolve();
}
return suite.getCamera()
.then(cameraRelease, suite.rejectGetCamera)
.then(startRecording, suite.rejectRelease)
.then(suite.expectedRejectStartRecording, rejectStartRecording);
});
suite.test('stop-recording-after-release', function() {
function stopRecording(p) {
try {
suite.camera.stopRecording();
ok(false, "stopRecording() should have failed");
} catch(e) {
ok(e.result === SpecialPowers.Cr.NS_ERROR_NOT_AVAILABLE,
"stopRecording() failed with: " + e.name);
}
}
return suite.getCamera()
.then(cameraRelease, suite.rejectGetCamera)
.then(stopRecording, suite.rejectRelease);
});
suite.test('set-configuration-after-release', function() {
function configure(p) {
return suite.camera.setConfiguration(null);
}
function rejectConfigure(error) {
ok(error.name === "NS_ERROR_NOT_AVAILABLE",
"takePicture() failed with: " + error.name);
return Promise.resolve();
}
return suite.getCamera()
.then(cameraRelease, suite.rejectGetCamera)
.then(configure, suite.rejectRelease)
.then(suite.expectedRejectConfigure, rejectConfigure);
});
suite.setup()
.then(suite.run);
</script>
</body>
</html>