OLD | NEW |
---|---|
1 if (window.testRunner) | 1 if (window.testRunner) |
2 testRunner.overridePreference("WebKitWebAudioEnabled", "1"); | 2 testRunner.overridePreference("WebKitWebAudioEnabled", "1"); |
3 | 3 |
4 function writeString(s, a, offset) { | 4 function writeString(s, a, offset) { |
5 for (var i = 0; i < s.length; ++i) { | 5 for (var i = 0; i < s.length; ++i) { |
6 a[offset + i] = s.charCodeAt(i); | 6 a[offset + i] = s.charCodeAt(i); |
7 } | 7 } |
8 } | 8 } |
9 | 9 |
10 function writeInt16(n, a, offset) { | 10 function writeInt16(n, a, offset) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 var endFrame = timeToSampleFrame(grainOffset + duration, sampleRate); | 168 var endFrame = timeToSampleFrame(grainOffset + duration, sampleRate); |
169 | 169 |
170 return endFrame - startFrame; | 170 return endFrame - startFrame; |
171 } | 171 } |
172 | 172 |
173 // True if the number is not an infinity or NaN | 173 // True if the number is not an infinity or NaN |
174 function isValidNumber(x) { | 174 function isValidNumber(x) { |
175 return !isNaN(x) && (x != Infinity) && (x != -Infinity); | 175 return !isNaN(x) && (x != Infinity) && (x != -Infinity); |
176 } | 176 } |
177 | 177 |
178 function shouldThrowTypeError(func, text) { | |
Raymond Toy
2015/02/11 21:31:18
No test was using this function?
hongchan
2015/02/12 18:38:00
This is removed and merged into |Should| name spac
| |
179 var ok = false; | |
180 try { | |
181 func(); | |
182 } catch (e) { | |
183 if (e instanceof TypeError) { | |
184 ok = true; | |
185 } | |
186 } | |
187 if (ok) { | |
188 testPassed(text + " threw TypeError."); | |
189 } else { | |
190 testFailed(text + " should throw TypeError."); | |
191 } | |
192 } | |
193 | |
194 // |Audit| is a task runner for web audio test. It makes asynchronous web audio | 178 // |Audit| is a task runner for web audio test. It makes asynchronous web audio |
195 // testing simple and manageable. | 179 // testing simple and manageable. |
196 // | 180 // |
197 // EXAMPLE: | 181 // EXAMPLE: |
198 // | 182 // |
199 // var audit = Audit.createTaskRunner(); | 183 // var audit = Audit.createTaskRunner(); |
200 // // Define test routine. Make sure to call done() when reached at the end. | 184 // // Define test routine. Make sure to call done() when reached at the end. |
201 // audit.defineTask('foo', function (done) { | 185 // audit.defineTask('foo', function (done) { |
202 // var context = new AudioContext(); | 186 // var context = new AudioContext(); |
203 // // do things | 187 // // do things |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 // Start task 0. | 232 // Start task 0. |
249 this.tasks[this.queue[this.currentTask]](done); | 233 this.tasks[this.queue[this.currentTask]](done); |
250 }; | 234 }; |
251 | 235 |
252 return { | 236 return { |
253 createTaskRunner: function () { | 237 createTaskRunner: function () { |
254 return new Tasks(); | 238 return new Tasks(); |
255 } | 239 } |
256 }; | 240 }; |
257 | 241 |
258 })(); | 242 })(); |
243 | |
244 | |
245 // Create a channel buffer for testing. Push a channel index value into the | |
246 // each channel buffer. The channel index is between 1 and |numChannels|. | |
247 // For example, a 4 channel buffer will have values [1, 2, 3, 4] for each | |
248 // channel respectively. | |
Raymond Toy
2015/02/11 21:31:18
I think I'd rephrase this. We're not really pushin
hongchan
2015/02/12 18:38:00
Done.
| |
249 function createTestingBuffer(context, numChannels, length) { | |
250 var buffer = context.createBuffer(numChannels, length, context.sampleRate); | |
251 for (var i = 1; i <= numChannels; i++) { | |
252 var data = buffer.getChannelData(i-1); | |
253 for (var j = 0; j < data.length; j++) { | |
254 // Storing channel index into the channel buffer. | |
255 data[j] = i; | |
256 } | |
257 } | |
258 return buffer; | |
259 } | |
260 | |
261 // Get summarized (truncated) function content. | |
Raymond Toy
2015/02/11 21:31:18
I have no idea what this function is trying to do
hongchan
2015/02/12 18:38:00
I missed that. Will add comment here. This is basi
| |
262 function getTaskSummary(func) { | |
263 var content = func.toString().replace(/(\s|\t|\r\n|\n|\r)/gm, ''); | |
264 return '"' + content.slice(11, 30) + '..."'; | |
265 } | |
266 | |
267 | |
268 // |Should| test utilities. Note that testPassed(), testFailed() are from | |
269 // resources/js-test.js. | |
270 var Should = {}; | |
271 | |
272 // Expect exception with a certin type. If type is undefined, it only checks for | |
273 // the exception. | |
274 Should.throwWithType = function (func, type) { | |
275 try { | |
276 func(); | |
277 var content = Expect.getTaskSummary(func); | |
278 testFailed('Exception should be thrown from '+ content); | |
279 } catch (e) { | |
280 if (e.name === type || type === undefined) | |
281 testPassed(e.name + ' was thrown as expected.'); | |
282 else | |
283 testFailed('Expected ' + type + ' but got ' + e.name); | |
Raymond Toy
2015/02/11 21:31:18
I didn't check, but it would be nice if you kind o
hongchan
2015/02/12 18:38:00
Good idea. Done.
| |
284 } | |
285 }; | |
286 | |
287 // Expect not to throw an exception. | |
288 Should.notThrow = function (func) { | |
289 try { | |
290 func(); | |
291 testPassed('Error was not thrown as expected.'); | |
292 } catch (e) { | |
293 var content = Expect.getFunctionContent(func); | |
294 testFailed('Error was not expected but got ' + e.name + ' from ' + conte nt); | |
295 } | |
296 }; | |
297 | |
298 | |
299 // Expect the channelData to have a certain value. | |
Raymond Toy
2015/02/11 21:31:18
Expand this comment to say that every value in cha
hongchan
2015/02/12 18:38:00
Done.
| |
300 Should.haveValueInChannel = function (value, channelData) { | |
301 var flag = true; | |
Raymond Toy
2015/02/11 21:31:18
s/flag/isConstant/ or some other more meaningful n
hongchan
2015/02/12 18:38:00
Done.
| |
302 for (var i = 0; i < channelData.length; i++) { | |
303 if (channelData[i] !== value) { | |
304 flag = false; | |
305 break; | |
306 } | |
307 } | |
308 if (flag) | |
309 testPassed('ChannelData has expected values.'); | |
Raymond Toy
2015/02/11 21:31:18
Include the expected value in message.
hongchan
2015/02/12 18:38:00
Done.
| |
310 else | |
311 testFailed('ChannelData has invalid values (expected ' + value + ')'); | |
Raymond Toy
2015/02/11 21:31:18
Might be useful for debugging to include the index
hongchan
2015/02/12 18:38:00
Yes, I will come up with a way of doing this.
| |
312 }; | |
OLD | NEW |