Bug 957439 - Do not assert at Pause or Resume on unsupported input stream. r=roc, r=jsmith

This commit is contained in:
Shelly Lin 2014-01-27 10:33:00 +08:00
parent 6a6aa3a1ea
commit c773010da1
3 changed files with 109 additions and 10 deletions

View File

@ -230,18 +230,20 @@ public:
nsContentUtils::UnregisterShutdownObserver(this);
}
void Pause()
nsresult Pause()
{
MOZ_ASSERT(NS_IsMainThread() && mTrackUnionStream);
NS_ENSURE_TRUE(NS_IsMainThread() && mTrackUnionStream, NS_ERROR_FAILURE);
mTrackUnionStream->ChangeExplicitBlockerCount(-1);
return NS_OK;
}
void Resume()
nsresult Resume()
{
MOZ_ASSERT(NS_IsMainThread() && mTrackUnionStream);
NS_ENSURE_TRUE(NS_IsMainThread() && mTrackUnionStream, NS_ERROR_FAILURE);
mTrackUnionStream->ChangeExplicitBlockerCount(1);
return NS_OK;
}
already_AddRefed<nsIDOMBlob> GetEncodedData()
@ -499,11 +501,13 @@ MediaRecorder::Pause(ErrorResult& aResult)
return;
}
mState = RecordingState::Paused;
MOZ_ASSERT(mSession != nullptr);
if (mSession) {
mSession->Pause();
nsresult rv = mSession->Pause();
if (NS_FAILED(rv)) {
NotifyError(rv);
return;
}
mState = RecordingState::Paused;
}
}
@ -518,7 +522,11 @@ MediaRecorder::Resume(ErrorResult& aResult)
MOZ_ASSERT(mSession != nullptr);
if (mSession) {
mSession->Resume();
nsresult rv = mSession->Resume();
if (NS_FAILED(rv)) {
NotifyError(rv);
return;
}
mState = RecordingState::Recording;
}
}

View File

@ -256,6 +256,7 @@ support-files =
[test_mediarecorder_reload_crash.html]
[test_mediarecorder_record_immediate_stop.html]
[test_mediarecorder_record_session.html]
[test_mediarecorder_unsupported_src.html]
[test_playback.html]
[test_seekLies.html]
[test_media_sniffer.html]

View File

@ -0,0 +1,90 @@
<html>
<head>
<title>Bug 957439 - Media Recording - Assertion fail at Pause if unsupported input stream.</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript" src="manifest.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=957439">Mozilla Bug 957439</a>
<pre id="test">
<script class="testbody" type="text/javascript">
function startTest() {
navigator.mozGetUserMedia({audio: false, video: true, fake: true},
function(stream) {
// Expected callback sequence should be:
// 1. onerror (from start)
// 2. onerror (from pause)
// 3. ondataavailable
// 4. onstop
var callbackStep = 0;
var mediaRecorder = new MediaRecorder(stream);
is(mediaRecorder.stream, stream, 'Stream should be provided on creation');
mediaRecorder.onerror = function (e) {
callbackStep++;
ok(callbackStep < 3, 'onerror callback fired as expected.');
is(e.name, 'GenericError', 'Error name should be GenericError.');
is(mediaRecorder.mimeType, '', 'mimetype should be empty');
is(mediaRecorder.state, 'recording', 'state is recording');
info('onerror callback fired');
}
mediaRecorder.onwarning = function () {
ok(false, 'Unexpected onwarning callback fired.');
};
mediaRecorder.ondataavailable = function (evt) {
callbackStep++;
info('ondataavailable callback fired');
is(callbackStep, 3, 'should fired ondataavailable callback');
is(evt.data.size, 0, 'data size should be zero');
ok(evt instanceof BlobEvent,
'Events fired from ondataavailable should be BlobEvent');
is(evt.data.type, '', 'encoder start fail, blob miemType should be empty');
};
mediaRecorder.onstop = function() {
callbackStep++;
info('onstop callback fired');
is(mediaRecorder.state, 'inactive', 'state should be inactive');
is(callbackStep, 4, 'should fired onstop callback');
SimpleTest.finish();
};
try {
mediaRecorder.start();
} catch(e) {
ok(false, 'Should not get exception in start call.');
}
try {
mediaRecorder.pause();
} catch(e) {
ok(false, 'Should not get exception in pause call.');
}
},
function(err) {
ok(false, 'Unexpected error fired with: ' + err);
SimpleTest.finish();
}
);
}
SimpleTest.waitForExplicitFinish();
// In order to generate an "unsupported stream", pref off video encoding to
// make the platform support audio encoding only.
SpecialPowers.pushPrefEnv(
{
"set": [
["media.encoder.webm.enabled", false]
]
}, startTest);
</script>
</head>
</html>