Bug 898952 - Media Recording - Avoid to record a stopped MediaStream. r=roc

This commit is contained in:
Randy Lin 2013-08-07 14:20:42 +08:00
parent a98d95a71e
commit 2f37b2b995
3 changed files with 53 additions and 0 deletions

View File

@ -166,6 +166,11 @@ MediaRecorder::Start(const Optional<int32_t>& aTimeSlice, ErrorResult& aResult)
return;
}
if (mStream->GetStream()->IsFinished() || mStream->GetStream()->IsDestroyed()) {
aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
if (aTimeSlice.WasPassed()) {
if (aTimeSlice.Value() < 0) {
aResult.Throw(NS_ERROR_INVALID_ARG);

View File

@ -117,6 +117,7 @@ MOCHITEST_FILES = \
test_audiowrite.html \
test_mediarecorder_creation.html \
test_mediarecorder_record_audiocontext.html \
test_mediarecorder_record_stopms.html \
test_mozHasAudio.html \
test_source_media.html \
test_autoplay_contentEditable.html \

View File

@ -0,0 +1,47 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test MediaRecorder Record Stopped Stream</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<div id="content" style="display: none">
<audio id="testAudio"></audio>
</div>
<script class="testbody" type="text/javascript">
function startTest() {
navigator.mozGetUserMedia({audio: true, fake: true}, function(stream) {
var testAudio = document.getElementById('testAudio');
testAudio.onended = function() {
var mediaRecorder = new MediaRecorder(stream);
try {
mediaRecorder.start();
ok(false, 'Recording a stopped stream failed to throw an exception');
} catch (e) {
is(e.name, 'InvalidStateError',
'Recording a stopped stream threw an InvalidStateError');
} finally {
SimpleTest.finish();
}
};
testAudio.mozSrcObject = stream;
testAudio.play();
stream.stop();
}, function(err) {
ok(false, 'Unexpected error fired with: ' + err);
SimpleTest.finish();
});
}
SimpleTest.waitForExplicitFinish();
startTest();
</script>
</pre>
</body>
</html>