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