| Index: LayoutTests/webaudio/resources/audio-testing.js
|
| diff --git a/LayoutTests/webaudio/resources/audio-testing.js b/LayoutTests/webaudio/resources/audio-testing.js
|
| index a1b86494b60d6040c115f70b209973a05212a060..9cf9047077542d4c729f6cd6d2906d8b07b83152 100644
|
| --- a/LayoutTests/webaudio/resources/audio-testing.js
|
| +++ b/LayoutTests/webaudio/resources/audio-testing.js
|
| @@ -175,22 +175,6 @@ function isValidNumber(x) {
|
| return !isNaN(x) && (x != Infinity) && (x != -Infinity);
|
| }
|
|
|
| -function shouldThrowTypeError(func, text) {
|
| - var ok = false;
|
| - try {
|
| - func();
|
| - } catch (e) {
|
| - if (e instanceof TypeError) {
|
| - ok = true;
|
| - }
|
| - }
|
| - if (ok) {
|
| - testPassed(text + " threw TypeError.");
|
| - } else {
|
| - testFailed(text + " should throw TypeError.");
|
| - }
|
| -}
|
| -
|
| // |Audit| is a task runner for web audio test. It makes asynchronous web audio
|
| // testing simple and manageable.
|
| //
|
| @@ -255,4 +239,78 @@ function shouldThrowTypeError(func, text) {
|
| }
|
| };
|
|
|
| -})();
|
| +})();
|
| +
|
| +
|
| +// Create an AudioBuffer for test verification. Fill an incremental index value
|
| +// into the each channel in the buffer. The channel index is between 1 and
|
| +// |numChannels|. For example, a 4-channel buffer created by this function will
|
| +// contain values 1, 2, 3 and 4 for each channel respectively.
|
| +function createTestingAudioBuffer(context, numChannels, length) {
|
| + var buffer = context.createBuffer(numChannels, length, context.sampleRate);
|
| + for (var i = 1; i <= numChannels; i++) {
|
| + var data = buffer.getChannelData(i-1);
|
| + for (var j = 0; j < data.length; j++) {
|
| + // Storing channel index into the channel buffer.
|
| + data[j] = i;
|
| + }
|
| + }
|
| + return buffer;
|
| +}
|
| +
|
| +// Returns a truncated string out of a function. This is to generate a brief
|
| +// description of function when throwing an error/exception message.
|
| +function getTaskSummary(func) {
|
| + var content = func.toString().replace(/(\s|\t|\r\n|\n|\r)/gm, '');
|
| + return '"' + content.slice(11, -2) + '"';
|
| +}
|
| +
|
| +// The name space for |Should| test utility. Dependencies: testPassed(),
|
| +// testFailed() from resources/js-test.js
|
| +var Should = {};
|
| +
|
| +// Expect an exception to be thrown with a certain type.
|
| +Should.throwWithType = function (type, func) {
|
| + var summary = getTaskSummary(func);
|
| + try {
|
| + func();
|
| + testFailed(summary + ' should throw ' + type + '.');
|
| + } catch (e) {
|
| + if (e.name === type)
|
| + testPassed(summary + ' threw exception ' + e.name + '.');
|
| + else
|
| + testFailed(summary + ' should throw ' + type + '. Threw exception ' + e.name + '.');
|
| + }
|
| +};
|
| +
|
| +// Expect not to throw an exception.
|
| +Should.notThrow = function (func) {
|
| + var summary = getTaskSummary(func);
|
| + try {
|
| + func();
|
| + testPassed(summary + ' did not throw exception.');
|
| + } catch (e) {
|
| + testFailed(summary + ' should not throw exception. Threw exception ' + e.name + '.');
|
| + }
|
| +};
|
| +
|
| +
|
| +// Verify if the channelData array contains a single constant |value|.
|
| +Should.haveValueInChannel = function (value, channelData) {
|
| + var mismatch = {};
|
| + for (var i = 0; i < channelData.length; i++) {
|
| + if (channelData[i] !== value) {
|
| + mismatch[i] = value;
|
| + }
|
| + }
|
| +
|
| + var numberOfmismatches = Object.keys(mismatch).length;
|
| + if (numberOfmismatches === 0) {
|
| + testPassed('ChannelData has expected values (' + value + ').');
|
| + } else {
|
| + testFailed(numberOfmismatches + ' values in ChannelData are not equal to ' + value + ':');
|
| + for (var index in mismatch) {
|
| + console.log('[' + index + '] : ' + mismatch[index]);
|
| + }
|
| + }
|
| +};
|
|
|