Index: LayoutTests/webaudio/audionode-disconnect.html |
diff --git a/LayoutTests/webaudio/audionode-disconnect.html b/LayoutTests/webaudio/audionode-disconnect.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..53a343ed00c086590e8ebb2db4a83b97f4bd06ac |
--- /dev/null |
+++ b/LayoutTests/webaudio/audionode-disconnect.html |
@@ -0,0 +1,245 @@ |
+<!DOCTYPE html> |
+<html> |
+ |
+<head> |
+ <script src="../resources/js-test.js"></script> |
+ <script src="resources/compatibility.js"></script> |
+ <script src="resources/audio-testing.js"></script> |
+</head> |
+ |
+<body> |
+ <div id="description"></div> |
+ <div id="console"></div> |
Raymond Toy
2015/02/11 21:31:18
Are these two div's needed? I thought js-test.js d
hongchan
2015/02/12 18:38:00
I just copied another test file's HTML code. I jus
|
+ <script> |
+ description('Test disconnect() method.'); |
+ window.jsTestIsAsync = true; |
+ |
+ var audit = Audit.createTaskRunner(); |
+ |
+ // Task 1: test disconnect() method. |
+ audit.defineTask('disconnect()', function (done) { |
+ var context = new OfflineAudioContext(1, 128, 44100); |
Raymond Toy
2015/02/11 21:31:18
Please describe what you're doing here and why.
hongchan
2015/02/12 18:38:00
Done.
|
+ var source = context.createBufferSource(); |
+ var buffer1ch = createTestingBuffer(context, 1, 128); |
+ var gain1 = context.createGain(); |
+ var gain2 = context.createGain(); |
+ var gain3 = context.createGain(); |
+ |
+ source.buffer = buffer1ch; |
+ |
+ source.connect(gain1); |
+ source.connect(gain2); |
+ source.connect(gain3); |
+ gain1.connect(context.destination); |
+ gain2.connect(context.destination); |
+ gain3.connect(context.destination); |
+ source.start(); |
+ |
+ // This disconnects everything. |
+ source.disconnect(); |
+ |
+ context.oncomplete = function (event) { |
+ var channelData = event.renderedBuffer.getChannelData(0); |
+ |
+ // With everything disconnected, the result should be zero. |
+ Should.haveValueInChannel(0, channelData); |
+ |
+ done(); |
+ }; |
+ |
+ context.startRendering(); |
Raymond Toy
2015/02/11 21:31:18
Consider using the promise instead of the oncomple
hongchan
2015/02/12 18:38:00
Done.
|
+ }); |
+ |
+ // Task 2: test disconnect(output) method. |
+ audit.defineTask('disconnect(output)', function (done) { |
+ var context = new OfflineAudioContext(1, 128, 44100); |
+ var source = context.createBufferSource(); |
+ var buffer3ch = createTestingBuffer(context, 3, 128); |
+ var splitter = context.createChannelSplitter(3); |
+ var sum = context.createGain(); |
+ |
+ source.buffer = buffer3ch; |
+ |
+ source.connect(splitter); |
+ splitter.connect(sum, 0); |
+ splitter.connect(sum, 1); |
+ splitter.connect(sum, 2); |
+ sum.connect(context.destination); |
+ source.start(); |
+ |
+ // This disconnects the second output. |
+ splitter.disconnect(1); |
Raymond Toy
2015/02/11 21:31:18
Since all of these connects/disconnects happen bef
hongchan
2015/02/12 18:38:00
Although all the operations here is synchronous an
|
+ |
+ // There is no output #3. Exception should be thrown. |
+ Should.throwWithType(function () { |
+ splitter.disconnect(3); |
+ }, 'IndexSizeError'); |
Raymond Toy
2015/02/11 21:31:18
Since the type is just a short string, it might be
hongchan
2015/02/12 18:38:00
Yes, I agree. Will fix.
|
+ |
+ // Disconnecting the output already disconnected should not throw. |
+ Should.notThrow(function () { |
+ splitter.disconnect(1); |
+ }); |
+ |
+ context.oncomplete = function (event) { |
+ var channelData = event.renderedBuffer.getChannelData(0); |
+ |
+ // The rendered channel should contain 4. (= 1 + 0 + 3) |
+ Should.haveValueInChannel(4, channelData); |
+ |
+ done(); |
+ }; |
+ |
+ context.startRendering(); |
+ }); |
+ |
+ // Task 3: test disconnect(AudioNode) method. |
+ audit.defineTask('disconnect(AudioNode)', function (done) { |
+ var context = new OfflineAudioContext(1, 128, 44100); |
+ var source = context.createBufferSource(); |
+ var buffer1ch = createTestingBuffer(context, 1, 128); |
+ var gain1 = context.createGain(); |
+ var gain2 = context.createGain(); |
+ var gain3 = context.createGain(); |
+ var gain4 = context.createGain(); |
+ |
+ source.buffer = buffer1ch; |
+ |
+ source.connect(gain1); |
+ source.connect(gain2); |
+ source.connect(gain3); |
+ gain1.connect(context.destination); |
+ gain2.connect(context.destination); |
+ gain3.connect(context.destination); |
+ source.start(); |
+ |
+ source.disconnect(gain2); |
+ |
+ // gain2 is already disconnected. Exception should be thrown. |
+ Should.throwWithType(function () { |
+ gain1.disconnect(gain2); |
+ }, 'InvalidAccessError'); |
+ |
+ // gain1 and gain4 are not connected. Exception should not be thrown. |
+ Should.throwWithType(function () { |
+ gain1.disconnect(gain4); |
+ }, 'InvalidAccessError'); |
+ |
+ context.oncomplete = function (event) { |
+ var channelData = event.renderedBuffer.getChannelData(0); |
+ |
+ // The |sum| gain node should produce value 2. (1 + 0 + 1 = 2) |
+ Should.haveValueInChannel(2, channelData); |
+ |
+ done(); |
+ }; |
+ |
+ context.startRendering(); |
+ }); |
+ |
+ // Task 4: test disconnect(AudioNode, output) method. |
+ audit.defineTask('disconnect(AudioNode, output)', function (done) { |
+ var context = new OfflineAudioContext(3, 128, 44100); |
+ var source = context.createBufferSource(); |
+ var buffer3ch = createTestingBuffer(context, 3, 128); |
+ var splitter = context.createChannelSplitter(3); |
+ var sum = context.createGain(); |
+ var orphan = context.createGain(); |
+ |
+ source.buffer = buffer3ch; |
+ |
+ source.connect(splitter); |
+ splitter.connect(sum, 0); |
+ splitter.connect(sum, 1); |
+ splitter.connect(sum, 2); |
+ sum.connect(context.destination); |
+ source.start(); |
+ |
+ splitter.disconnect(sum, 0); |
+ |
+ // There is no output #3 in the splitter. An exception should be thrown. |
+ Should.throwWithType(function () { |
+ splitter.disconnect(sum, 3); |
+ }, 'IndexSizeError'); |
+ |
+ // No valid connection to |orphan|. An exception should be thrown. |
+ Should.throwWithType(function () { |
+ splitter.disconnect(orphan, 0); |
+ }, 'InvalidAccessError'); |
+ |
+ context.oncomplete = function (event) { |
+ var channelData0 = event.renderedBuffer.getChannelData(0); |
+ |
+ // The |sum| gain node should produce value 5. (0 + 2 + 3 = 5) |
+ Should.haveValueInChannel(5, channelData0); |
+ |
+ done(); |
+ }; |
+ |
+ context.startRendering(); |
+ }); |
+ |
+ // Task 5: test disconnect(AudioNode, output, input) method. |
+ audit.defineTask('disconnect(AudioNode, output, input)', function (done) { |
+ var context = new OfflineAudioContext(3, 128, 44100); |
+ var source = context.createBufferSource(); |
+ var buffer3ch = createTestingBuffer(context, 3, 128); |
+ var splitter = context.createChannelSplitter(3); |
+ var merger = context.createChannelMerger(3); |
+ var orphan = context.createGain(); |
+ |
+ context.destination.channelCount = 3; |
+ context.destination.channelCountMode = 'explicit'; |
+ source.buffer = buffer3ch; |
+ |
+ source.connect(splitter); |
+ splitter.connect(merger, 0, 0); |
+ splitter.connect(merger, 1, 1); |
+ splitter.connect(merger, 2, 2); |
+ merger.connect(context.destination); |
+ source.start(); |
+ |
+ splitter.disconnect(merger, 2, 2); |
+ |
+ // Orphan doesn't have a connection. An exception should be thrown. |
+ Should.throwWithType(function () { |
+ splitter.disconnect(orphan, 0, 0); |
+ }, 'InvalidAccessError'); |
+ |
+ // The output index is out of bound. An exception should be thrown. |
+ Should.throwWithType(function () { |
+ splitter.disconnect(merger, 3, 0); |
+ }, 'IndexSizeError'); |
+ |
+ context.oncomplete = function (event) { |
+ var channelData0 = event.renderedBuffer.getChannelData(0); |
+ var channelData1 = event.renderedBuffer.getChannelData(1); |
+ |
+ // Each channel should have [1] and [2] respectively. |
+ Should.haveValueInChannel(1, channelData0); |
+ Should.haveValueInChannel(2, channelData1); |
+ |
+ done(); |
+ }; |
+ |
+ context.startRendering(); |
+ }); |
+ |
+ audit.defineTask('finish', function (done) { |
+ finishJSTest(); |
+ done(); |
+ }); |
+ |
+ audit.runTasks( |
+ 'disconnect()', |
+ 'disconnect(output)', |
+ 'disconnect(AudioNode)', |
+ 'disconnect(AudioNode, output)', |
+ 'disconnect(AudioNode, output, input)', |
+ 'finish' |
+ ); |
+ |
+ successfullyParsed = true; |
+ </script> |
+</body> |
+ |
+</html> |