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

Unified 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, 10 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..201b89eca4e2cc103b8d2e606de3a5eb0b9afdce 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,81 @@ 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;
+}
+
+// Generate a string out of function. Useful when throwing an error/exception
+// with a description. It creates strings from a function, then extract the
+// function body and trim out leading and trailing white spaces.
+function getTaskSummary(func) {
+ var lines = func.toString().split('\n').slice(1, -1);
+ lines = lines.map(function (str) { return str.trim(); });
+ lines = lines.join(' ');
+ return '"' + lines + '"';
+}
+
+// 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]);
+ }
+ }
+};
« 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