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) { | |
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 an AudioBuffer for test verification. Fill an incremental index value | |
246 // into the each channel in the buffer. The channel index is between 1 and | |
247 // |numChannels|. For example, a 4-channel buffer created by this function will | |
248 // contain values 1, 2, 3 and 4 for each channel respectively. | |
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 // Returns a truncated string out of a function. This is to generate a brief | |
262 // description of function when throwing an error/exception message. | |
263 function getTaskSummary(func) { | |
264 var content = func.toString().replace(/(\s|\t|\r\n|\n|\r)/gm, ''); | |
Raymond Toy
2015/02/12 19:45:53
Is this going to do something sensible if the func
hongchan
2015/02/13 01:16:57
It works well with the single quote and Google JS
Raymond Toy
2015/02/13 17:16:44
That's going to be hard for me to get used to (sin
| |
265 return '"' + content.slice(11, -2) + '"'; | |
Raymond Toy
2015/02/12 19:45:53
What if the function is many, many lines long? Do
hongchan
2015/02/13 01:16:57
I can't cover the multiline function. Would you ra
Raymond Toy
2015/02/13 17:16:44
Multiline is ok. I'm not sure I like squashing al
| |
266 } | |
267 | |
268 // The name space for |Should| test utility. Dependencies: testPassed(), | |
269 // testFailed() from resources/js-test.js | |
270 var Should = {}; | |
271 | |
272 // Expect an exception to be thrown with a certain type. | |
273 Should.throwWithType = function (type, func) { | |
274 var summary = getTaskSummary(func); | |
275 try { | |
276 func(); | |
277 testFailed(summary + ' should throw ' + type + '.'); | |
278 } catch (e) { | |
279 if (e.name === type) | |
280 testPassed(summary + ' threw exception ' + e.name + '.'); | |
281 else | |
282 testFailed(summary + ' should throw ' + type + '. Threw exception ' + e.name + '.'); | |
283 } | |
284 }; | |
285 | |
286 // Expect not to throw an exception. | |
287 Should.notThrow = function (func) { | |
288 var summary = getTaskSummary(func); | |
289 try { | |
290 func(); | |
291 testPassed(summary + ' did not throw exception.'); | |
292 } catch (e) { | |
293 testFailed(summary + ' should not throw exception. Threw exception ' + e .name + '.'); | |
294 } | |
295 }; | |
296 | |
297 | |
298 // Verify if the channelData array contains a single constant |value|. | |
299 Should.haveValueInChannel = function (value, channelData) { | |
300 var mistmatch = {}; | |
Raymond Toy
2015/02/12 19:45:53
Typo: mistmatch -> mismatch
hongchan
2015/02/13 01:16:57
Oops. Fixing it.
| |
301 for (var i = 0; i < channelData.length; i++) { | |
302 if (channelData[i] !== value) { | |
303 mistmatch[i] = value; | |
304 } | |
305 } | |
306 | |
307 var numberOfmistmatches = Object.keys(mistmatch).length; | |
308 if (numberOfmistmatches === 0) { | |
309 testPassed('ChannelData has expected values (' + value + ').'); | |
310 } else { | |
311 testFailed(numberOfmistmatches + ' values in ChannelData are not equal t o ' + value + ':'); | |
312 for (var index in mistmatch) { | |
313 console.log('[' + index + '] : ' + mistmatch[index]); | |
314 } | |
315 } | |
316 }; | |
OLD | NEW |