Commit 8bef0bcb authored by rtoy's avatar rtoy Committed by Commit bot

Convert constructor/iirfilter.html to new Audit

Manually convert constructor/iirfilter.html to use new Audit.

Updated new-audionodeoptions to allow specifying constructor option
when testing the default constructor.

BUG=704976
TEST=constructor/iirfilter.html

Review-Url: https://codereview.chromium.org/2859193003
Cr-Commit-Position: refs/heads/master@{#469489}
parent 8dae3f2f
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
<script src="../../resources/testharness.js"></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="../../resources/testharnessreport.js"></script>
<script src="../resources/audit-util.js"></script> <script src="../resources/audit-util.js"></script>
<script src="../resources/audio-testing.js"></script> <script src="../resources/audit.js"></script>
<script src="audionodeoptions.js"></script> <script src="new-audionodeoptions.js"></script>
</head> </head>
<body> <body>
...@@ -15,72 +15,58 @@ ...@@ -15,72 +15,58 @@
var audit = Audit.createTaskRunner(); var audit = Audit.createTaskRunner();
audit.defineTask("initialize", function (taskDone) { audit.define('initialize', (task, should) => {
Should("context = new OfflineAudioContext(...)", function () { context = initializeContext(should);
context = new OfflineAudioContext(1, 1, 48000); task.done();
}).notThrow();
taskDone();
}); });
audit.defineTask("invalid constructor", function (taskDone) { audit.define('invalid constructor', (task, should) => {
var node; testInvalidConstructor(should, 'IIRFilterNode', context);
var success = true; task.done();
success = Should("new IIRFilterNode()", function () {
node = new IIRFilterNode();
}).throw("TypeError");
success = Should("new IIRFilterNode(1)", function () {
node = new IIRFilterNode(1) && success;
}).throw("TypeError");
success = Should("new IIRFilterNode(context, 42)", function () {
node = new IIRFilterNode(context, 42) && success;
}).throw("TypeError");
Should("Invalid constructors", success)
.summarize(
"correctly threw errors",
"did not throw errors in all cases");
taskDone();
}); });
audit.defineTask("test AudioNodeOptions", function (taskDone) { audit.define('default constructor', (task, should) => {
testAudioNodeOptions(context, "IIRFilterNode", { let prefix = 'node0';
additionalOptions: { let node = testDefaultConstructor(should, 'IIRFilterNode', context, {
feedforward: [1, 1], prefix: prefix,
feedback: [1, .5] numberOfInputs: 1,
} numberOfOutputs: 1,
channelCount: 2,
channelCountMode: 'max',
channelInterpretation: 'speakers',
constructorOptions: {feedforward: [1], feedback: [1, -.9]}
}); });
taskDone();
task.done();
}); });
audit.defineTask("constructor options", function (taskDone) { audit.define('test AudioNodeOptions', (task, should) => {
testAudioNodeOptions(
should, context, 'IIRFilterNode',
{additionalOptions: {feedforward: [1, 1], feedback: [1, .5]}});
task.done();
});
audit.define('constructor options', (task, should) => {
var node; var node;
var success = true;
var options = {feedback: [1, .5]};
var options = { should(
feedback: [1, .5] () => {
}; node = new IIRFilterNode(context, options);
success = Should("node = new IIRFilterNode(, " + JSON.stringify(options) + ")", },
function () { 'node = new IIRFilterNode(, ' + JSON.stringify(options) + ')')
node = new IIRFilterNode(context, options); .throw('TypeError');
}).throw("TypeError") && success;
options = {feedforward: [1, 0.5]};
options = { should(
feedforward: [1, 0.5] () => {
} node = new IIRFilterNode(context, options);
success = Should("node = new IIRFilterNode(c, " + JSON.stringify(options) + ")", },
function () { 'node = new IIRFilterNode(c, ' + JSON.stringify(options) + ')')
node = new IIRFilterNode(context, options); .throw('TypeError');
}).throw("TypeError") && success;
task.done();
Should("new AnalyserNode() with options", success)
.summarize(
"constructed with correct attributes",
"was not constructed correctly");
taskDone();
}); });
// Test functionality of constructor. This is needed because we have no // Test functionality of constructor. This is needed because we have no
...@@ -89,31 +75,30 @@ ...@@ -89,31 +75,30 @@
// TODO(rtoy): This functionality test should be moved out to a separate // TODO(rtoy): This functionality test should be moved out to a separate
// file. // file.
audit.defineTask("functionality", function (taskDone) { audit.define('functionality', (task, should) => {
var options = { var options = {feedback: [1, .5], feedforward: [1, 1]};
feedback: [1, .5],
feedforward: [1, 1]
};
// Create two-channel offline context; sample rate and length are fairly // Create two-channel offline context; sample rate and length are fairly
// arbitrary. Channel 0 contains the test output and channel 1 contains // arbitrary. Channel 0 contains the test output and channel 1 contains
// the expected output. // the expected output.
var sampleRate = 48000; var sampleRate = 48000;
var renderLength = 0.125; var renderLength = 0.125;
var testContext = new OfflineAudioContext(2, renderLength * sampleRate, sampleRate); var testContext =
new OfflineAudioContext(2, renderLength * sampleRate, sampleRate);
// The test node uses the constructor. The reference node creates the // The test node uses the constructor. The reference node creates the
// same filter but uses the old factory method. // same filter but uses the old factory method.
var testNode = new IIRFilterNode(testContext, options); var testNode = new IIRFilterNode(testContext, options);
var refNode = testContext.createIIRFilter( var refNode = testContext.createIIRFilter(
Float32Array.from(options.feedforward), Float32Array.from(options.feedforward),
Float32Array.from(options.feedback)); Float32Array.from(options.feedback));
var source = testContext.createOscillator(); var source = testContext.createOscillator();
source.connect(testNode); source.connect(testNode);
source.connect(refNode); source.connect(refNode);
var merger = testContext.createChannelMerger(testContext.destination.channelCount); var merger = testContext.createChannelMerger(
testContext.destination.channelCount);
testNode.connect(merger, 0, 0); testNode.connect(merger, 0, 0);
refNode.connect(merger, 0, 1); refNode.connect(merger, 0, 1);
...@@ -121,18 +106,20 @@ ...@@ -121,18 +106,20 @@
merger.connect(testContext.destination); merger.connect(testContext.destination);
source.start(); source.start();
testContext.startRendering().then(function (resultBuffer) { testContext.startRendering()
var actual = resultBuffer.getChannelData(0); .then(function(resultBuffer) {
var expected = resultBuffer.getChannelData(1); var actual = resultBuffer.getChannelData(0);
var expected = resultBuffer.getChannelData(1);
// The output from the two channels should be exactly equal because
// exactly the same IIR filter should have been created. // The output from the two channels should be exactly equal
Should("Output of filter using new IIRFilter(...)", actual) // because exactly the same IIR filter should have been created.
.beEqualToArray(expected); should(actual, 'Output of filter using new IIRFilter(...)')
}).then(taskDone); .beEqualToArray(expected);
})
.then(() => task.done());
}); });
audit.runTasks(); audit.run();
</script> </script>
</body> </body>
</html> </html>
...@@ -190,12 +190,17 @@ function testInvalidConstructor(should, name, context) { ...@@ -190,12 +190,17 @@ function testInvalidConstructor(should, name, context) {
function testDefaultConstructor(should, name, context, options) { function testDefaultConstructor(should, name, context, options) {
let node; let node;
let message = options.prefix + ' = new ' + name + '(context';
if (options.constructorOptions)
message += ', ' + JSON.stringify(options.constructorOptions);
message += ')'
should(() => { should(() => {
node = new window[name](context); node = new window[name](context, options.constructorOptions);
}, options.prefix + ' = new ' + name + '(context)').notThrow(); }, message).notThrow();
should(node instanceof window[name], options.prefix + ' instanceof ' + name) should(node instanceof window[name], options.prefix + ' instanceof ' + name)
.beEqualTo(true); .beEqualTo(true);
should(node.numberOfInputs, options.prefix + '.numberOfInputs') should(node.numberOfInputs, options.prefix + '.numberOfInputs')
.beEqualTo(options.numberOfInputs); .beEqualTo(options.numberOfInputs);
should(node.numberOfOutputs, options.prefix + '.numberOfOutputs') should(node.numberOfOutputs, options.prefix + '.numberOfOutputs')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment