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

Unified Diff: third_party/WebKit/LayoutTests/webaudio/AudioNode/audionode-channel-rules.html

Issue 2651623004: Convert more AudioNode tests to use testharness (Closed)
Patch Set: Rebase Created 3 years, 11 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: third_party/WebKit/LayoutTests/webaudio/AudioNode/audionode-channel-rules.html
diff --git a/third_party/WebKit/LayoutTests/webaudio/AudioNode/audionode-channel-rules.html b/third_party/WebKit/LayoutTests/webaudio/AudioNode/audionode-channel-rules.html
index 487394e3bcc08b0c1c3373f273308f13c5128fc3..b4e22931e92c6a1a78ad37741edac6b2455b8110 100644
--- a/third_party/WebKit/LayoutTests/webaudio/AudioNode/audionode-channel-rules.html
+++ b/third_party/WebKit/LayoutTests/webaudio/AudioNode/audionode-channel-rules.html
@@ -2,31 +2,39 @@
<html>
<head>
-<script src="../../resources/js-test.js"></script>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
<script src="../resources/audit-util.js"></script>
-<script src="../resources/audio-testing.js"></script>
+<script src="../resources/audit.js"></script>
<script src="../resources/mixing-rules.js"></script>
</head>
<body>
<script>
-description("Channel mixing rules for AudioNodes.");
-
-var context = 0;
-var sampleRate = 44100;
-var renderNumberOfChannels = 8;
-var singleTestFrameLength = 8;
-var testBuffers;
-
-// A list of connections to an AudioNode input, each of which is to be used in one or more specific test cases.
-// Each element in the list is a string, with the number of connections corresponding to the length of the string,
-// and each character in the string is from '1' to '8' representing a 1 to 8 channel connection (from an AudioNode output).
-// For example, the string "128" means 3 connections, having 1, 2, and 8 channels respectively.
-var connectionsList = ["1", "2", "3", "4", "5", "6", "7", "8", "11", "12", "14", "18", "111", "122", "123", "124", "128"];
-
-// A list of mixing rules, each of which will be tested against all of the connections in connectionsList.
-var mixingRulesList = [
+let audit = Audit.createTaskRunner();
+let context = 0;
+let sampleRate = 44100;
+let renderNumberOfChannels = 8;
+let singleTestFrameLength = 8;
+let testBuffers;
+
+// A list of connections to an AudioNode input, each of which is to be used in
+// one or more specific test cases. Each element in the list is a string, with
+// the number of connections corresponding to the length of the string, and each
+// character in the string is from '1' to '8' representing a 1 to 8 channel
+// connection (from an AudioNode output).
+
+// For example, the string "128" means 3 connections, having 1, 2, and 8
+// channels respectively.
+
+let connectionsList = ["1", "2", "3", "4", "5", "6", "7", "8", "11", "12",
+ "14", "18", "111", "122", "123", "124", "128"
+];
+
+// A list of mixing rules, each of which will be tested against all of the
+// connections in connectionsList.
+let mixingRulesList = [
{channelCount: 2, channelCountMode: "max", channelInterpretation: "speakers"},
{channelCount: 4, channelCountMode: "clamped-max", channelInterpretation: "speakers"},
@@ -42,42 +50,46 @@ var mixingRulesList = [
{channelCount: 8, channelCountMode: "explicit", channelInterpretation: "discrete"},
];
-var numberOfTests = mixingRulesList.length * connectionsList.length;
+let numberOfTests = mixingRulesList.length * connectionsList.length;
// Print out the information for an individual test case.
-function printTestInformation(testNumber, actualBuffer, expectedBuffer, frameLength, frameOffset) {
- var actual = stringifyBuffer(actualBuffer, frameLength);
- var expected = stringifyBuffer(expectedBuffer, frameLength, frameOffset);
- debug('TEST CASE #' + testNumber + '\n');
- debug('actual channels:\n' + actual);
- debug('expected channels:\n' + expected);
+function printTestInformation(testNumber, actualBuffer, expectedBuffer,
+ frameLength, frameOffset) {
+ let actual = stringifyBuffer(actualBuffer, frameLength);
+ let expected = stringifyBuffer(expectedBuffer, frameLength, frameOffset);
+ debug('TEST CASE #' + testNumber + '\n');
+ debug('actual channels:\n' + actual);
+ debug('expected channels:\n' + expected);
}
-function scheduleTest(testNumber, connections, channelCount, channelCountMode, channelInterpretation) {
- var mixNode = context.createGain();
+function scheduleTest(testNumber, connections, channelCount, channelCountMode,
+ channelInterpretation) {
+ let mixNode = context.createGain();
mixNode.channelCount = channelCount;
mixNode.channelCountMode = channelCountMode;
mixNode.channelInterpretation = channelInterpretation;
mixNode.connect(context.destination);
- for (var i = 0; i < connections.length; ++i) {
- var connectionNumberOfChannels = connections.charCodeAt(i) - "0".charCodeAt(0);
+ for (let i = 0; i < connections.length; ++i) {
+ let connectionNumberOfChannels = connections.charCodeAt(i) - "0".charCodeAt(
+ 0);
- var source = context.createBufferSource();
+ let source = context.createBufferSource();
// Get a buffer with the right number of channels, converting from 1-based to 0-based index.
- var buffer = testBuffers[connectionNumberOfChannels - 1];
+ let buffer = testBuffers[connectionNumberOfChannels - 1];
source.buffer = buffer;
source.connect(mixNode);
// Start at the right offset.
- var sampleFrameOffset = testNumber * singleTestFrameLength;
- var time = sampleFrameOffset / sampleRate;
+ let sampleFrameOffset = testNumber * singleTestFrameLength;
+ let time = sampleFrameOffset / sampleRate;
source.start(time);
}
}
-function checkTestResult(renderedBuffer, testNumber, connections, channelCount, channelCountMode, channelInterpretation) {
- var s = "connections: " + connections + ", " + channelCountMode;
+function checkTestResult(renderedBuffer, testNumber, connections, channelCount,
+ channelCountMode, channelInterpretation, should) {
+ let s = "connections: " + connections + ", " + channelCountMode;
// channelCount is ignored in "max" mode.
if (channelCountMode == "clamped-max" || channelCountMode == "explicit") {
@@ -86,15 +98,18 @@ function checkTestResult(renderedBuffer, testNumber, connections, channelCount,
s += ", " + channelInterpretation;
- var computedNumberOfChannels = computeNumberOfChannels(connections, channelCount, channelCountMode);
+ let computedNumberOfChannels = computeNumberOfChannels(connections,
+ channelCount, channelCountMode);
// Create a zero-initialized silent AudioBuffer with computedNumberOfChannels.
- var destBuffer = context.createBuffer(computedNumberOfChannels, singleTestFrameLength, context.sampleRate);
+ let destBuffer = context.createBuffer(computedNumberOfChannels,
+ singleTestFrameLength, context.sampleRate);
// Mix all of the connections into the destination buffer.
- for (var i = 0; i < connections.length; ++i) {
- var connectionNumberOfChannels = connections.charCodeAt(i) - "0".charCodeAt(0);
- var sourceBuffer = testBuffers[connectionNumberOfChannels - 1]; // convert from 1-based to 0-based index
+ for (let i = 0; i < connections.length; ++i) {
+ let connectionNumberOfChannels = connections.charCodeAt(i) - "0".charCodeAt(
+ 0);
+ let sourceBuffer = testBuffers[connectionNumberOfChannels - 1]; // convert from 1-based to 0-based index
if (channelInterpretation == "speakers") {
speakersSum(sourceBuffer, destBuffer);
@@ -106,70 +121,69 @@ function checkTestResult(renderedBuffer, testNumber, connections, channelCount,
}
// Use this when debugging mixing rules.
- // printTestInformation(testNumber, renderedBuffer, destBuffer, singleTestFrameLength, sampleFrameOffset);
+ // printTestInformation(testNumber, renderedBuffer, destBuffer,
+ // singleTestFrameLength, sampleFrameOffset);
- // Validate that destBuffer matches the rendered output.
- // We need to check the rendered output at a specific sample-frame-offset corresponding
- // to the specific test case we're checking for based on testNumber.
+ // Validate that destBuffer matches the rendered output. We need to check
+ // the rendered output at a specific sample-frame-offset corresponding to
+ // the specific test case we're checking for based on testNumber.
- var sampleFrameOffset = testNumber * singleTestFrameLength;
- for (var c = 0; c < renderNumberOfChannels; ++c) {
- var renderedData = renderedBuffer.getChannelData(c);
- for (var frame = 0; frame < singleTestFrameLength; ++frame) {
- var renderedValue = renderedData[frame + sampleFrameOffset];
+ let sampleFrameOffset = testNumber * singleTestFrameLength;
+ for (let c = 0; c < renderNumberOfChannels; ++c) {
+ let renderedData = renderedBuffer.getChannelData(c);
+ for (let frame = 0; frame < singleTestFrameLength; ++frame) {
+ let renderedValue = renderedData[frame + sampleFrameOffset];
- var expectedValue = 0;
+ let expectedValue = 0;
if (c < destBuffer.numberOfChannels) {
- var expectedData = destBuffer.getChannelData(c);
+ let expectedData = destBuffer.getChannelData(c);
expectedValue = expectedData[frame];
}
- // We may need to add an epsilon in the comparison if we add more test vectors.
+ // We may need to add an epsilon in the comparison if we add more
+ // test vectors.
if (renderedValue != expectedValue) {
- var message = s + "rendered: " + renderedValue + " expected: " + expectedValue + " channel: " + c + " frame: " + frame;
- testFailed(s);
+ let message = s + "rendered: " + renderedValue + " expected: " +
+ expectedValue + " channel: " + c + " frame: " + frame;
+ //testFailed(s);
+ should(renderedValue, s)
+ .beEqualTo(expectedValue);
return;
}
}
}
- testPassed(s);
+ should(true, s)
+ .beTrue();
}
-function checkResult(event) {
- var buffer = event.renderedBuffer;
-
+function checkResult(buffer, should) {
// Sanity check result.
- if (buffer.length != numberOfTests * singleTestFrameLength || buffer.numberOfChannels != renderNumberOfChannels) {
- testFailed("OfflineAudioContext result not of expected size!");
- finishJSTest();
- return;
- }
+ should(buffer.length, "Rendered number of frames")
+ .beEqualTo(numberOfTests * singleTestFrameLength);
+ should(buffer.numberOfChannels, "Rendered number of channels")
+ .beEqualTo(renderNumberOfChannels);
// Check all the tests.
- var testNumber = 0;
- for (var m = 0; m < mixingRulesList.length; ++m) {
- var mixingRules = mixingRulesList[m];
- for (var i = 0; i < connectionsList.length; ++i, ++testNumber) {
- checkTestResult(buffer, testNumber, connectionsList[i], mixingRules.channelCount, mixingRules.channelCountMode, mixingRules.channelInterpretation);
+ let testNumber = 0;
+ for (let m = 0; m < mixingRulesList.length; ++m) {
+ let mixingRules = mixingRulesList[m];
+ for (let i = 0; i < connectionsList.length; ++i, ++testNumber) {
+ checkTestResult(buffer, testNumber, connectionsList[i],
+ mixingRules.channelCount, mixingRules.channelCountMode,
+ mixingRules.channelInterpretation, should);
}
}
-
- finishJSTest();
}
-function runTest() {
- if (window.testRunner) {
- testRunner.dumpAsText();
- testRunner.waitUntilDone();
- }
-
- window.jsTestIsAsync = true;
+audit.define("test", function (task, should) {
+ task.describe("Channel mixing rules for AudioNodes");
- // Create 8-channel offline audio context.
- // Each test will render 8 sample-frames starting at sample-frame position testNumber * 8.
- var totalFrameLength = numberOfTests * singleTestFrameLength;
- context = new OfflineAudioContext(renderNumberOfChannels, totalFrameLength, sampleRate);
+ // Create 8-channel offline audio context. Each test will render 8
+ // sample-frames starting at sample-frame position testNumber * 8.
+ let totalFrameLength = numberOfTests * singleTestFrameLength;
+ context = new OfflineAudioContext(renderNumberOfChannels,
+ totalFrameLength, sampleRate);
// Set destination to discrete mixing.
context.destination.channelCount = renderNumberOfChannels;
@@ -178,25 +192,32 @@ function runTest() {
// Create test buffers from 1 to 8 channels.
testBuffers = new Array();
- for (var i = 0; i < renderNumberOfChannels; ++i) {
- testBuffers[i] = createShiftedImpulseBuffer(context, i + 1, singleTestFrameLength);
+ for (let i = 0; i < renderNumberOfChannels; ++i) {
+ testBuffers[i] = createShiftedImpulseBuffer(context, i + 1,
+ singleTestFrameLength);
}
// Schedule all the tests.
- var testNumber = 0;
- for (var m = 0; m < mixingRulesList.length; ++m) {
- var mixingRules = mixingRulesList[m];
- for (var i = 0; i < connectionsList.length; ++i, ++testNumber) {
- scheduleTest(testNumber, connectionsList[i], mixingRules.channelCount, mixingRules.channelCountMode, mixingRules.channelInterpretation);
+ let testNumber = 0;
+ for (let m = 0; m < mixingRulesList.length; ++m) {
+ let mixingRules = mixingRulesList[m];
+ for (let i = 0; i < connectionsList.length; ++i, ++testNumber) {
+ scheduleTest(testNumber, connectionsList[i], mixingRules.channelCount,
+ mixingRules.channelCountMode, mixingRules.channelInterpretation
+ );
}
}
// Render then check results.
- context.oncomplete = checkResult;
- context.startRendering();
-}
-
-runTest();
+ //context.oncomplete = checkResult;
+ context.startRendering()
+ .then(buffer => {
+ checkResult(buffer, should);
+ task.done();
+ });;
+});
+
+audit.run();
</script>

Powered by Google App Engine
This is Rietveld 408576698