author Dorel Luca <>
Sat, 12 Jan 2019 01:28:30 +0200
changeset 453595 c45da646fc6140bd59a36bda18f6cecde6163feb
parent 410502 378575c7b83768c79692c86e3e25707fcf528efe
child 469641 ba6f655fd68963530c866d0d4a48c3db3d307777
permissions -rw-r--r--
Backed out changeset 24243f13c895 (bug 1519308) for build bustage in mozbuild/mozbuild/test/configure/ CLOSED TREE

  <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>
  <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">

async function startTest() {
  // also do general checks on mimetype support for audio-only
  ok(MediaRecorder.isTypeSupported("audio/ogg"), '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');
  ok(!MediaRecorder.isTypeSupported("video/webm"), 'Should not support video/webm');
  ok(!MediaRecorder.isTypeSupported("video/mp4"), 'Should not support video/mp4');

  try {
    await setupGetUserMediaTestPrefs();
    let stream = await navigator.mediaDevices.getUserMedia({audio: false, video: true});

    // Expected callback sequence should be:
    // 1. onerror (from start)
    // 2. ondataavailable
    // 3. onstop
    let callbackStep = 0;
    let mediaRecorder = new MediaRecorder(stream);

    is(, stream, 'Stream should be provided on creation');

    mediaRecorder.onerror = function (e) {
      info('onerror callback fired');
      if (callbackStep == 1) {
        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');
      ok(callbackStep == 1, 'onerror callback should handle be the 1st event fired');
      is(, 'UnknownError', 'Error name should be UnknownError.');
        'Events fired from onerror should include an error with a stack trace indicating ' +
        'an error in this test');
      is(mediaRecorder.mimeType, '', 'mimetype should be empty');
      is(mediaRecorder.state, 'inactive', 'state is inactive');

    mediaRecorder.onwarning = function () {
      ok(false, 'Unexpected onwarning callback fired.');

    mediaRecorder.ondataavailable = function (evt) {
      info('ondataavailable callback fired');
      is(callbackStep, 2, 'ondataavailable callback should handle the 2nd event fired');
      is(, 0, 'data size should be zero');
      ok(evt instanceof BlobEvent,
          'Events fired from ondataavailable should be BlobEvent');
      is(, '', 'encoder start fail, blob miemType should be empty');

    mediaRecorder.onstop = function() {
      info('onstop callback fired');
      is(mediaRecorder.state, 'inactive', 'state should be inactive');
      is(callbackStep, 3, 'onstop callback should handle the 3rd event fired');

    try {
    } catch(e) {
      ok(false, 'Should not get exception in start call.');
  } catch (err) {
    ok(false, 'Unexpected error fired with: ' + err);


// In order to generate an "unsupported stream", pref off video encoding to
// make the platform support audio encoding only.
    "set": [
      ["media.encoder.webm.enabled", false],
  }, startTest);