Bug 1265408 - Add webplatform-test for IIRFilterNode; r=padenot
authorDan Minor <dminor@mozilla.com>
Tue, 24 May 2016 13:04:55 -0400
changeset 300929 e8ac527f4d47372fe793bd1495c1f584bbb644cc
parent 300928 78eb3b1b93ce2f5b455a1467d630003a077fe78a
child 300930 555f1884bd94d1acd8a596195034bb65170e9170
push id19599
push usercbook@mozilla.com
push dateWed, 08 Jun 2016 10:16:21 +0000
treeherderfx-team@81f4cc3f6f4c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1265408
milestone50.0a1
Bug 1265408 - Add webplatform-test for IIRFilterNode; r=padenot MozReview-Commit-ID: qSDxvk60j2
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/webaudio/the-audio-api/the-iirfilternode-interface/test-iirfilternode.html
--- 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>