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

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

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

Powered by Google App Engine
This is Rietveld 408576698