Bug 1130010 - Add tests for the new {AudioParam,AudioNode}.disconnect() methods. r=dminor
authorPaul Adenot <paul@paul.cx>
Mon, 18 Jul 2016 18:53:24 +0200
changeset 318831 1b34fb6f5b5f07489c57277da49b4680276cfe67
parent 318830 38ae3688a00bba02f5d47a65c5f58d84ef25b7bc
child 318832 37434b4379d9b9891cbbb6157a709e45b64f2a41
push id30854
push userryanvm@gmail.com
push dateFri, 21 Oct 2016 21:08:02 +0000
treeherdermozilla-central@806054dd12bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdminor
bugs1130010
milestone52.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 1130010 - Add tests for the new {AudioParam,AudioNode}.disconnect() methods. r=dminor Initial patch by Thomas Escalon <tesc.bugzilla@gmail.com>. MozReview-Commit-ID: 2cptcTYuzDQ
dom/media/webaudio/test/mochitest.ini
dom/media/webaudio/test/test_disconnectAll.html
dom/media/webaudio/test/test_disconnectAudioParam.html
dom/media/webaudio/test/test_disconnectAudioParamFromOutput.html
dom/media/webaudio/test/test_disconnectExceptions.html
dom/media/webaudio/test/test_disconnectFromAudioNode.html
dom/media/webaudio/test/test_disconnectFromAudioNodeAndOutput.html
dom/media/webaudio/test/test_disconnectFromAudioNodeAndOutputAndInput.html
dom/media/webaudio/test/test_disconnectFromOutput.html
--- a/dom/media/webaudio/test/mochitest.ini
+++ b/dom/media/webaudio/test/mochitest.ini
@@ -120,16 +120,24 @@ skip-if = toolkit == 'android' # bug 105
 [test_delayNodeCycles.html]
 [test_delayNodePassThrough.html]
 [test_delayNodeSmallMaxDelay.html]
 [test_delayNodeTailIncrease.html]
 [test_delayNodeTailWithDisconnect.html]
 [test_delayNodeTailWithGain.html]
 [test_delayNodeTailWithReconnect.html]
 [test_delayNodeWithGain.html]
