dom/media/test/test_mediarecorder_record_audiocontext.html
author Jan-Ivar Bruaroey <jib@mozilla.com>
Tue, 14 Jul 2015 10:12:31 -0400
changeset 287631 79d3b8d912500dfc4705573c8036a0b9c91575f7
parent 283407 b00a687ec1f2a00c943c7a61d74006d9ed651f74
child 528458 ba6f655fd68963530c866d0d4a48c3db3d307777
permissions -rw-r--r--
Bug 1175523 - Update most (but not all) tests to use elem.srcObject over .mozSrcObject. r=pehrsons

<!DOCTYPE HTML>
<html>
<head>
  <title>Test MediaRecorder Record AudioContext</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">

function startTest() {
  var context = new AudioContext();
  var hasonstop = false;
  var buffer = context.createBuffer(1, 80920, context.sampleRate);
  for (var i = 0; i < 80920; ++i) {
    buffer.getChannelData(0)[i] = Math.sin(1000 * 2 * Math.PI * i / context.sampleRate);
  }

  var source = context.createBufferSource();
  source.buffer = buffer;
  source.loop = true;

  var dest = context.createMediaStreamDestination();
  source.connect(dest);
  var elem = document.createElement('audio');
  elem.srcObject = dest.stream;
  mMediaStream = dest.stream;
  source.start(0);
  elem.play();
  mMediaRecorder = new MediaRecorder(dest.stream);
  mMediaRecorder.onwarning = function() {
    ok(false, 'onwarning unexpectedly fired');
  };

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

  mMediaRecorder.onstop = function() {
    ok(true, 'onstop fired successfully');
    is(mMediaRecorder.state, 'inactive', 'check recording status is inactive');
    SimpleTest.finish();
  };
  mMediaRecorder.ondataavailable = function (e) {
    if (mMediaRecorder.state == 'recording') {
      is('audio/ogg', mMediaRecorder.mimeType, "check the record mimetype return " + mMediaRecorder.mimeType);
      ok(e.data.size > 0, 'check blob has data');
      mMediaRecorder.stop();
    }
  };
  try {
    mMediaRecorder.start(1000);
    is('recording', mMediaRecorder.state, "check record state recording");
  } catch (e) {
    ok(false, 'Can t record audio context');
  }
}

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