Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: LayoutTests/webaudio/audionode-disconnect.html

Issue 886173004: Fix AudioNode.disconnect() to support selective disconnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: JS argument evaluation order fixed. More comments added. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3
4 <head>
5 <script src="../resources/js-test.js"></script>
6 <script src="resources/compatibility.js"></script>
7 <script src="resources/audio-testing.js"></script>
8 </head>
9
10 <body>
11 <script>
12 description('Test disconnect() method on AudioNode destination.');
13 window.jsTestIsAsync = true;
14
15 var audit = Audit.createTaskRunner();
16
17 // Task 1: test disconnect() method.
18 audit.defineTask('disconnect()', function (done) {
19
20 // Connect a source to multiple gain nodes, each connected to the
21 // destination. Then disconnect the source. The expected output should be
22 // all zeros since the source was disconnected.
23 var context = new OfflineAudioContext(1, 128, 44100);
24 var source = context.createBufferSource();
25 var buffer1ch = createTestingAudioBuffer(context, 1, 128);
26 var gain1 = context.createGain();
27 var gain2 = context.createGain();
28 var gain3 = context.createGain();
29
30 source.buffer = buffer1ch;
31
32 source.connect(gain1);
33 source.connect(gain2);
34 source.connect(gain3);
35 gain1.connect(context.destination);
36 gain2.connect(context.destination);
37 gain3.connect(context.destination);
38 source.start();
39
40 // This disconnects everything.
41 source.disconnect();
42
43 context.startRendering().then(function (buffer) {
44 var channelData = buffer.getChannelData(0);
45
46 // With everything disconnected, the result should be zero.
47 Should.haveValueInChannel(0, channelData);
48
49 }).then(done);
50 });
51
52 // Task 2: test disconnect(output) method.
53 audit.defineTask('disconnect(output)', function (done) {
54
55 // Create multiple connections from each output of a ChannelSplitter
56 // to a gain node. Then test if disconnecting a single output of splitter
57 // is actually disconnected.
58 var context = new OfflineAudioContext(1, 128, 44100);
59 var source = context.createBufferSource();
60 var buffer3ch = createTestingAudioBuffer(context, 3, 128);
61 var splitter = context.createChannelSplitter(3);
62 var sum = context.createGain();
63
64 source.buffer = buffer3ch;
65
66 source.connect(splitter);
67 splitter.connect(sum, 0);
68 splitter.connect(sum, 1);
69 splitter.connect(sum, 2);
70 sum.connect(context.destination);
71 source.start();
72
73 // This disconnects the second output.
74 splitter.disconnect(1);
75
76 context.startRendering().then(function (buffer) {
77 var channelData = buffer.getChannelData(0);
78
79 // The rendered channel should contain 4. (= 1 + 0 + 3)
80 Should.haveValueInChannel(4, channelData);
81
82 }).then(done);
83 });
84
85 // Task 3: test disconnect(AudioNode) method.
86 audit.defineTask('disconnect(AudioNode)', function (done) {
87
88 // Connect a source to multiple gain nodes. Then test if disconnecting a
89 // single destination selectively works correctly.
90 var context = new OfflineAudioContext(1, 128, 44100);
91 var source = context.createBufferSource();
92 var buffer1ch = createTestingAudioBuffer(context, 1, 128);
93 var gain1 = context.createGain();
94 var gain2 = context.createGain();
95 var gain3 = context.createGain();
96 var orphan = context.createGain();
97
98 source.buffer = buffer1ch;
99
100 source.connect(gain1);
101 source.connect(gain2);
102 source.connect(gain3);
103 gain1.connect(context.destination);
104 gain2.connect(context.destination);
105 gain3.connect(context.destination);
106 source.start();
107
108 source.disconnect(gain2);
109
110 context.startRendering().then(function (buffer) {
111 var channelData = buffer.getChannelData(0);
112
113 // The |sum| gain node should produce value 2. (1 + 0 + 1 = 2)
114 Should.haveValueInChannel(2, channelData);
115
116 }).then(done);
117 });
118
119 // Task 4: test disconnect(AudioNode, output) method.
120 audit.defineTask('disconnect(AudioNode, output)', function (done) {
121
122 // Connect a buffer with 2 channels with each containing 1 and 2
123 // respectively to a ChannelSplitter, then connect the splitter to 2 gain
124 // nodes as shown below:
125 // (1) splitter#0 => gain1
126 // (2) splitter#0 => gain2
127 // (3) splitter#1 => gain2
128 // Then disconnect (2) and verify if the selective disconnection on a
129 // specified output of the destination node works correctly.
130 var context = new OfflineAudioContext(1, 128, 44100);
131 var source = context.createBufferSource();
132 var buffer2ch = createTestingAudioBuffer(context, 2, 128);
133 var splitter = context.createChannelSplitter(2);
134 var gain1 = context.createGain();
135 var gain2 = context.createGain();
136
137 source.buffer = buffer2ch;
138
139 source.connect(splitter);
140 splitter.connect(gain1, 0); // gain1 gets channel 0.
141 splitter.connect(gain2, 0); // gain2 sums channel 0 and 1.
142 splitter.connect(gain2, 1);
143 gain1.connect(context.destination);
144 gain2.connect(context.destination);
145 source.start();
146
147 splitter.disconnect(gain2, 0); // Now gain2 gets [2]
148
149 context.startRendering().then(function (buffer) {
150 var channelData0 = buffer.getChannelData(0);
151
152 // The sum of gain1 and gain2 should produce value 3. (= 1 + 2)
153 Should.haveValueInChannel(3, channelData0);
154
155 }).then(done);
156 });
157
158 // Task 5: test disconnect(AudioNode, output, input) method.
159 audit.defineTask('disconnect(AudioNode, output, input)', function (done) {
160
161 // Create a 3-channel buffer with [1, 2, 3] in each channel and then pass
162 // it through a splitter and a merger. Each input/output of the splitter
163 // and the merger is connected in a sequential order as shown below.
164 // (1) splitter#0 => merger#0
165 // (2) splitter#1 => merger#1
166 // (3) splitter#2 => merger#2
167 // Then disconnect (3) and verify if each channel contains [1] and [2]
168 // respectively.
169 var context = new OfflineAudioContext(3, 128, 44100);
170 var source = context.createBufferSource();
171 var buffer3ch = createTestingAudioBuffer(context, 3, 128);
172 var splitter = context.createChannelSplitter(3);
173 var merger = context.createChannelMerger(3);
174
175 source.buffer = buffer3ch;
176
177 source.connect(splitter);
178 splitter.connect(merger, 0, 0);
179 splitter.connect(merger, 1, 1);
180 splitter.connect(merger, 2, 2);
181 merger.connect(context.destination);
182 source.start();
183
184 splitter.disconnect(merger, 2, 2);
185
186 context.startRendering().then(function (buffer) {
187 var channelData0 = buffer.getChannelData(0);
188 var channelData1 = buffer.getChannelData(1);
189 var channelData2 = buffer.getChannelData(2);
190
191 // Each channel should have 1, 2, and 0 respectively.
192 Should.haveValueInChannel(1, channelData0);
193 Should.haveValueInChannel(2, channelData1);
194 Should.haveValueInChannel(0, channelData2);
195
196 }).then(done);
197 });
198
199 // Task 6: exception checks.
200 audit.defineTask('exceptions', function (done) {
201 var context = new OfflineAudioContext(2, 128, 44100);
202 var gain1 = context.createGain();
203 var splitter = context.createChannelSplitter(2);
204 var merger = context.createChannelMerger(2);
205 var gain2 = context.createGain();
206 var gain3 = context.createGain();
207
208 // Build an audiograph to test the invalid disconnection.
Raymond Toy 2015/02/13 20:47:26 I was hoping for something more descriptive. Some
209 gain1.connect(splitter);
210 splitter.connect(gain2, 0);
211 splitter.connect(gain3, 1);
212 splitter.connect(merger, 0, 0);
213 splitter.connect(merger, 1, 1);
214 gain2.connect(gain3);
215 gain3.connect(context.destination);
216 merger.connect(context.destination);
217
218 // There is no output #2. An exception should be thrown.
219 Should.throwWithType('IndexSizeError', function () {
220 splitter.disconnect(2);
221 });
222
223 // Disconnecting the output already disconnected should not throw.
224 Should.notThrow(function () {
225 splitter.disconnect(1);
226 splitter.disconnect(1);
227 });
228
229 // gain1 is not connected gain2. An exception should be thrown.
230 Should.throwWithType('InvalidAccessError', function () {
231 gain1.disconnect(gain2);
232 });
233
234 // gain1 and gain3 are not connected. An exception should be thrown.
235 Should.throwWithType('InvalidAccessError', function () {
236 gain1.disconnect(gain3);
237 });
238
239 // There is no output #2 in the splitter. An exception should be thrown.
240 Should.throwWithType('IndexSizeError', function () {
241 splitter.disconnect(gain2, 2);
242 });
243
244 // the splitter and gain1 are not connected. An exception should be thrown .
Raymond Toy 2015/02/13 20:47:26 "the" -> "The"
245 Should.throwWithType('InvalidAccessError', function () {
246 splitter.disconnect(gain1, 0);
247 });
248
249 // The splitter output #0 and the gain3 output #0 are not connected. An
250 // exception should be thrown.
251 Should.throwWithType('InvalidAccessError', function () {
252 splitter.disconnect(gain3, 0, 0);
253 });
254
255 // The output index is out of bound. An exception should be thrown.
256 Should.throwWithType('IndexSizeError', function () {
257 splitter.disconnect(merger, 3, 0);
258 });
259
260 done();
261 });
262
263 audit.defineTask('finish', function (done) {
264 finishJSTest();
265 done();
266 });
267
268 audit.runTasks(
269 'disconnect()',
270 'disconnect(output)',
271 'disconnect(AudioNode)',
272 'disconnect(AudioNode, output)',
273 'disconnect(AudioNode, output, input)',
274 'exceptions',
275 'finish'
276 );
277
278 successfullyParsed = true;
279 </script>
280 </body>
281
282 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698