dom/media/test/test_mediarecorder_record_getdata_afterstart.html
author Dorel Luca <dluca@mozilla.com>
Sat, 12 Jan 2019 01:28:30 +0200
changeset 453595 c45da646fc6140bd59a36bda18f6cecde6163feb
parent 251702 b00a687ec1f2a00c943c7a61d74006d9ed651f74
child 469641 ba6f655fd68963530c866d0d4a48c3db3d307777
permissions -rw-r--r--
Backed out changeset 24243f13c895 (bug 1519308) for build bustage in mozbuild/mozbuild/test/configure/test_checks_configure.py. CLOSED TREE

<!DOCTYPE HTML>
<html>
<head>
  <title>Bug 951008 Test MediaRecorder Record has start event</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>
</head>
<body>

<script class="testbody" type="text/javascript">

var manager = new MediaTestManager;

function startTest(test, token) {

  var element = document.createElement('audio');
  var hasonstart = false;
  var hasondataavailable = false;
  var mMediaRecorder;

  element.token = token;
  manager.started(token);
  element.src = test.name;
  element.test = test;
  element.stream = element.mozCaptureStream();

  mMediaRecorder = new MediaRecorder(element.stream);
  mMediaRecorder.onwarning = function() {
    ok(false, 'onwarning unexpectedly fired');
  };

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

  mMediaRecorder.onstart = function() {
    info('onstart fired successfully');
    hasonstart = true;
    // On audio only case, we produce audio/ogg as mimeType.
    is('audio/ogg', mMediaRecorder.mimeType, "check the record mimetype return " + mMediaRecorder.mimeType);
    mMediaRecorder.requestData();
  };

  mMediaRecorder.onstop = function() {
    info('onstop fired successfully');
    ok (hasondataavailable, "should have ondataavailable before onstop");
    is(mMediaRecorder.state, 'inactive', 'check recording status is inactive');
    SimpleTest.finish();
  };

  mMediaRecorder.ondataavailable = function (e) {
    info('ondataavailable fired successfully');
    if (mMediaRecorder.state == 'recording') {
      hasondataavailable = true;
      ok(hasonstart, "should has onstart event first");
      ok(e.data.size > 0, 'check blob has data');
      mMediaRecorder.stop();
    }
  };

  // Start recording once metadata are parsed.
  element.onloadedmetadata = function() {
    element.oncanplaythrough = null;
    mMediaRecorder.start(0);
    is(mMediaRecorder.state, 'recording', 'Media recorder should be recording');
    is(mMediaRecorder.stream, element.stream,
       'Media recorder stream = element stream at the start of recording');
    };

  element.play();
}

manager.runTests(gMediaRecorderTests, startTest);

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