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.

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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test MediaRecorder fires an event after changing state</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;

/**
 * The flow of test is start()=>pause()=>resume()=>stop(). In each steps,
 * this test verifies whether each MediaRecorder methods properly change
 * its state before firing an event. Checking the state is done in the
 * corresponding event handlers.
 */
function startTest(test, token) {
  var element = document.createElement('audio');

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

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

  var mediaRecorder = new MediaRecorder(element.stream);

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

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

  mediaRecorder.onstart = function() {
    info('onstart fired successfully');
    is(mediaRecorder.state, 'recording',
        'Media Recorder changes state to recording before firing a start event');
    mediaRecorder.pause();
  };

  mediaRecorder.onpause = function() {
    info('onpause fired successfully');
    is(mediaRecorder.state, 'paused',
        'Media Recorder changes state to paused before firing a pause event');
    mediaRecorder.resume();
  };

  mediaRecorder.onresume = function() {
    info('onresume fired successfully');
    is(mediaRecorder.state, 'recording',
        'Media Recorder changes state to recording before firing a resume event');
    mediaRecorder.stop();
  };

  mediaRecorder.onstop = function() {
    info('onstop fired successfully');
    is(mediaRecorder.state, 'inactive',
        'Media Recorder changes state to inactive before firing a stop event');
    SimpleTest.finish();
  };

  // Call start() once metadata are parsed.
  element.onloadedmetadata = function() {
    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');
  };
}

manager.runTests(gMediaRecorderTests, startTest);

</script>
</pre>
</body>
</html>