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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
<!DOCTYPE HTML>
<html>
<head>
  <title>Test MediaRecorder Immediate Stop</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>
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
var manager = new MediaTestManager;

/**
 * Stops the media recorder immediately after starting the recorder. This test
 * verifies whether the media recorder can handle this scenario nicely. The
 * return blob size should be greater than zero, but its duration would be zero
 * length when play.
 */
function startTest(test, token) {
  var element = document.createElement('audio');
  var expectedMimeType = test.type;

  element.token = token;
  manager.started(token);

  element.src = test.name;
  element.test = test;
  element.stream = element.mozCaptureStreamUntilEnded();

  var mediaRecorder =
    new MediaRecorder(element.stream, {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) {
        manager.finished(token);
      } 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');

      // The initialization of encoder can be cancelled.
      // On some platforms, the stop method may run after media stream track
      // available, so the blob can contain the header data.
      is(evt.data.type, expectedMimeType,
         'Blob data received and should have mime type');
      is(mediaRecorder.mimeType, expectedMimeType,
         'Media Recorder mime type in ondataavailable = ' + expectedMimeType);
      ok(evt.data.size >= 0, 'Blob size can not be negative');

      // onstop should not have fired before ondataavailable
      if (onStopFired) {
        ok(false, 'ondataavailable unexpectedly fired later than onstop');
        manager.finished(token);
      }
    }
  };

  // This handler completes a start and stop of recording and verifies
  // respective media recorder state.
  element.onloadedmetadata = function () {
    element.onloadedmetadata = null;
    element.play();
    mediaRecorder.start();
    is(mediaRecorder.state, 'recording', 'Media recorder should be recording');
    is(mediaRecorder.stream, element.stream,
       'Media recorder stream = element stream at the start of recording');

    mediaRecorder.stop();
    is(mediaRecorder.state, 'inactive',
       'Media recorder is inactive after being stopped');
    is(mediaRecorder.stream, element.stream,
       'Media recorder stream = element stream post recording');
  };

  element.preload = "metadata";
}

manager.runTests(gMediaRecorderTests, startTest);
</script>
</pre>
</body>
</html>