Bug 1265408 - Add webplatform-test for IIRFilterNode; r=padenot
MozReview-Commit-ID: qSDxvk60j2
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -36036,16 +36036,22 @@
"url": "/web-animations/timing-model/animations/current-time.html"
}
],
"web-animations/timing-model/animations/set-the-timeline-of-an-animation.html": [
{
"path": "web-animations/timing-model/animations/set-the-timeline-of-an-animation.html",
"url": "/web-animations/timing-model/animations/set-the-timeline-of-an-animation.html"
}
+ ],
+ "webaudio/the-audio-api/the-iirfilternode-interface/test-iirfilternode.html": [
+ {
+ "path": "webaudio/the-audio-api/the-iirfilternode-interface/test-iirfilternode.html",
+ "url": "/webaudio/the-audio-api/the-iirfilternode-interface/test-iirfilternode.html"
+ }
]
}
},
"reftest_nodes": {}
},
"reftest_nodes": {
"2dcontext/building-paths/canvas_complexshapes_arcto_001.htm": [
{
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-iirfilternode-interface/test-iirfilternode.html
@@ -0,0 +1,59 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>Test the IIRFilterNode Interface</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script>
+test(function(t) {
+ var ac = new AudioContext();
+
+ function check_args(arg1, arg2, err, desc) {
+ test(function() {
+ assert_throws(err, function() {
+ ac.createIIRFilter(arg1, arg2)
+ })
+ }, desc)
+ }
+
+ check_args([], [1.0], 'NotSupportedError',
+ 'feedforward coefficients can not be empty');
+
+ check_args([1.0], [], 'NotSupportedError',
+ 'feedback coefficients can not be empty');
+
+ var coeff = new Float32Array(21)
+ coeff[0] = 1.0;
+
+ check_args(coeff, [1.0], 'NotSupportedError',
+ 'more than 20 feedforward coefficients can not be used');
+
+ check_args([1.0], coeff, 'NotSupportedError',
+ 'more than 20 feedback coefficients can not be used');
+
+ check_args([0.0, 0.0], [1.0], 'InvalidStateError',
+ 'at least one feedforward coefficient must be non-zero');
+
+ check_args([0.5, 0.5], [0.0], 'InvalidStateError',
+ 'the first feedback coefficient must be non-zero');
+
+}, "IIRFilterNode coefficients are checked properly");
+
+test(function(t) {
+ var ac = new AudioContext();
+
+ var frequencies = new Float32Array([-1.0, ac.sampleRate*0.5 - 1.0, ac.sampleRate]);
+ var magResults = new Float32Array(3);
+ var phaseResults = new Float32Array(3);
+
+ var filter = ac.createIIRFilter([0.5, 0.5], [1.0]);
+ filter.getFrequencyResponse(frequencies, magResults, phaseResults);
+
+ assert_true(isNaN(magResults[0]), "Invalid input frequency should give NaN magnitude response");
+ assert_true(!isNaN(magResults[1]), "Valid input frequency should not give NaN magnitude response");
+ assert_true(isNaN(magResults[2]), "Invalid input frequency should give NaN magnitude response");
+ assert_true(isNaN(phaseResults[0]), "Invalid input frequency should give NaN phase response");
+ assert_true(!isNaN(phaseResults[1]), "Valid input frequency should not give NaN phase response");
+ assert_true(isNaN(phaseResults[2]), "Invalid input frequency should give NaN phase response");
+
+}, "IIRFilterNode getFrequencyResponse handles invalid frequencies properly");
+</script>