Bug 896353 - Media Recording - Test case for record the MediaStream from audioContext. r=jsmith
authorRandy Lin <rlin@mozilla.com>
Fri, 26 Jul 2013 10:47:56 +0800
changeset 154799 6ca6b7563842709f24792aa6ab59716313811570
parent 154798 980905e0308e1f92e5890ef29c16cac419772665
child 154800 86ed8b6613f2cb59191fbcdca4e43ef971449a13
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjsmith
bugs896353
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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>