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/audio-testing.js"></script> | |
8 </head> | |
9 | |
10 <body> | |
11 <div id="description"></div> | |
12 <div id="console"></div> | |
Raymond Toy
2015/02/11 21:31:18
Are these two div's needed? I thought js-test.js d
hongchan
2015/02/12 18:38:00
I just copied another test file's HTML code. I jus
| |
13 <script> | |
14 description('Test disconnect() method.'); | |
15 window.jsTestIsAsync = true; | |
16 | |
17 var audit = Audit.createTaskRunner(); | |
18 | |
19 // Task 1: test disconnect() method. | |
20 audit.defineTask('disconnect()', function (done) { | |
21 var context = new OfflineAudioContext(1, 128, 44100); | |
Raymond Toy
2015/02/11 21:31:18
Please describe what you're doing here and why.
hongchan
2015/02/12 18:38:00
Done.
| |
22 var source = context.createBufferSource(); | |
23 var buffer1ch = createTestingBuffer(context, 1, 128); | |
24 var gain1 = context.createGain(); | |
25 var gain2 = context.createGain(); | |
26 var gain3 = context.createGain(); | |
27 | |
28 source.buffer = buffer1ch; | |
29 | |
30 source.connect(gain1); | |
31 source.connect(gain2); | |
32 source.connect(gain3); | |
33 gain1.connect(context.destination); | |
34 gain2.connect(context.destination); | |
35 gain3.connect(context.destination); | |
36 source.start(); | |
37 | |
38 // This disconnects everything. | |
39 source.disconnect(); | |
40 | |
41 context.oncomplete = function (event) { | |
42 var channelData = event.renderedBuffer.getChannelData(0); | |
43 | |
44 // With everything disconnected, the result should be zero. | |
45 Should.haveValueInChannel(0, channelData); | |
46 | |
47 done(); | |
48 }; | |
49 | |
50 context.startRendering(); | |
Raymond Toy
2015/02/11 21:31:18
Consider using the promise instead of the oncomple
hongchan
2015/02/12 18:38:00
Done.
| |
51 }); | |
52 | |
53 // Task 2: test disconnect(output) method. | |
54 audit.defineTask('disconnect(output)', function (done) { | |
55 var context = new OfflineAudioContext(1, 128, 44100); | |
56 var source = context.createBufferSource(); | |
57 var buffer3ch = createTestingBuffer(context, 3, 128); | |
58 var splitter = context.createChannelSplitter(3); | |
59 var sum = context.createGain(); | |
60 | |
61 source.buffer = buffer3ch; | |
62 | |
63 source.connect(splitter); | |
64 splitter.connect(sum, 0); | |
65 splitter.connect(sum, 1); | |
66 splitter.connect(sum, 2); | |
67 sum.connect(context.destination); | |
68 source.start(); | |
69 | |
70 // This disconnects the second output. | |
71 splitter.disconnect(1); | |
Raymond Toy
2015/02/11 21:31:18
Since all of these connects/disconnects happen bef
hongchan
2015/02/12 18:38:00
Although all the operations here is synchronous an
| |
72 | |
73 // There is no output #3. Exception should be thrown. | |
74 Should.throwWithType(function () { | |
75 splitter.disconnect(3); | |
76 }, 'IndexSizeError'); | |
Raymond Toy
2015/02/11 21:31:18
Since the type is just a short string, it might be
hongchan
2015/02/12 18:38:00
Yes, I agree. Will fix.
| |
77 | |
78 // Disconnecting the output already disconnected should not throw. | |
79 Should.notThrow(function () { | |
80 splitter.disconnect(1); | |
81 }); | |
82 | |
83 context.oncomplete = function (event) { | |
84 var channelData = event.renderedBuffer.getChannelData(0); | |
85 | |
86 // The rendered channel should contain 4. (= 1 + 0 + 3) | |
87 Should.haveValueInChannel(4, channelData); | |
88 | |
89 done(); | |
90 }; | |
91 | |
92 context.startRendering(); | |
93 }); | |
94 | |
95 // Task 3: test disconnect(AudioNode) method. | |
96 audit.defineTask('disconnect(AudioNode)', function (done) { | |
97 var context = new OfflineAudioContext(1, 128, 44100); | |
98 var source = context.createBufferSource(); | |
99 var buffer1ch = createTestingBuffer(context, 1, 128); | |
100 var gain1 = context.createGain(); | |
101 var gain2 = context.createGain(); | |
102 var gain3 = context.createGain(); | |
103 var gain4 = context.createGain(); | |
104 | |
105 source.buffer = buffer1ch; | |
106 | |
107 source.connect(gain1); | |
108 source.connect(gain2); | |
109 source.connect(gain3); | |
110 gain1.connect(context.destination); | |
111 gain2.connect(context.destination); | |
112 gain3.connect(context.destination); | |
113 source.start(); | |
114 | |
115 source.disconnect(gain2); | |
116 | |
117 // gain2 is already disconnected. Exception should be thrown. | |
118 Should.throwWithType(function () { | |
119 gain1.disconnect(gain2); | |
120 }, 'InvalidAccessError'); | |
121 | |
122 // gain1 and gain4 are not connected. Exception should not be thrown. | |
123 Should.throwWithType(function () { | |
124 gain1.disconnect(gain4); | |
125 }, 'InvalidAccessError'); | |
126 | |
127 context.oncomplete = function (event) { | |
128 var channelData = event.renderedBuffer.getChannelData(0); | |
129 | |
130 // The |sum| gain node should produce value 2. (1 + 0 + 1 = 2) | |
131 Should.haveValueInChannel(2, channelData); | |
132 | |
133 done(); | |
134 }; | |
135 | |
136 context.startRendering(); | |
137 }); | |
138 | |
139 // Task 4: test disconnect(AudioNode, output) method. | |
140 audit.defineTask('disconnect(AudioNode, output)', function (done) { | |
141 var context = new OfflineAudioContext(3, 128, 44100); | |
142 var source = context.createBufferSource(); | |
143 var buffer3ch = createTestingBuffer(context, 3, 128); | |
144 var splitter = context.createChannelSplitter(3); | |
145 var sum = context.createGain(); | |
146 var orphan = context.createGain(); | |
147 | |
148 source.buffer = buffer3ch; | |
149 | |
150 source.connect(splitter); | |
151 splitter.connect(sum, 0); | |
152 splitter.connect(sum, 1); | |
153 splitter.connect(sum, 2); | |
154 sum.connect(context.destination); | |
155 source.start(); | |
156 | |
157 splitter.disconnect(sum, 0); | |
158 | |
159 // There is no output #3 in the splitter. An exception should be thrown. | |
160 Should.throwWithType(function () { | |
161 splitter.disconnect(sum, 3); | |
162 }, 'IndexSizeError'); | |
163 | |
164 // No valid connection to |orphan|. An exception should be thrown. | |
165 Should.throwWithType(function () { | |
166 splitter.disconnect(orphan, 0); | |
167 }, 'InvalidAccessError'); | |
168 | |
169 context.oncomplete = function (event) { | |
170 var channelData0 = event.renderedBuffer.getChannelData(0); | |
171 | |
172 // The |sum| gain node should produce value 5. (0 + 2 + 3 = 5) | |
173 Should.haveValueInChannel(5, channelData0); | |
174 | |
175 done(); | |
176 }; | |
177 | |
178 context.startRendering(); | |
179 }); | |
180 | |
181 // Task 5: test disconnect(AudioNode, output, input) method. | |
182 audit.defineTask('disconnect(AudioNode, output, input)', function (done) { | |
183 var context = new OfflineAudioContext(3, 128, 44100); | |
184 var source = context.createBufferSource(); | |
185 var buffer3ch = createTestingBuffer(context, 3, 128); | |
186 var splitter = context.createChannelSplitter(3); | |
187 var merger = context.createChannelMerger(3); | |
188 var orphan = context.createGain(); | |
189 | |
190 context.destination.channelCount = 3; | |
191 context.destination.channelCountMode = 'explicit'; | |
192 source.buffer = buffer3ch; | |
193 | |
194 source.connect(splitter); | |
195 splitter.connect(merger, 0, 0); | |
196 splitter.connect(merger, 1, 1); | |
197 splitter.connect(merger, 2, 2); | |
198 merger.connect(context.destination); | |
199 source.start(); | |
200 | |
201 splitter.disconnect(merger, 2, 2); | |
202 | |
203 // Orphan doesn't have a connection. An exception should be thrown. | |
204 Should.throwWithType(function () { | |
205 splitter.disconnect(orphan, 0, 0); | |
206 }, 'InvalidAccessError'); | |
207 | |
208 // The output index is out of bound. An exception should be thrown. | |
209 Should.throwWithType(function () { | |
210 splitter.disconnect(merger, 3, 0); | |
211 }, 'IndexSizeError'); | |
212 | |
213 context.oncomplete = function (event) { | |
214 var channelData0 = event.renderedBuffer.getChannelData(0); | |
215 var channelData1 = event.renderedBuffer.getChannelData(1); | |
216 | |
217 // Each channel should have [1] and [2] respectively. | |
218 Should.haveValueInChannel(1, channelData0); | |
219 Should.haveValueInChannel(2, channelData1); | |
220 | |
221 done(); | |
222 }; | |
223 | |
224 context.startRendering(); | |
225 }); | |
226 | |
227 audit.defineTask('finish', function (done) { | |
228 finishJSTest(); | |
229 done(); | |
230 }); | |
231 | |
232 audit.runTasks( | |
233 'disconnect()', | |
234 'disconnect(output)', | |
235 'disconnect(AudioNode)', | |
236 'disconnect(AudioNode, output)', | |
237 'disconnect(AudioNode, output, input)', | |
238 'finish' | |
239 ); | |
240 | |
241 successfullyParsed = true; | |
242 </script> | |
243 </body> | |
244 | |
245 </html> | |
OLD | NEW |