mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-11-20 10:33:36 +00:00
209 lines
6.0 KiB
HTML
209 lines
6.0 KiB
HTML
|
<!DOCTYPE HTML>
|
||
|
<html>
|
||
|
<head>
|
||
|
<title>Test Camera Recording</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();
|
||
|
|
||
|
var baseConfig = {
|
||
|
mode: 'video',
|
||
|
};
|
||
|
|
||
|
var testFilePath = 'test.3gp';
|
||
|
var storage = navigator.getDeviceStorage("videos");
|
||
|
|
||
|
function cleanup()
|
||
|
{
|
||
|
return storage.delete(testFilePath).then(function(p) {
|
||
|
}, function(e) {
|
||
|
Promise.resolve();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
suite.test('recording', function() {
|
||
|
function startRecording(p) {
|
||
|
var eventPromise = new Promise(function(resolve, reject) {
|
||
|
function onEvent(evt) {
|
||
|
ok(evt.newState === 'Started', 'recorder state change event = ' + evt.newState);
|
||
|
suite.camera.removeEventListener('recorderstatechange', onEvent);
|
||
|
resolve();
|
||
|
}
|
||
|
suite.camera.addEventListener('recorderstatechange', onEvent);
|
||
|
});
|
||
|
|
||
|
var domPromise = suite.camera.startRecording({}, storage, testFilePath);
|
||
|
return Promise.all([domPromise, eventPromise]);
|
||
|
}
|
||
|
|
||
|
function pauseRecording(p) {
|
||
|
var eventPromise = new Promise(function(resolve, reject) {
|
||
|
function onEvent(evt) {
|
||
|
ok(evt.newState === 'Paused', 'recorder state change event = ' + evt.newState);
|
||
|
suite.camera.removeEventListener('recorderstatechange', onEvent);
|
||
|
resolve();
|
||
|
}
|
||
|
suite.camera.addEventListener('recorderstatechange', onEvent);
|
||
|
});
|
||
|
|
||
|
var domPromise = new Promise(function(resolve, reject) {
|
||
|
try {
|
||
|
suite.camera.pauseRecording();
|
||
|
resolve();
|
||
|
} catch(e) {
|
||
|
reject(e);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return Promise.all([domPromise, eventPromise]);
|
||
|
}
|
||
|
|
||
|
function resumeRecording(p) {
|
||
|
var eventPromise = new Promise(function(resolve, reject) {
|
||
|
function onEvent(evt) {
|
||
|
ok(evt.newState === 'Resumed', 'recorder state change event = ' + evt.newState);
|
||
|
suite.camera.removeEventListener('recorderstatechange', onEvent);
|
||
|
resolve();
|
||
|
}
|
||
|
suite.camera.addEventListener('recorderstatechange', onEvent);
|
||
|
});
|
||
|
|
||
|
var domPromise = new Promise(function(resolve, reject) {
|
||
|
try {
|
||
|
suite.camera.resumeRecording();
|
||
|
resolve();
|
||
|
} catch(e) {
|
||
|
reject(e);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return Promise.all([domPromise, eventPromise]);
|
||
|
}
|
||
|
|
||
|
function stopRecording(p) {
|
||
|
var eventPromise = new Promise(function(resolve, reject) {
|
||
|
function onEvent(evt) {
|
||
|
ok(evt.newState === 'Stopped', 'recorder state change event = ' + evt.newState);
|
||
|
suite.camera.removeEventListener('recorderstatechange', onEvent);
|
||
|
resolve();
|
||
|
}
|
||
|
suite.camera.addEventListener('recorderstatechange', onEvent);
|
||
|
});
|
||
|
|
||
|
var domPromise = new Promise(function(resolve, reject) {
|
||
|
try {
|
||
|
suite.camera.stopRecording();
|
||
|
resolve();
|
||
|
} catch(e) {
|
||
|
reject(e);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return Promise.all([domPromise, eventPromise]);
|
||
|
}
|
||
|
|
||
|
return suite.getCamera(undefined, baseConfig)
|
||
|
.then(cleanup, suite.rejectGetCamera)
|
||
|
.then(startRecording)
|
||
|
.then(pauseRecording, suite.rejectStartRecording)
|
||
|
.then(resumeRecording, suite.rejectPauseRecording)
|
||
|
.then(stopRecording, suite.rejectResumeRecording)
|
||
|
.catch(suite.rejectStopRecording);
|
||
|
});
|
||
|
|
||
|
// bug 1152500
|
||
|
suite.test('interrupt-record', function() {
|
||
|
function startRecording(p) {
|
||
|
var startPromise = suite.camera.startRecording({}, storage, testFilePath);
|
||
|
suite.camera.stopRecording();
|
||
|
return startPromise;
|
||
|
}
|
||
|
|
||
|
function rejectStartRecording(e) {
|
||
|
ok(e.name === 'NS_ERROR_ABORT', 'onError called correctly on startRecording interrupted: ' + e);
|
||
|
}
|
||
|
|
||
|
return suite.getCamera(undefined, baseConfig)
|
||
|
.then(cleanup, suite.rejectGetCamera)
|
||
|
.then(startRecording)
|
||
|
.then(suite.expectedRejectStartRecording, rejectStartRecording);
|
||
|
});
|
||
|
|
||
|
// bug 1152500
|
||
|
suite.test('already-initiated-recording', function() {
|
||
|
function startRecording(p) {
|
||
|
return new Promise(function(resolve, reject) {
|
||
|
var firstCall = false;
|
||
|
var secondCall = false;
|
||
|
|
||
|
function end() {
|
||
|
if (firstCall && secondCall) {
|
||
|
resolve();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
suite.camera.startRecording({}, storage, testFilePath).then(function(p) {
|
||
|
ok(true, "First call to startRecording() succeeded");
|
||
|
firstCall = true;
|
||
|
end();
|
||
|
}, function(e) {
|
||
|
ok(false, "First call to startRecording() failed unexpectedly with: " + e);
|
||
|
firstCall = true;
|
||
|
end();
|
||
|
});
|
||
|
|
||
|
suite.camera.startRecording({}, storage, testFilePath).then(function(p) {
|
||
|
ok(false, "Second call to startRecording() succeeded unexpectedly");
|
||
|
secondCall = true;
|
||
|
end();
|
||
|
}, function(e) {
|
||
|
ok(e.name === 'NS_ERROR_IN_PROGRESS', "Second call to startRecording() failed expectedly with: " + e);
|
||
|
secondCall = true;
|
||
|
end();
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
|
||
|
return suite.getCamera(undefined, baseConfig)
|
||
|
.then(cleanup, suite.rejectGetCamera)
|
||
|
.then(startRecording);
|
||
|
});
|
||
|
|
||
|
// bug 1152500
|
||
|
suite.test('already-started-recording', function() {
|
||
|
function startRecording(p) {
|
||
|
return suite.camera.startRecording({}, storage, testFilePath);
|
||
|
}
|
||
|
|
||
|
function startRecordingAgain(p) {
|
||
|
return suite.camera.startRecording({}, storage, testFilePath);
|
||
|
}
|
||
|
|
||
|
function rejectStartRecordingAgain(e) {
|
||
|
ok(e.name === 'NS_ERROR_IN_PROGRESS', "Second call to startRecording() failed expectedly with: " + e);
|
||
|
}
|
||
|
|
||
|
return suite.getCamera(undefined, baseConfig)
|
||
|
.then(cleanup, suite.rejectGetCamera)
|
||
|
.then(startRecording)
|
||
|
.then(startRecordingAgain, suite.rejectStartRecording)
|
||
|
.then(suite.expectedRejectStartRecording, rejectStartRecordingAgain)
|
||
|
});
|
||
|
|
||
|
suite.setup()
|
||
|
.then(suite.run);
|
||
|
|
||
|
</script>
|
||
|
</body>
|
||
|
|
||
|
</html>
|