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

Side by Side Diff: LayoutTests/webaudio/resources/audio-testing.js

Issue 886173004: Fix AudioNode.disconnect() to support selective disconnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Conflict solved. Created 5 years, 9 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
« no previous file with comments | « LayoutTests/webaudio/dom-exceptions-expected.txt ('k') | Source/modules/webaudio/AudioNode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 createTestingAudioBuffer(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 // Generate a string out of function. Useful when throwing an error/exception
262 // with a description. It creates strings from a function, then extract the
263 // function body and trim out leading and trailing white spaces.
264 function getTaskSummary(func) {
265 var lines = func.toString().split('\n').slice(1, -1);
266 lines = lines.map(function (str) { return str.trim(); });
267 lines = lines.join(' ');
268 return '"' + lines + '"';
269 }
270
271 // The name space for |Should| test utility. Dependencies: testPassed(),
272 // testFailed() from resources/js-test.js
273 var Should = {};
274
275 // Expect an exception to be thrown with a certain type.
276 Should.throwWithType = function (type, func) {
277 var summary = getTaskSummary(func);
278 try {
279 func();
280 testFailed(summary + ' should throw ' + type + '.');
281 } catch (e) {
282 if (e.name === type)
283 testPassed(summary + ' threw exception ' + e.name + '.');
284 else
285 testFailed(summary + ' should throw ' + type + '. Threw exception ' + e.name + '.');
286 }
287 };
288
289 // Expect not to throw an exception.
290 Should.notThrow = function (func) {
291 var summary = getTaskSummary(func);
292 try {
293 func();
294 testPassed(summary + ' did not throw exception.');
295 } catch (e) {
296 testFailed(summary + ' should not throw exception. Threw exception ' + e .name + '.');
297 }
298 };
299
300
301 // Verify if the channelData array contains a single constant |value|.
302 Should.haveValueInChannel = function (value, channelData) {
303 var mismatch = {};
304 for (var i = 0; i < channelData.length; i++) {
305 if (channelData[i] !== value) {
306 mismatch[i] = value;
307 }
308 }
309
310 var numberOfmismatches = Object.keys(mismatch).length;
311 if (numberOfmismatches === 0) {
312 testPassed('ChannelData has expected values (' + value + ').');
313 } else {
314 testFailed(numberOfmismatches + ' values in ChannelData are not equal to ' + value + ':');
315 for (var index in mismatch) {
316 console.log('[' + index + '] : ' + mismatch[index]);
317 }
318 }
319 };
OLDNEW
« no previous file with comments | « LayoutTests/webaudio/dom-exceptions-expected.txt ('k') | Source/modules/webaudio/AudioNode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698