Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webaudio / audionode-disconnect.html
blobf1edeaf3a0c310449b568a876532dc2f798888bc
1 <!DOCTYPE html>
2 <html>
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>
10 <body>
11 <script>
12 description('Test disconnect() method on AudioNode destination.');
13 window.jsTestIsAsync = true;
15 var audit = Audit.createTaskRunner();
17 // Task 1: test disconnect() method.
18 audit.defineTask('disconnect()', function (done) {
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();
30 source.buffer = buffer1ch;
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();
40 // This disconnects everything.
41 source.disconnect();
43 context.startRendering().then(function (buffer) {
45 // With everything disconnected, the result should be zero.
46 Should('Channel #0', buffer.getChannelData(0)).beConstantValueOf(0);
48 }).then(done);
49 });
51 // Task 2: test disconnect(output) method.
52 audit.defineTask('disconnect(output)', function (done) {
54 // Create multiple connections from each output of a ChannelSplitter
55 // to a gain node. Then test if disconnecting a single output of splitter
56 // is actually disconnected.
57 var context = new OfflineAudioContext(1, 128, 44100);
58 var source = context.createBufferSource();
59 var buffer3ch = createTestingAudioBuffer(context, 3, 128);
60 var splitter = context.createChannelSplitter(3);
61 var sum = context.createGain();
63 source.buffer = buffer3ch;
65 source.connect(splitter);
66 splitter.connect(sum, 0);
67 splitter.connect(sum, 1);
68 splitter.connect(sum, 2);
69 sum.connect(context.destination);
70 source.start();
72 // This disconnects the second output.
73 splitter.disconnect(1);
75 context.startRendering().then(function (buffer) {
77 // The rendered channel should contain 4. (= 1 + 0 + 3)
78 Should('Channel #0', buffer.getChannelData(0)).beConstantValueOf(4);
80 }).then(done);
81 });
83 // Task 3: test disconnect(AudioNode) method.
84 audit.defineTask('disconnect(AudioNode)', function (done) {
86 // Connect a source to multiple gain nodes. Then test if disconnecting a
87 // single destination selectively works correctly.
88 var context = new OfflineAudioContext(1, 128, 44100);
89 var source = context.createBufferSource();
90 var buffer1ch = createTestingAudioBuffer(context, 1, 128);
91 var gain1 = context.createGain();
92 var gain2 = context.createGain();
93 var gain3 = context.createGain();
94 var orphan = context.createGain();
96 source.buffer = buffer1ch;
98 source.connect(gain1);
99 source.connect(gain2);
100 source.connect(gain3);
101 gain1.connect(context.destination);
102 gain2.connect(context.destination);
103 gain3.connect(context.destination);
104 source.start();
106 source.disconnect(gain2);
108 context.startRendering().then(function (buffer) {
110 // The |sum| gain node should produce value 2. (1 + 0 + 1 = 2)
111 Should('Channel #0', buffer.getChannelData(0)).beConstantValueOf(2);
113 }).then(done);
116 // Task 4: test disconnect(AudioNode, output) method.
117 audit.defineTask('disconnect(AudioNode, output)', function (done) {
119 // Connect a buffer with 2 channels with each containing 1 and 2
120 // respectively to a ChannelSplitter, then connect the splitter to 2 gain
121 // nodes as shown below:
122 // (1) splitter#0 => gain1
123 // (2) splitter#0 => gain2
124 // (3) splitter#1 => gain2
125 // Then disconnect (2) and verify if the selective disconnection on a
126 // specified output of the destination node works correctly.
127 var context = new OfflineAudioContext(1, 128, 44100);
128 var source = context.createBufferSource();
129 var buffer2ch = createTestingAudioBuffer(context, 2, 128);
130 var splitter = context.createChannelSplitter(2);
131 var gain1 = context.createGain();
132 var gain2 = context.createGain();
134 source.buffer = buffer2ch;
136 source.connect(splitter);
137 splitter.connect(gain1, 0); // gain1 gets channel 0.
138 splitter.connect(gain2, 0); // gain2 sums channel 0 and 1.
139 splitter.connect(gain2, 1);
140 gain1.connect(context.destination);
141 gain2.connect(context.destination);
142 source.start();
144 splitter.disconnect(gain2, 0); // Now gain2 gets [2]
146 context.startRendering().then(function (buffer) {
148 // The sum of gain1 and gain2 should produce value 3. (= 1 + 2)
149 Should('Channel #0', buffer.getChannelData(0)).beConstantValueOf(3);
151 }).then(done);
154 // Task 5: test disconnect(AudioNode, output, input) method.
155 audit.defineTask('disconnect(AudioNode, output, input)', function (done) {
157 // Create a 3-channel buffer with [1, 2, 3] in each channel and then pass
158 // it through a splitter and a merger. Each input/output of the splitter
159 // and the merger is connected in a sequential order as shown below.
160 // (1) splitter#0 => merger#0
161 // (2) splitter#1 => merger#1
162 // (3) splitter#2 => merger#2
163 // Then disconnect (3) and verify if each channel contains [1] and [2]
164 // respectively.
165 var context = new OfflineAudioContext(3, 128, 44100);
166 var source = context.createBufferSource();
167 var buffer3ch = createTestingAudioBuffer(context, 3, 128);
168 var splitter = context.createChannelSplitter(3);
169 var merger = context.createChannelMerger(3);
171 source.buffer = buffer3ch;
173 source.connect(splitter);
174 splitter.connect(merger, 0, 0);
175 splitter.connect(merger, 1, 1);
176 splitter.connect(merger, 2, 2);
177 merger.connect(context.destination);
178 source.start();
180 splitter.disconnect(merger, 2, 2);
182 context.startRendering().then(function (buffer) {
184 // Each channel should have 1, 2, and 0 respectively.
185 Should('Channel #0', buffer.getChannelData(0)).beConstantValueOf(1);
186 Should('Channel #1', buffer.getChannelData(1)).beConstantValueOf(2);
187 Should('Channel #2', buffer.getChannelData(2)).beConstantValueOf(0);
189 }).then(done);
192 // Task 6: exception checks.
193 audit.defineTask('exceptions', function (done) {
194 var context = new OfflineAudioContext(2, 128, 44100);
195 var gain1 = context.createGain();
196 var splitter = context.createChannelSplitter(2);
197 var merger = context.createChannelMerger(2);
198 var gain2 = context.createGain();
199 var gain3 = context.createGain();
201 // Connect a splitter to gain nodes and merger so we can test the possible
202 // ways of disconnecting the nodes to verify that appropriate exceptions
203 // are thrown.
204 gain1.connect(splitter);
205 splitter.connect(gain2, 0);
206 splitter.connect(gain3, 1);
207 splitter.connect(merger, 0, 0);
208 splitter.connect(merger, 1, 1);
209 gain2.connect(gain3);
210 gain3.connect(context.destination);
211 merger.connect(context.destination);
213 // There is no output #2. An exception should be thrown.
214 Should('splitter.disconnect(2)', function () {
215 splitter.disconnect(2);
216 }).throw('IndexSizeError');
218 // Disconnecting the output already disconnected should not throw.
219 Should('Disconnecting a connection twice', function () {
220 splitter.disconnect(1);
221 splitter.disconnect(1);
222 }).notThrow();
224 // gain1 is not connected gain2. An exception should be thrown.
225 Should('gain1.disconnect(gain2)', function () {
226 gain1.disconnect(gain2);
227 }).throw('InvalidAccessError');
229 // gain1 and gain3 are not connected. An exception should be thrown.
230 Should('gain1.disconnect(gain3)', function () {
231 gain1.disconnect(gain3);
232 }).throw('InvalidAccessError');
234 // There is no output #2 in the splitter. An exception should be thrown.
235 Should('splitter.disconnect(gain2, 2)', function () {
236 splitter.disconnect(gain2, 2);
237 }).throw('IndexSizeError');
239 // The splitter and gain1 are not connected. An exception should be thrown.
240 Should('splitter.disconnect(gain1, 0)', function () {
241 splitter.disconnect(gain1, 0);
242 }).throw('InvalidAccessError');
244 // The splitter output #0 and the gain3 output #0 are not connected. An
245 // exception should be thrown.
246 Should('splitter.disconnect(gain3, 0, 0)', function () {
247 splitter.disconnect(gain3, 0, 0);
248 }).throw('InvalidAccessError');
250 // The output index is out of bound. An exception should be thrown.
251 Should('splitter.disconnect(merger, 3, 0)', function () {
252 splitter.disconnect(merger, 3, 0);
253 }).throw('IndexSizeError');
255 done();
258 audit.defineTask('finish', function (done) {
259 finishJSTest();
260 done();
263 audit.runTasks(
264 'disconnect()',
265 'disconnect(output)',
266 'disconnect(AudioNode)',
267 'disconnect(AudioNode, output)',
268 'disconnect(AudioNode, output, input)',
269 'exceptions',
270 'finish'
273 successfullyParsed = true;
274 </script>
275 </body>
277 </html>