Bug 896353 - Media Recording - Test case for record the MediaStream from audioContext. r=jsmith
☠☠ backed out by 5aa02ee02f4b ☠ ☠
authorRandy Lin <rlin@mozilla.com>
Fri, 26 Jul 2013 10:47:56 +0800
changeset 140125 f2862e93b71017234ca2217cbe28d2d40b940eff
parent 140124 4fe81f58dbef639635e15d39a0ff33d56b3ce80d
child 140126 740efbc3485a87b9c873941ffd8651f5726eddad
push id1945
push userryanvm@gmail.com
push dateSat, 27 Jul 2013 02:27:26 +0000
treeherderfx-team@4874fa438b1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjsmith
bugs896353
milestone25.0a1
Bug 896353 - Media Recording - Test case for record the MediaStream from audioContext. r=jsmith
content/media/test/Makefile.in
content/media/test/test_mediarecorder_record_audiocontext.html
--- a/content/media/test/Makefile.in
+++ b/content/media/test/Makefile.in
@@ -111,16 +111,17 @@ MOCHITEST_FILES = \
 		test_source.html \
 		test_source_write.html \
 		test_source_null.html \
 		test_standalone.html \
 		test_volume.html \
 		test_video_to_canvas.html \
 		test_audiowrite.html \
 		test_mediarecorder_creation.html \
+		test_mediarecorder_record_audiocontext.html \
 		test_mozHasAudio.html \
 		test_source_media.html \
 		test_autoplay_contentEditable.html \
 		test_bug448534.html \
 		test_bug463162.xhtml \
 		test_decoder_disable.html \
 		test_mediarecorder_reload_crash.html \
 		test_media_selection.html \
new file mode 100644
--- /dev/null
+++ b/content/media/test/test_mediarecorder_record_audiocontext.html
@@ -0,0 +1,65 @@
+<!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;
+
+  var dest = context.createMediaStreamDestination();
+  source.connect(dest);
+  var elem = document.createElement('audio');
+  elem.mozSrcObject = 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>