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

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: Test for AudioParam disconnection 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
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..dca85445e50d4d002cfe07a4dd911985b9090438 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) {
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
- 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,74 @@ function shouldThrowTypeError(func, text) {
}
};
-})();
+})();
+
+
+// Create a channel buffer for testing. Push a channel index value into the
+// each channel buffer. The channel index is between 1 and |numChannels|.
+// For example, a 4 channel buffer will have values [1, 2, 3, 4] for each
+// 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.
+function createTestingBuffer(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;
+}
+
+// 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
+function getTaskSummary(func) {
+ var content = func.toString().replace(/(\s|\t|\r\n|\n|\r)/gm, '');
+ return '"' + content.slice(11, 30) + '..."';
+}
+
+
+// |Should| test utilities. Note that testPassed(), testFailed() are from
+// resources/js-test.js.
+var Should = {};
+
+// Expect exception with a certin type. If type is undefined, it only checks for
+// the exception.
+Should.throwWithType = function (func, type) {
+ try {
+ func();
+ var content = Expect.getTaskSummary(func);
+ testFailed('Exception should be thrown from '+ content);
+ } catch (e) {
+ if (e.name === type || type === undefined)
+ testPassed(e.name + ' was thrown as expected.');
+ else
+ 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.
+ }
+};
+
+// Expect not to throw an exception.
+Should.notThrow = function (func) {
+ try {
+ func();
+ testPassed('Error was not thrown as expected.');
+ } catch (e) {
+ var content = Expect.getFunctionContent(func);
+ testFailed('Error was not expected but got ' + e.name + ' from ' + content);
+ }
+};
+
+
+// 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.
+Should.haveValueInChannel = function (value, channelData) {
+ 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.
+ for (var i = 0; i < channelData.length; i++) {
+ if (channelData[i] !== value) {
+ flag = false;
+ break;
+ }
+ }
+ if (flag)
+ 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.
+ else
+ 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.
+};

Powered by Google App Engine
This is Rietveld 408576698