blob: 9751dd6c5bb932259574f3d80efbf72f835f0042 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../fast/js/resources/js-test-pre.js"></script>
<script src="resources/audio-testing.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description("Basic tests for BiquadFilterNode.");
var context = 0;
function runTest() {
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
window.jsTestIsAsync = true;
context = new webkitAudioContext();
var filter = context.createBiquadFilter();
if (filter.numberOfInputs === 1)
testPassed("BiquadFilterNode has one input.");
else
testFailed("BiquadFilterNode should have one input.");
if (filter.numberOfOutputs === 1)
testPassed("BiquadFilterNode has one output.");
else
testFailed("BiquadFilterNode should have one output.");
if (filter.type === "lowpass")
testPassed("Biquad filter defaults to low-pass filter.");
else
testFailed("Biquad filter should default to low-pass filter.");
if (filter.frequency.value === 350)
testPassed("The default value of frequency is 350.");
else
testFailed("The default value of frequency should be 350.");
if (filter.Q.value === 1)
testPassed("The default value of Q is 1.");
else
testFailed("The default value of Q should be 1.");
if (filter.gain.value === 0)
testPassed("The default value of gain is 0.");
else
testFailed("The default value of gain should be 0.");
// Check that all legal filter types can be set.
var filterTypeArray = [{type: "lowpass", integerType: filter.LOWPASS},
{type: "highpass", integerType: filter.HIGHPASS},
{type: "bandpass", integerType: filter.BANDPASS},
{type: "lowshelf", integerType: filter.LOWSHELF},
{type: "highshelf", integerType: filter.HIGHSHELF},
{type: "peaking", integerType: filter.PEAKING},
{type: "notch", integerType: filter.NOTCH},
{type: "allpass", integerType: filter.ALLPASS}];
for (var i = 0; i < filterTypeArray.length; ++i) {
try {
filter.type = filterTypeArray[i].type;
if (filter.type === filterTypeArray[i].type) {
var message = "Biquad filter type '" + filterTypeArray[i].type + "' is settable.";
testPassed(message);
} else {
var message = "Biquad filter type '" + filterTypeArray[i].type + "' was not correctly set.";
testFailed(message);
}
} catch(e) {
var message = "Biquad filter type " + i + " should not throw exception.";
testFailed(message);
}
}
// For legacy support, verify that we can set the type attribute as an integer value and
// verify that this translates correctly to the WebIDL enum value.
for (var i = 0; i < filterTypeArray.length; ++i) {
try {
filter.type = filterTypeArray[i].integerType;
if (filter.type === filterTypeArray[i].type && filterTypeArray[i].integerType === i) {
var message = "Biquad filter type " + i + " is settable using legacy integer value.";
testPassed(message);
} else {
var message = "Biquad filter type " + i + " was not correctly set using legacy integer value.";
testFailed(message);
}
} catch(e) {
var message = "Biquad filter type " + i + " should not throw exception using legacy integer value.";
testFailed(message);
}
}
// Check that illegal filter type throws.
try {
filter.type = filter.ALLPASS + 1;
testFailed("Illegal filter type should throw exception.");
} catch(e) {
testPassed("Illegal filter type correctly throws exception.");
}
// Check specifically that we throw a TypeError.
shouldThrowTypeError(function() { filter.type = "xyz12349jfksd"; }, "Setting .type to illegal string value");
shouldThrowTypeError(function() { filter.type = new Float32Array(1); }, "Setting .type to illegal type of Float32Array");
finishJSTest();
}
runTest();
</script>
<script src="../fast/js/resources/js-test-post.js"></script>
</body>
</html>