Source code

Revision control

Other Tools

Test Info: Warnings

  • This test gets skipped with pattern: (os == "win" && processor == "aarch64")
<title>Bug 957439 - Media Recording - Assertion fail at Pause if unsupported input stream.</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>
<script type="text/javascript" src="gUM_support.js"></script>
<a target="_blank" href="">Mozilla Bug 957439</a>
<pre id="test">
<script class="testbody" type="text/javascript">
function unexpected(e) {
ok(false, `Got unexpected ${e.type} event`);
async function startTest() {
// also do general checks on mimetype support for audio-only
'Should support audio/ogg');
ok(MediaRecorder.isTypeSupported('audio/ogg; codecs=opus'),
'Should support audio/ogg+opus');
ok(!MediaRecorder.isTypeSupported('audio/ogg; codecs=foobar'),
'Should not support audio/ogg + unknown_codec');
'Should support video/webm');
'Should not support video/mp4');
try {
await setupGetUserMediaTestPrefs();
const expectedMimeType = 'video/webm; codecs="vp8, opus"';
const stream = await navigator.mediaDevices.getUserMedia({audio: true, video: true});
const [audioTrack] = stream.getAudioTracks();
// Expected event sequence should be:
// 1. start
// 2. error (from removed track)
// 3. dataavailable
// 4. stop
const mediaRecorder = new MediaRecorder(stream);
is(, stream, 'Stream should be provided on creation');
mediaRecorder.onstart = unexpected;
mediaRecorder.onerror = unexpected;
mediaRecorder.ondataavailable = unexpected;
mediaRecorder.onstop = unexpected;
is(mediaRecorder.state, 'recording', 'state should be recording');
is(mediaRecorder.mimeType, '', 'mimetype should be unset');
await new Promise(r => mediaRecorder.onstart = r);
mediaRecorder.onstart = unexpected;
ok(true, 'start event fired');
is(mediaRecorder.mimeType, expectedMimeType, 'mimetype should be set');
// Trigger an error
const err = await new Promise(r => mediaRecorder.onerror = r);
mediaRecorder.onerror = unexpected;
ok(true, 'error event fired');
is(, 'InvalidModificationError',
'Error name should be InvalidModificationError.');
'Events fired from onerror should include an error with a stack trace indicating ' +
'an error in this test');
is(mediaRecorder.mimeType, '', 'mimetype should be unset');
is(mediaRecorder.state, 'inactive', 'state is inactive');
try {
ok(false, 'pause should fire an exception if called on an inactive recorder');
} catch(e) {
ok(e instanceof DOMException, 'pause should fire an exception ' +
'if called on an inactive recorder');
is(, 'InvalidStateError', 'Exception name should be InvalidStateError');
const evt = await new Promise(r => mediaRecorder.ondataavailable = r);
mediaRecorder.ondataavailable = unexpected;
ok(true, 'dataavailable event fired');
isnot(, 0, 'data size should not be zero');
ok(evt instanceof BlobEvent,
'Events fired from ondataavailable should be BlobEvent');
is(, expectedMimeType, 'blob mimeType is set');
await new Promise(r => mediaRecorder.onstop = r);
mediaRecorder.onstop = unexpected;
ok(true, 'onstop event fired');
is(mediaRecorder.state, 'inactive', 'state should be inactive');
} catch (err) {
ok(false, `Unexpected error fired with: ${err}`);
} finally {
window.onload = startTest;