DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (409f3966645a)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
<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>
  <script type="text/javascript" src="gUM_support.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">


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(mediaRecorder.stream, stream, 'Stream should be provided on creation');

    mediaRecorder.onerror = function (e) {
      callbackStep++;
      info('onerror callback fired');
      if (callbackStep == 1) {
        try {
          mediaRecorder.pause();
          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(e.name, 'InvalidStateError', 'Exception name should be InvalidStateError');
        }
      }
      ok(callbackStep == 1, 'onerror callback should handle be the 1st event fired');
      is(e.error.name, 'UnknownError', 'Error name should be UnknownError.');
      ok(e.error.stack.includes('test_mediarecorder_unsupported_src.html'),
        '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) {
      callbackStep++;
      info('ondataavailable callback fired');
      is(callbackStep, 2, 'ondataavailable callback should handle the 2nd event fired');
      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, 3, 'onstop callback should handle the 3rd event fired');
      SimpleTest.finish();
    };

    try {
      mediaRecorder.start();
    } catch(e) {
      ok(false, 'Should not get exception in start call.');
    }
  } catch (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>