Bug 866434 - Part 4: Add a test case for connecting an AudioNode to an AudioParam; r=roc
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 01 May 2013 23:13:43 -0400
changeset 141682 42ced245b6f8ff0462a4122ca7befe3d01fa5d0a
parent 141681 8d0cd25b661101d1bdd39a3b6ba345d9ae90a679
child 141683 3b2020da6f66a78fc17fc56fcf8539b96039a3cc
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs866434
milestone23.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 866434 - Part 4: Add a test case for connecting an AudioNode to an AudioParam; r=roc
content/media/webaudio/test/Makefile.in
content/media/webaudio/test/test_nodeToParamConnection.html
--- a/content/media/webaudio/test/Makefile.in
+++ b/content/media/webaudio/test/Makefile.in
@@ -35,16 +35,17 @@ MOCHITEST_FILES := \
   test_biquadFilterNode.html \
   test_currentTime.html \
   test_delayNode.html \
   test_delayNodeWithGain.html \
   test_decodeAudioData.html \
   test_dynamicsCompressorNode.html \
   test_gainNode.html \
   test_mixingRules.html \
+  test_nodeToParamConnection.html \
   test_pannerNode.html \
   test_scriptProcessorNode.html \
   test_scriptProcessorNodeChannelCount.html \
   test_singleSourceDest.html \
   ting.ogg \
   ting-expected.wav \
   ting-dualchannel44.1.ogg \
   ting-dualchannel44.1-expected.wav \
new file mode 100644
--- /dev/null
+++ b/content/media/webaudio/test/test_nodeToParamConnection.html
@@ -0,0 +1,69 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test connecting an AudioNode to an AudioParam</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="webaudio.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+addLoadEvent(function() {
+  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
+
+  var context = new AudioContext();
+  var buffer = context.createBuffer(2, 2048, context.sampleRate);
+  for (var i = 0; i < 2048; ++i) {
+    for (var j = 0; j < 2; ++j) {
+      buffer.getChannelData(j)[i] = Math.sin(440 * 2 * (j + 1) * Math.PI * i / context.sampleRate);
+    }
+  }
+  var sourceBuffer = context.createBuffer(2, 2048, context.sampleRate);
+  for (var i = 0; i < 2048; ++i) {
+    sourceBuffer.getChannelData(0)[i] = 1;
+    sourceBuffer.getChannelData(1)[i] = -1;
+  }
+  var expectedBuffer = context.createBuffer(2, 2048, context.sampleRate);
+  for (var i = 0; i < 2048; ++i) {
+    expectedBuffer.getChannelData(0)[i] = 1 + (buffer.getChannelData(0)[i] + buffer.getChannelData(1)[i]) / 2;
+    expectedBuffer.getChannelData(1)[i] = -(1 + (buffer.getChannelData(0)[i] + buffer.getChannelData(1)[i]) / 2);
+  }
+
+  var destination = context.destination;
+
+  var paramSource = context.createBufferSource();
+  paramSource.buffer = buffer;
+
+  var source = context.createBufferSource();
+  source.buffer = sourceBuffer;
+
+  var gain = context.createGain();
+
+  paramSource.connect(gain.gain);
+  source.connect(gain);
+
+  var sp = context.createScriptProcessor(2048);
+  gain.connect(sp);
+  sp.connect(destination);
+
+  paramSource.start(0);
+  source.start(0);
+  sp.onaudioprocess = function(e) {
+    is(e.inputBuffer.numberOfChannels, 2, "Correct input channel count");
+    compareBuffers(e.inputBuffer.getChannelData(0), expectedBuffer.getChannelData(0));
+    compareBuffers(e.inputBuffer.getChannelData(1), expectedBuffer.getChannelData(1));
+
+    sp.onaudioprocess = null;
+
+    SpecialPowers.clearUserPref("media.webaudio.enabled");
+    SimpleTest.finish();
+  };
+});
+
+</script>
+</pre>
+</body>
+</html>