Bug 1424271 - convert mochitest test_audioParamChaining.html to a web-platform-test r?padenot draft
authorp1509425
Fri, 05 Jan 2018 17:03:51 +0100
changeset 717085 bfa6fbe910960686130ec4f1fbb0d21a570f21f4
parent 717084 1f8bf942111cf28a8ce260e86d64127ed9b0432b
child 745147 5e30b4136fe540cc7d12aa1c9316917096547e70
push id94557
push userbmo:alan.guyoch@gmail.com
push dateMon, 08 Jan 2018 07:50:18 +0000
reviewerspadenot
bugs1424271
milestone59.0a1
Bug 1424271 - convert mochitest test_audioParamChaining.html to a web-platform-test r?padenot MozReview-Commit-ID: 9E0hmjdofjZ
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/webaudio/the-audio-api/the-audiocontext-interface/test_audioParamChaining.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -348594,16 +348594,22 @@
     ]
    ],
    "webaudio/the-audio-api/the-audiocontext-interface/test_audioDestinationNode.html": [
     [
      "/webaudio/the-audio-api/the-audiocontext-interface/test_audioDestinationNode.html",
      {}
     ]
    ],
+   "webaudio/the-audio-api/the-audiocontext-interface/test_audioParamChaining.html": [
+    [
+     "/webaudio/the-audio-api/the-audiocontext-interface/test_audioParamChaining.html",
+     {}
+    ]
+   ],
    "webaudio/the-audio-api/the-audiodestinationnode-interface/idl-test.html": [
     [
      "/webaudio/the-audio-api/the-audiodestinationnode-interface/idl-test.html",
      {}
     ]
    ],
    "webaudio/the-audio-api/the-audionode-interface/audionode-connect-return-value.html": [
     [
@@ -576527,16 +576533,20 @@
   "webaudio/the-audio-api/the-audiocontext-interface/test_AudioListener.html": [
    "940029c8ed0a0dcf87d618a64cdb3358deb5a7bf",
    "testharness"
   ],
   "webaudio/the-audio-api/the-audiocontext-interface/test_audioDestinationNode.html": [
    "10a4852ec668833e7047610aa0085861a9f96f56",
    "testharness"
   ],
+  "webaudio/the-audio-api/the-audiocontext-interface/test_audioParamChaining.html": [
+   "8bac09e81d915712b8c3d3e131809b0583557849",
+   "testharness"
+  ],
   "webaudio/the-audio-api/the-audiodestinationnode-interface/.gitkeep": [
    "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "support"
   ],
   "webaudio/the-audio-api/the-audiodestinationnode-interface/idl-test.html": [
    "3e8b55e707434899be9af13334d935368579f1dc",
    "testharness"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-audiocontext-interface/test_audioParamChaining.html
@@ -0,0 +1,100 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="utf-8">
+  <script src="/resources/testharness.js"></script>
+  <script src="/resources/testharnessreport.js"></script>
+  <script>
+var t = async_test();
+
+function frameToTime(frame, rate) {
+  return frame / rate;
+}
+
+const RATE = 44100;
+
+var oc = new OfflineAudioContext(1, 44100, RATE);
+// This allows us to have a source that is simply a DC offset.
+var source = oc.createBufferSource();
+var buf = oc.createBuffer(1, 1, RATE);
+buf.getChannelData(0)[0] = 1;
+source.loop = true;
+source.buffer = buf;
+
+source.start(0);
+
+var gain = oc.createGain();
+
+source.connect(gain).connect(oc.destination);
+
+var gain2 = oc.createGain();
+var rv2 = gain2.gain.linearRampToValueAtTime(0.1, 0.5);
+assert_true(
+  rv2 instanceof AudioParam,
+  "linearRampToValueAtTime returns an AudioParam."
+);
+assert_true(
+  rv2 == gain2.gain,
+  "linearRampToValueAtTime returns the right AudioParam."
+);
+
+rv2 = gain2.gain.exponentialRampToValueAtTime(0.01, 1.0);
+assert_true(
+  rv2 instanceof AudioParam,
+  "exponentialRampToValueAtTime returns an AudioParam."
+);
+assert_true(
+  rv2 == gain2.gain,
+  "exponentialRampToValueAtTime returns the right AudioParam."
+);
+
+rv2 = gain2.gain.setTargetAtTime(1.0, 2.0, 0.1);
+assert_true(
+  rv2 instanceof AudioParam,
+  "setTargetAtTime returns an AudioParam."
+);
+assert_true(rv2 == gain2.gain, "setTargetAtTime returns the right AudioParam.");
+
+var array = new Float32Array(10);
+rv2 = gain2.gain.setValueCurveAtTime(array, 10, 11);
+assert_true(
+  rv2 instanceof AudioParam,
+  "setValueCurveAtTime returns an AudioParam."
+);
+assert_true(
+  rv2 == gain2.gain,
+  "setValueCurveAtTime returns the right AudioParam."
+);
+
+// We chain three automation methods, making a gain step.
+var rv = gain.gain
+  .setValueAtTime(0, frameToTime(0, RATE))
+  .setValueAtTime(0.5, frameToTime(22000, RATE))
+  .setValueAtTime(1, frameToTime(44000, RATE));
+
+assert_true(rv instanceof AudioParam, "setValueAtTime returns an AudioParam.");
+assert_true(rv == gain.gain, "setValueAtTime returns the right AudioParam.");
+
+oc.startRendering().then(function(rendered) {
+  console.log(rendered.getChannelData(0));
+  assert_equals(
+    rendered.getChannelData(0)[0],
+    0,
+    "The value of the first step is correct."
+  );
+  assert_equals(
+    rendered.getChannelData(0)[22050],
+    0.5,
+    "The value of the second step is correct"
+  );
+  assert_equals(
+    rendered.getChannelData(0)[44099],
+    1,
+    "The value of the third step is correct."
+  );
+  t.done();
+});
+  </script>
+</head>
+</body>
+</html>