Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<title>Test MediaRecorder Record No Timeslice</title>
<script 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>
<pre id="test">
<script class="testbody" type="text/javascript">
var manager = new MediaTestManager;
* Starts a test on every media recorder file included to check that a
* stream derived from the file can be recorded with no time slice provided.
function startTest(test, token) {
var element = document.createElement('audio');
var expectedMimeType = test.type;
element.token = token;
element.src =;
element.test = test; = element.mozCaptureStreamUntilEnded();
var mediaRecorder =
new MediaRecorder(, {mimeType: expectedMimeType});
var onStopFired = false;
var onDataAvailableFired = false;
mediaRecorder.onerror = function () {
ok(false, 'Unexpected onerror callback fired');
mediaRecorder.onwarning = function () {
ok(false, 'Unexpected onwarning callback fired');
// This handler verifies that only a single onstop event handler is fired.
mediaRecorder.onstop = function () {
if (onStopFired) {
ok(false, 'onstop unexpectedly fired more than once');
} else {
onStopFired = true;
// ondataavailable should always fire before onstop
if (onDataAvailableFired) {
ok(true, 'onstop fired after ondataavailable');
} else {
ok(false, 'onstop fired without an ondataavailable event first');
// This handler verifies that only a single ondataavailable event handler
// is fired with the blob generated having greater than zero size
// and a correct mime type.
mediaRecorder.ondataavailable = function (evt) {
if (onDataAvailableFired) {
ok(false, 'ondataavailable unexpectedly fired more than once');
} else {
onDataAvailableFired = true;
ok(evt instanceof BlobEvent,
'Events fired from ondataavailable should be BlobEvent');
is(evt.type, 'dataavailable',
'Event type should dataavailable');
ok( > 0,
'Blob data received should be greater than zero');
is(, expectedMimeType,
'Blob data received should have type = ' + expectedMimeType);
is(mediaRecorder.mimeType, expectedMimeType,
'Mime type in ondataavailable = ' + expectedMimeType);
// onstop should not have fired before ondataavailable
if (onStopFired) {
ok(false, 'ondataavailable unexpectedly fired later than onstop');
element.preload = "metadata";
element.onloadedmetadata = function () {
element.onloadedmetadata = null;
is(mediaRecorder.state, 'recording',
'Media recorder should be recording');
'Media recorder stream = element stream at the start of recording');;
manager.runTests(gMediaRecorderTests, startTest);