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 (c68fe15a81fc)

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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test MediaRecorder Record gUM video with 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="gUM_support.js"></script>
</head>
<body>
<pre id="test">
<div id="content" style="display: none">
</div>
<script class="testbody" type="text/javascript">

async function startTest() {
  try {
    await setupGetUserMediaTestPrefs();
    let stream = await navigator.mediaDevices.getUserMedia({audio: true, video: true});
    let dataAvailableCount = 0;
    let onDataAvailableFirst = false;
    const expectedMimeType = 'video/webm; codecs="vp8, opus"';

    let mediaRecorder = new MediaRecorder(stream);
    is(mediaRecorder.stream, stream,
       'Media recorder stream = element stream at the start of recording');
    mediaRecorder.onwarning = function() {
      ok(false, 'onwarning unexpectedly fired');
    };

    mediaRecorder.onerror = function() {
      ok(false, 'onerror unexpectedly fired');
    };

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

    mediaRecorder.onstart = function() {
      is(mediaRecorder.mimeType, expectedMimeType, 'Expected mime type');
    };

    mediaRecorder.ondataavailable = function (evt) {
      info('ondataavailable fired');
      dataAvailableCount++;

      ok(evt instanceof BlobEvent,
         'Events fired from ondataavailable should be BlobEvent');
      is(evt.type, 'dataavailable',
         'Event type should dataavailable');
      ok(evt.data.size >= 0,
         'Blob data size ' + evt.data.size + ' received is greater than or equal to zero');
      is(evt.data.type, expectedMimeType, 'Expected blob mime type');

      // We'll stop recording upon the 1st blob being received
      if (dataAvailableCount === 1) {
        mediaRecorder.onstop = function (event) {
          info('onstop fired');

          if (!onDataAvailableFirst) {
            ok(false, 'onstop unexpectedly fired before ondataavailable');
          }

          ok(true, 'onstop fired successfully');
          is(mediaRecorder.state, 'inactive',
             'check recording status is inactive');
          SimpleTest.finish();
        };

        mediaRecorder.stop();
        is(mediaRecorder.state, 'inactive',
           'Media recorder is inactive after being stopped');

      } else if (dataAvailableCount === 2) {
        // Ensure we've received at least two ondataavailable events before
        // onstop
        onDataAvailableFirst = true;
      }
    };

    mediaRecorder.start(250);
    is(mediaRecorder.state, 'recording', 'Media recorder should be recording');
    is(mediaRecorder.mimeType, '', 'Expected mime type');
  } catch (err) {
    ok(false, 'Unexpected error fired with: ' + err);
    SimpleTest.finish();
  }
}

SimpleTest.waitForExplicitFinish();
startTest();
</script>
</pre>
</body>
</html>