Bug 957841 - Test case for MediaRecorder crash [@ mozilla::dom::MediaRecorder::Session::AfterTracksAdded]. r=jsmith

This commit is contained in:
Randy Lin 2014-01-29 23:09:46 +08:00
parent 0c268a1465
commit 70966ac27f
2 changed files with 77 additions and 0 deletions

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_record_startstopstart.html]
[test_mediarecorder_unsupported_src.html]
[test_playback.html]
[test_seekLies.html]

View File

@ -0,0 +1,76 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test MediaRecorder crash on sequence start stop start method</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">
</div>
<script class="testbody" type="text/javascript">
function startTest() {
var ac = new window.AudioContext();
var dest = ac.createMediaStreamDestination();
var recorder = new MediaRecorder(dest.stream);
var stopCount = 0;
var dataavailable = 0;
// mobile device may produce another format, but not landed.
// In audio only case, we should produce opus type.
var expectedMimeType = 'audio/ogg';
recorder.onstop = function (e) {
info('onstop fired');
is(recorder.stream, dest.stream,
'Media recorder stream = element stream post recording');
stopCount++;
if (stopCount == 2) {
is(2, dataavailable, 'Should has two dataavailable event');
SimpleTest.finish();
}
}
recorder.ondataavailable = function (evt) {
info('ondataavailable fired');
ok(evt instanceof BlobEvent,
'Events fired from ondataavailable should be BlobEvent');
is(evt.type, 'dataavailable',
'Event type should dataavailable');
// If script runs slower, it may generate header data in blob from encoder
if (evt.data.size > 0) {
info('blob size = ' + evt.data.size);
is(evt.data.type, expectedMimeType,
'Blob data received should have type = ' + expectedMimeType);
} else {
is(evt.data.type, '',
'Blob data received should have empty type');
}
dataavailable++;
}
recorder.onerror = function (e) {
ok(false, 'it should execute normally without exception');
}
recorder.onwarning = function() {
ok(false, 'onwarning unexpectedly fired');
};
recorder.start(2000);
is(recorder.state, 'recording', 'Media recorder should be recording');
recorder.stop();
is(recorder.state, 'inactive', 'check recording status is inactive');
recorder.start(10000); // This bug would crash on this line without this fix.
is(recorder.state, 'recording', 'check recording status is recording');
// Simulate delay stop, only delay stop no no stop can trigger crash.
setTimeout(function() {
recorder.stop();
is(recorder.state, 'inactive','check recording status is recording');
}, 1000);
}
startTest();
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>