OLD | NEW |
| (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/audit-util.js"></script> | |
8 <script src="resources/audio-testing.js"></script> | |
9 </head> | |
10 | |
11 <body> | |
12 <script> | |
13 description('Test disconnect() method on AudioNode destination.'); | |
14 window.jsTestIsAsync = true; | |
15 | |
16 var audit = Audit.createTaskRunner(); | |
17 | |
18 // Task 1: test disconnect() method. | |
19 audit.defineTask('disconnect()', function (done) { | |
20 | |
21 // Connect a source to multiple gain nodes, each connected to the | |
22 // destination. Then disconnect the source. The expected output should be | |
23 // all zeros since the source was disconnected. | |
24 var context = new OfflineAudioContext(1, 128, 44100); | |
25 var source = context.createBufferSource(); | |
26 var buffer1ch = createConstantBuffer(context, 128, [1]); | |
27 var gain1 = context.createGain(); | |
28 var gain2 = context.createGain(); | |
29 var gain3 = context.createGain(); | |
30 | |
31 source.buffer = buffer1ch; | |
32 | |
33 source.connect(gain1); | |
34 source.connect(gain2); | |
35 source.connect(gain3); | |
36 gain1.connect(context.destination); | |
37 gain2.connect(context.destination); | |
38 gain3.connect(context.destination); | |
39 source.start(); | |
40 | |
41 // This disconnects everything. | |
42 source.disconnect(); | |
43 | |
44 context.startRendering().then(function (buffer) { | |
45 | |
46 // With everything disconnected, the result should be zero. | |
47 Should('Channel #0', buffer.getChannelData(0)).beConstantValueOf(0); | |
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 = createConstantBuffer(context, 128, [1, 2, 3]); | |
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 | |
78 // The rendered channel should contain 4. (= 1 + 0 + 3) | |
79 Should('Channel #0', buffer.getChannelData(0)).beConstantValueOf(4); | |
80 | |
81 }).then(done); | |
82 }); | |
83 | |
84 // Task 3: test disconnect(AudioNode) method. | |
85 audit.defineTask('disconnect(AudioNode)', function (done) { | |
86 | |
87 // Connect a source to multiple gain nodes. Then test if disconnecting a | |
88 // single destination selectively works correctly. | |
89 var context = new OfflineAudioContext(1, 128, 44100); | |
90 var source = context.createBufferSource(); | |
91 var buffer1ch = createConstantBuffer(context, 128, [1]); | |
92 var gain1 = context.createGain(); | |
93 var gain2 = context.createGain(); | |
94 var gain3 = context.createGain(); | |
95 var orphan = context.createGain(); | |
96 | |
97 source.buffer = buffer1ch; | |
98 | |
99 source.connect(gain1); | |
100 source.connect(gain2); | |
101 source.connect(gain3); | |
102 gain1.connect(context.destination); | |
103 gain2.connect(context.destination); | |
104 gain3.connect(context.destination); | |
105 source.start(); | |
106 | |
107 source.disconnect(gain2); | |
108 | |
109 context.startRendering().then(function (buffer) { | |
110 | |
111 // The |sum| gain node should produce value 2. (1 + 0 + 1 = 2) | |
112 Should('Channel #0', buffer.getChannelData(0)).beConstantValueOf(2); | |
113 | |
114 }).then(done); | |
115 }); | |
116 | |
117 // Task 4: test disconnect(AudioNode, output) method. | |
118 audit.defineTask('disconnect(AudioNode, output)', function (done) { | |
119 | |
120 // Connect a buffer with 2 channels with each containing 1 and 2 | |
121 // respectively to a ChannelSplitter, then connect the splitter to 2 gain | |
122 // nodes as shown below: | |
123 // (1) splitter#0 => gain1 | |
124 // (2) splitter#0 => gain2 | |
125 // (3) splitter#1 => gain2 | |
126 // Then disconnect (2) and verify if the selective disconnection on a | |
127 // specified output of the destination node works correctly. | |
128 var context = new OfflineAudioContext(1, 128, 44100); | |
129 var source = context.createBufferSource(); | |
130 var buffer2ch = createConstantBuffer(context, 128, [1, 2]); | |
131 var splitter = context.createChannelSplitter(2); | |
132 var gain1 = context.createGain(); | |
133 var gain2 = context.createGain(); | |
134 | |
135 source.buffer = buffer2ch; | |
136 | |
137 source.connect(splitter); | |
138 splitter.connect(gain1, 0); // gain1 gets channel 0. | |
139 splitter.connect(gain2, 0); // gain2 sums channel 0 and 1. | |
140 splitter.connect(gain2, 1); | |
141 gain1.connect(context.destination); | |
142 gain2.connect(context.destination); | |
143 source.start(); | |
144 | |
145 splitter.disconnect(gain2, 0); // Now gain2 gets [2] | |
146 | |
147 context.startRendering().then(function (buffer) { | |
148 | |
149 // The sum of gain1 and gain2 should produce value 3. (= 1 + 2) | |
150 Should('Channel #0', buffer.getChannelData(0)).beConstantValueOf(3); | |
151 | |
152 }).then(done); | |
153 }); | |
154 | |
155 // Task 5: test disconnect(AudioNode, output, input) method. | |
156 audit.defineTask('disconnect(AudioNode, output, input)', function (done) { | |
157 | |
158 // Create a 3-channel buffer with [1, 2, 3] in each channel and then pass | |
159 // it through a splitter and a merger. Each input/output of the splitter | |
160 // and the merger is connected in a sequential order as shown below. | |
161 // (1) splitter#0 => merger#0 | |
162 // (2) splitter#1 => merger#1 | |
163 // (3) splitter#2 => merger#2 | |
164 // Then disconnect (3) and verify if each channel contains [1] and [2] | |
165 // respectively. | |
166 var context = new OfflineAudioContext(3, 128, 44100); | |
167 var source = context.createBufferSource(); | |
168 var buffer3ch = createConstantBuffer(context, 128, [1, 2, 3]); | |
169 var splitter = context.createChannelSplitter(3); | |
170 var merger = context.createChannelMerger(3); | |
171 | |
172 source.buffer = buffer3ch; | |
173 | |
174 source.connect(splitter); | |
175 splitter.connect(merger, 0, 0); | |
176 splitter.connect(merger, 1, 1); | |
177 splitter.connect(merger, 2, 2); | |
178 merger.connect(context.destination); | |
179 source.start(); | |
180 | |
181 splitter.disconnect(merger, 2, 2); | |
182 | |
183 context.startRendering().then(function (buffer) { | |
184 | |
185 // Each channel should have 1, 2, and 0 respectively. | |
186 Should('Channel #0', buffer.getChannelData(0)).beConstantValueOf(1); | |
187 Should('Channel #1', buffer.getChannelData(1)).beConstantValueOf(2); | |
188 Should('Channel #2', buffer.getChannelData(2)).beConstantValueOf(0); | |
189 | |
190 }).then(done); | |
191 }); | |
192 | |
193 // Task 6: exception checks. | |
194 audit.defineTask('exceptions', function (done) { | |
195 var context = new OfflineAudioContext(2, 128, 44100); | |
196 var gain1 = context.createGain(); | |
197 var splitter = context.createChannelSplitter(2); | |
198 var merger = context.createChannelMerger(2); | |
199 var gain2 = context.createGain(); | |
200 var gain3 = context.createGain(); | |
201 | |
202 // Connect a splitter to gain nodes and merger so we can test the possible
| |
203 // ways of disconnecting the nodes to verify that appropriate exceptions | |
204 // are thrown. | |
205 gain1.connect(splitter); | |
206 splitter.connect(gain2, 0); | |
207 splitter.connect(gain3, 1); | |
208 splitter.connect(merger, 0, 0); | |
209 splitter.connect(merger, 1, 1); | |
210 gain2.connect(gain3); | |
211 gain3.connect(context.destination); | |
212 merger.connect(context.destination); | |
213 | |
214 // There is no output #2. An exception should be thrown. | |
215 Should('splitter.disconnect(2)', function () { | |
216 splitter.disconnect(2); | |
217 }).throw('IndexSizeError'); | |
218 | |
219 // Disconnecting the output already disconnected should not throw. | |
220 Should('Disconnecting a connection twice', function () { | |
221 splitter.disconnect(1); | |
222 splitter.disconnect(1); | |
223 }).notThrow(); | |
224 | |
225 // gain1 is not connected gain2. An exception should be thrown. | |
226 Should('gain1.disconnect(gain2)', function () { | |
227 gain1.disconnect(gain2); | |
228 }).throw('InvalidAccessError'); | |
229 | |
230 // gain1 and gain3 are not connected. An exception should be thrown. | |
231 Should('gain1.disconnect(gain3)', function () { | |
232 gain1.disconnect(gain3); | |
233 }).throw('InvalidAccessError'); | |
234 | |
235 // There is no output #2 in the splitter. An exception should be thrown. | |
236 Should('splitter.disconnect(gain2, 2)', function () { | |
237 splitter.disconnect(gain2, 2); | |
238 }).throw('IndexSizeError'); | |
239 | |
240 // The splitter and gain1 are not connected. An exception should be thrown
. | |
241 Should('splitter.disconnect(gain1, 0)', function () { | |
242 splitter.disconnect(gain1, 0); | |
243 }).throw('InvalidAccessError'); | |
244 | |
245 // The splitter output #0 and the gain3 output #0 are not connected. An | |
246 // exception should be thrown. | |
247 Should('splitter.disconnect(gain3, 0, 0)', function () { | |
248 splitter.disconnect(gain3, 0, 0); | |
249 }).throw('InvalidAccessError'); | |
250 | |
251 // The output index is out of bound. An exception should be thrown. | |
252 Should('splitter.disconnect(merger, 3, 0)', function () { | |
253 splitter.disconnect(merger, 3, 0); | |
254 }).throw('IndexSizeError'); | |
255 | |
256 done(); | |
257 }); | |
258 | |
259 audit.defineTask('disabled-outputs', function (taskDone) { | |
260 // See crbug.com/656652 | |
261 var context = new OfflineAudioContext(2, 1024, 44100); | |
262 var g1 = context.createGain(); | |
263 var g2 = context.createGain(); | |
264 g1.connect(g2); | |
265 g1.disconnect(g2); | |
266 var g3 = context.createGain(); | |
267 g2.connect(g3); | |
268 g1.connect(g2); | |
269 context.startRendering().then(function () { | |
270 // If we make it here, we passed. | |
271 Should("Disabled outputs handled", true) | |
272 .summarize("correctly", "inccorrectly"); | |
273 }).then(taskDone); | |
274 }); | |
275 | |
276 audit.defineTask('finish', function (done) { | |
277 finishJSTest(); | |
278 done(); | |
279 }); | |
280 | |
281 audit.runTasks(); | |
282 | |
283 successfullyParsed = true; | |
284 </script> | |
285 </body> | |
286 | |
287 </html> | |
OLD | NEW |