+[test_disconnectAll.html]
+[test_disconnectAudioParam.html]
+[test_disconnectAudioParamFromOutput.html]
+[test_disconnectExceptions.html]
+[test_disconnectFromAudioNode.html]
+[test_disconnectFromAudioNodeAndOutput.html]
+[test_disconnectFromAudioNodeAndOutputAndInput.html]
+[test_disconnectFromOutput.html]
 [test_dynamicsCompressorNode.html]
 [test_dynamicsCompressorNodePassThrough.html]
 [test_dynamicsCompressorNodeWithGain.html]
 [test_gainNode.html]
 [test_gainNodeInLoop.html]
 [test_gainNodePassThrough.html]
 [test_iirFilterNodePassThrough.html]
 [test_maxChannelCount.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_disconnectAll.html
@@ -0,0 +1,51 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <title>Test whether we can disconnect an AudioNode</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">
+      var gTest = {
+        length: 256,
+        numberOfChannels: 1,
+        createGraph: function(context) {
+          var sourceBuffer = context.createBuffer(1, 256, context.sampleRate);
+          var data = sourceBuffer.getChannelData(0);
+          for (var j = 0; j < data.length; j++) {
+              data[j] = 1;
+          }
+
+          var source = context.createBufferSource();
+          source.buffer = sourceBuffer;
+
+          var source = context.createBufferSource();
+          source.buffer = sourceBuffer;
+
+          var gain1 = context.createGain();
+          var gain2 = context.createGain();
+          var gain3 = context.createGain();
+          var merger = context.createChannelMerger(3);
+
+          source.connect(gain1);
+          source.connect(gain2);
+          source.connect(gain3);
+          gain1.connect(merger);
+          gain2.connect(merger);
+          gain3.connect(merger);
+          source.start();
+
+          source.disconnect();
+
+          return merger;
+        }
+      };
+
+      runTest();
+      </script>
+    </pre>
+  </body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_disconnectAudioParam.html
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <title>Test whether we can disconnect 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">
+      var gTest = {
+        length: 256,
+        numberOfChannels: 1,
+        createGraph: function(context) {
+          var sourceBuffer = context.createBuffer(1, 256, context.sampleRate);
+          var data = sourceBuffer.getChannelData(0);
+          for (var j = 0; j < data.length; j++) {
+              data[j] = 1;
+          }
+
+          var source = context.createBufferSource();
+          source.buffer = sourceBuffer;
+
+          var half = context.createGain();
+          var gain1 = context.createGain();
+          var gain2 = context.createGain();
+
+          half.gain.value = 0.5;
+
+          source.connect(gain1);
+          gain1.connect(gain2);
+          source.connect(half);
+
+          half.connect(gain1.gain);
+          half.connect(gain2.gain);
+
+          half.disconnect(gain2.gain);
+
+          source.start();
+
+          return gain2;
+        },
+        createExpectedBuffers: function(context) {
+          expectedBuffer = context.createBuffer(1, 256, context.sampleRate);
+          for (var i = 0; i < 256; ++i) {
+            expectedBuffer.getChannelData(0)[i] = 1.5;
+          }
+
+          return expectedBuffer;
+        }
+      };
+
+      runTest();
+      </script>
+    </pre>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_disconnectAudioParamFromOutput.html
@@ -0,0 +1,67 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <title>Test whether we can disconnect 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">
+      var gTest = {
+        length: 256,
+        numberOfChannels: 2,
+        createGraph: function(context) {
+          var sourceBuffer = context.createBuffer(2, 256, context.sampleRate);
+          for (var i = 1; i <= 2; i++) {
+            var data = sourceBuffer.getChannelData(i-1);
+            for (var j = 0; j < data.length; j++) {
+                data[j] = i;
+            }
+          }
+
+          var source = context.createBufferSource();
+          source.buffer = sourceBuffer;
+
+          var source = context.createBufferSource();
+          source.buffer = sourceBuffer;
+
+          var half = context.createGain();
+          var gain1 = context.createGain();
+          var gain2 = context.createGain();
+          var splitter = context.createChannelSplitter(2);
+
+          half.gain.value = 0.5;
+
+          source.connect(gain1);
+          gain1.connect(gain2);
+          source.connect(half);
+          half.connect(splitter);
+          splitter.connect(gain1.gain, 0);
+          splitter.connect(gain2.gain, 1);
+
+          splitter.disconnect(gain2.gain, 1);
+
+          source.start();
+
+          return gain2;
+        },
+        createExpectedBuffers: function(context) {
+          var expectedBuffer = context.createBuffer(2, 256, context.sampleRate);
+          for (var i = 1; i <= 2; i++) {
+            var data = expectedBuffer.getChannelData(i-1);
+            for (var j = 0; j < data.length; j++) {
+              data[j] = (i == 1) ? 1.5 : 3.0;
+            }
+          }
+
+          return expectedBuffer;
+        }
+      };
+
+      runTest();
+      </script>
+    </pre>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_disconnectExceptions.html
@@ -0,0 +1,75 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <title>Test whether we can disconnect an AudioNode</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">
+      var ctx = new AudioContext();
+      var sourceBuffer = ctx.createBuffer(2, 256, ctx.sampleRate);
+      for (var i = 1; i <= 2; i++) {
+        var data = sourceBuffer.getChannelData(i-1);
+        for (var j = 0; j < data.length; j++) {
+            data[j] = i;
+        }
+      }
+
+      var source = ctx.createBufferSource();
+      source.buffer = sourceBuffer;
+
+      var gain1 = ctx.createGain();
+      var splitter = ctx.createChannelSplitter(2);
+      var merger = ctx.createChannelMerger(2);
+      var gain2 = ctx.createGain();
+      var gain3 = ctx.createGain();
+
+      gain1.connect(splitter);
+      splitter.connect(gain2, 0);
+      splitter.connect(gain3, 1);
+      splitter.connect(merger, 0, 0);
+      splitter.connect(merger, 1, 1);
+      gain2.connect(gain3);
+      gain3.connect(ctx.destination);
+      merger.connect(ctx.destination);
+
+      expectException(function() {
+          splitter.disconnect(2);
+      }, DOMException.INDEX_SIZE_ERR);
+
+      expectNoException(function() {
+        splitter.disconnect(1);
+        splitter.disconnect(1);
+      });
+
+      expectException(function() {
+        gain1.disconnect(gain2);
+      }, DOMException.INVALID_ACCESS_ERR);
+
+      expectException(function() {
+        gain1.disconnect(gain3);
+        ok(false, 'Should get InvalidAccessError exception');
+      }, DOMException.INVALID_ACCESS_ERR);
+
+      expectException(function() {
+        splitter.disconnect(gain2, 2);
+      }, DOMException.INDEX_SIZE_ERR);
+
+      expectException(function() {
+        splitter.disconnect(gain1, 0);
+      }, DOMException.INVALID_ACCESS_ERR);
+
+      expectException(function() {
+        splitter.disconnect(gain3, 0, 0);
+      }, DOMException.INVALID_ACCESS_ERR);
+
+      expectException(function() {
+        splitter.disconnect(merger, 3, 0);
+      }, DOMException.INDEX_SIZE_ERR);
+      </script>
+    </pre>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_disconnectFromAudioNode.html
@@ -0,0 +1,55 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <title>Test whether we can disconnect an AudioNode</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">
+      var gTest = {
+        length: 256,
+        numberOfChannels: 1,
+        createGraph: function(context) {
+          var sourceBuffer = context.createBuffer(1, 256, context.sampleRate);
+          var data = sourceBuffer.getChannelData(0);
+          for (var j = 0; j < data.length; j++) {
+              data[j] = 1;
+          }
+
+          var source = context.createBufferSource();
+          source.buffer = sourceBuffer;
+
+          var gain1 = context.createGain();
+          var gain2 = context.createGain();
+          var gain3 = context.createGain();
+
+          source.connect(gain1);
+          source.connect(gain2);
+
+          gain1.connect(gain3);
+          gain2.connect(gain3);
+
+          source.start();
+
+          source.disconnect(gain2);
+
+          return gain3;
+        },
+        createExpectedBuffers: function(context) {
+          expectedBuffer = context.createBuffer(1, 256, context.sampleRate);
+          for (var i = 0; i < 256; ++i) {
+            expectedBuffer.getChannelData(0)[i] = 1.0;
+          }
+
+          return expectedBuffer;
+        }
+      };
+
+      runTest();
+      </script>
+    </pre>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_disconnectFromAudioNodeAndOutput.html
@@ -0,0 +1,59 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <title>Test whether we can disconnect an AudioNode</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">
+      var gTest = {
+        length: 256,
+        numberOfChannels: 2,
+        createGraph: function(context) {
+          var sourceBuffer = context.createBuffer(2, 256, context.sampleRate);
+          for (var i = 1; i <= 2; i++) {
+            var data = sourceBuffer.getChannelData(i-1);
+            for (var j = 0; j < data.length; j++) {
+                data[j] = i;
+            }
+          }
+
+          var source = context.createBufferSource();
+          source.buffer = sourceBuffer;
+
+          var splitter = context.createChannelSplitter(2);
+          var gain1 = context.createGain();
+          var gain2 = context.createGain();
+          var merger = context.createChannelMerger(2);
+
+          source.connect(splitter);
+          splitter.connect(gain1, 0);
+          splitter.connect(gain2, 0);
+          splitter.connect(gain2, 1);
+          gain1.connect(merger, 0, 1);
+          gain2.connect(merger, 0, 1);
+          source.start();
+
+          splitter.disconnect(gain2, 0);
+
+          return merger;
+        },
+        createExpectedBuffers: function(context) {
+          expectedBuffer = context.createBuffer(2, 256, context.sampleRate);
+          for (var i = 0; i < 256; ++i) {
+            expectedBuffer.getChannelData(0)[i] = 0;
+            expectedBuffer.getChannelData(1)[i] = 3;
+          }
+
+          return expectedBuffer;
+        }
+      };
+
+      runTest();
+      </script>
+    </pre>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_disconnectFromAudioNodeAndOutputAndInput.html
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <title>Test whether we can disconnect an AudioNode</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">
+      var gTest = {
+        length: 256,
+        numberOfChannels: 3,
+        createGraph: function(context) {
+          var sourceBuffer = context.createBuffer(3, 256, context.sampleRate);
+          for (var i = 1; i <= 3; i++) {
+            var data = sourceBuffer.getChannelData(i-1);
+            for (var j = 0; j < data.length; j++) {
+                data[j] = i;
+            }
+          }
+
+          var source = context.createBufferSource();
+          source.buffer = sourceBuffer;
+
+          var splitter = context.createChannelSplitter(3);
+          var merger = context.createChannelMerger(3);
+
+          source.connect(splitter);
+          splitter.connect(merger, 0, 0);
+          splitter.connect(merger, 1, 1);
+          splitter.connect(merger, 2, 2);
+          source.start();
+
+          splitter.disconnect(merger, 2, 2);
+
+          return merger;
+        },
+        createExpectedBuffers: function(context) {
+          var expectedBuffer = context.createBuffer(3, 256, context.sampleRate);
+          for (var i = 1; i <= 3; i++) {
+            var data = expectedBuffer.getChannelData(i-1);
+            for (var j = 0; j < data.length; j++) {
+              data[j] = (i == 3) ? 0 : i;
+            }
+          }
+
+          return expectedBuffer;
+        }
+      };
+
+      runTest();
+      </script>
+    </pre>
+  </body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_disconnectFromOutput.html
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <title>Test whether we can disconnect an AudioNode</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">
+      var gTest = {
+        length: 256,
+        numberOfChannels: 1,
+        createGraph: function(context) {
+          var sourceBuffer = context.createBuffer(3, 256, context.sampleRate);
+          for (var i = 1; i <= 3; i++) {
+            var data = sourceBuffer.getChannelData(i-1);
+            for (var j = 0; j < data.length; j++) {
+                data[j] = i;
+            }
+          }
+
+          var source = context.createBufferSource();
+          source.buffer = sourceBuffer;
+
+          var splitter = context.createChannelSplitter(3);
+          var sum = context.createGain();
+
+          source.connect(splitter);
+          splitter.connect(sum, 0);
+          splitter.connect(sum, 1);
+          splitter.connect(sum, 2);
+          source.start();
+
+          splitter.disconnect(1);
+
+          return sum;
+        },
+        createExpectedBuffers: function(context) {
+          expectedBuffer = context.createBuffer(1, 256, context.sampleRate);
+          for (var i = 0; i < 256; ++i) {
+            expectedBuffer.getChannelData(0)[i] = 4;
+          }
+
+          return expectedBuffer;
+        },
+      };
+
+      runTest();
+      </script>
+    </pre>
+  </body>
+</html>
\ No newline at end of file