Bug 1458089 [wpt PR 10720] - Move AudioBuffer ctor test to WPT., a=testonly
authorRaymond Toy <rtoy@chromium.org>
Tue, 01 May 2018 17:26:06 +0000
changeset 472725 72e3cc3de7063afc91718930b5f8ef8b3b2bf97b
parent 472724 15aeca73863da992b87c437d71732fa83889915b
child 472726 5e07e3179c7bc640523f3a4e7201721e5c224cde
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1458089, 10720, 745778, 1035917, 554887
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1458089 [wpt PR 10720] - Move AudioBuffer ctor test to WPT., a=testonly Automatic update from web-platform-testsMove AudioBuffer ctor test to WPT. This test fails on Firefox because it signals the incorrect type on some tests. A bug was filed and should be fixed soon. Bug: 745778 Change-Id: Idb0ece151a3f9404b4a10ddb719cfc4982a57959 Reviewed-on: https://chromium-review.googlesource.com/1035917 Reviewed-by: Hongchan Choi <hongchan@chromium.org> Commit-Queue: Raymond Toy <rtoy@chromium.org> Cr-Commit-Position: refs/heads/master@{#554887} -- wpt-commits: e580c7e9126412a44880755aeb17b05e13a02a88 wpt-pr: 10720
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/webaudio/the-audio-api/the-audiobuffer-interface/ctor-audiobuffer.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -369755,16 +369755,22 @@
     ]
    ],
    "webaudio/the-audio-api/the-analysernode-interface/test-analysernode.html": [
     [
      "/webaudio/the-audio-api/the-analysernode-interface/test-analysernode.html",
      {}
     ]
    ],
+   "webaudio/the-audio-api/the-audiobuffer-interface/ctor-audiobuffer.html": [
+    [
+     "/webaudio/the-audio-api/the-audiobuffer-interface/ctor-audiobuffer.html",
+     {}
+    ]
+   ],
    "webaudio/the-audio-api/the-audiobuffer-interface/idl-test.html": [
     [
      "/webaudio/the-audio-api/the-audiobuffer-interface/idl-test.html",
      {}
     ]
    ],
    "webaudio/the-audio-api/the-audiobuffersourcenode-interface/ctor-audiobuffersource.html": [
     [
@@ -610036,16 +610042,20 @@
   "webaudio/the-audio-api/the-analysernode-interface/test-analysernode.html": [
    "8478aa405a4641a9c47554529762e85a37d7593a",
    "testharness"
   ],
   "webaudio/the-audio-api/the-audiobuffer-interface/.gitkeep": [
    "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "support"
   ],
+  "webaudio/the-audio-api/the-audiobuffer-interface/ctor-audiobuffer.html": [
+   "34d9e7ccb333ce23c838126a4e84918321292d33",
+   "testharness"
+  ],
   "webaudio/the-audio-api/the-audiobuffer-interface/idl-test.html": [
    "0ef05c242d8f987d521c0e9ce474d0f9a46bee28",
    "testharness"
   ],
   "webaudio/the-audio-api/the-audiobuffersourcenode-interface/.gitkeep": [
    "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "support"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-audiobuffer-interface/ctor-audiobuffer.html
@@ -0,0 +1,234 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>
+      Test Constructor: AudioBuffer
+    </title>
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+    <script src="/webaudio/resources/audit-util.js"></script>
+    <script src="/webaudio/resources/audit.js"></script>
+    <script src="/webaudio/resources/audionodeoptions.js"></script>
+  </head>
+  <body>
+    <script id="layout-test-code">
+      let context;
+
+      let audit = Audit.createTaskRunner();
+
+      audit.define('initialize', (task, should) => {
+        context = initializeContext(should);
+        task.done();
+      });
+
+      audit.define('invalid constructor', (task, should) => {
+        should(() => {
+          new AudioBuffer();
+        }, 'new AudioBuffer()').throw('TypeError');
+        should(() => {
+          new AudioBuffer(1);
+        }, 'new AudioBuffer(1)').throw('TypeError');
+        should(() => {
+          new AudioBuffer(Date, 42);
+        }, 'new AudioBuffer(Date, 42)').throw('TypeError');
+
+        task.done();
+      });
+
+      audit.define('required options', (task, should) => {
+        let buffer;
+
+        // The length and sampleRate attributes are required; all others are
+        // optional.
+        should(() => {
+          new AudioBuffer({});
+        }, 'buffer = new AudioBuffer({})').throw('TypeError');
+
+        should(() => {
+          new AudioBuffer({length: 1});
+        }, 'buffer = new AudioBuffer({length: 1})').throw('TypeError');
+
+        should(() => {
+          new AudioBuffer({sampleRate: 48000});
+        }, 'buffer = new AudioBuffer({sampleRate: 48000})').throw('TypeError');
+
+        should(() => {
+          buffer = new AudioBuffer({numberOfChannels: 1});
+        }, 'buffer = new AudioBuffer({numberOfChannels: 1}').throw('TypeError');
+
+        // Length and sampleRate are required, but others are optional.
+        should(
+            () => {
+              buffer =
+                  new AudioBuffer({length: 21, sampleRate: context.sampleRate});
+            },
+            'buffer0 = new AudioBuffer({length: 21, sampleRate: ' +
+                context.sampleRate + '}')
+            .notThrow();
+        // Verify the buffer has the correct values.
+        should(buffer.numberOfChannels, 'buffer0.numberOfChannels')
+            .beEqualTo(1);
+        should(buffer.length, 'buffer0.length').beEqualTo(21);
+        should(buffer.sampleRate, 'buffer0.sampleRate')
+            .beEqualTo(context.sampleRate);
+
+        should(
+            () => {
+              buffer = new AudioBuffer(
+                  {numberOfChannels: 3, length: 1, sampleRate: 48000});
+            },
+            'buffer1 = new AudioBuffer(' +
+                '{numberOfChannels: 3, length: 1, sampleRate: 48000})')
+            .notThrow();
+        // Verify the buffer has the correct values.
+        should(buffer.numberOfChannels, 'buffer1.numberOfChannels')
+            .beEqualTo(3);
+        should(buffer.length, 'buffer1.length').beEqualTo(1);
+        should(buffer.sampleRate, 'buffer1.sampleRate').beEqualTo(48000);
+
+        task.done();
+      });
+
+      audit.define('invalid option values', (task, should) => {
+        let options = {numberOfChannels: 0, length: 1, sampleRate: 16000};
+        should(
+            () => {
+              let buffer = new AudioBuffer(options);
+            },
+            'new AudioBuffer(' + JSON.stringify(options) + ')')
+            .throw('NotSupportedError');
+
+        options = {numberOfChannels: 99, length: 0, sampleRate: 16000};
+        should(
+            () => {
+              let buffer = new AudioBuffer(options);
+            },
+            'new AudioBuffer(' + JSON.stringify(options) + ')')
+            .throw('NotSupportedError');
+
+        options = {numberOfChannels: 1, length: 0, sampleRate: 16000};
+        should(
+            () => {
+              let buffer = new AudioBuffer(options);
+            },
+            'new AudioBuffer(' + JSON.stringify(options) + ')')
+            .throw('NotSupportedError');
+
+        options = {numberOfChannels: 1, length: 1, sampleRate: 100};
+        should(
+            () => {
+              let buffer = new AudioBuffer(options);
+            },
+            'new AudioBuffer(' + JSON.stringify(options) + ')')
+            .throw('NotSupportedError');
+
+        task.done();
+      });
+
+      audit.define('default constructor', (task, should) => {
+        let buffer;
+
+        let options = {numberOfChannels: 5, length: 17, sampleRate: 16000};
+        should(
+            () => {
+              buffer = new AudioBuffer(options);
+            },
+            'buffer = new AudioBuffer(' + JSON.stringify(options) + ')')
+            .notThrow();
+
+        should(buffer.numberOfChannels, 'buffer.numberOfChannels')
+            .beEqualTo(options.numberOfChannels);
+        should(buffer.length, 'buffer.length').beEqualTo(options.length);
+        should(buffer.sampleRate, 'buffer.sampleRate').beEqualTo(16000);
+
+        task.done();
+      });
+
+      audit.define('valid constructor', (task, should) => {
+        let buffer;
+
+        let options = {numberOfChannels: 3, length: 42, sampleRate: 54321};
+
+        let message = 'new AudioBuffer(' + JSON.stringify(options) + ')';
+        should(() => {
+          buffer = new AudioBuffer(options);
+        }, message).notThrow();
+
+        should(buffer.numberOfChannels, 'buffer.numberOfChannels')
+            .beEqualTo(options.numberOfChannels);
+
+        should(buffer.length, 'buffer.length').beEqualTo(options.length);
+
+        should(buffer.sampleRate, 'buffer.sampleRate')
+            .beEqualTo(options.sampleRate);
+
+        // Verify that we actually got the right number of channels
+        for (let k = 0; k < options.numberOfChannels; ++k) {
+          let data;
+          let message = 'buffer.getChannelData(' + k + ')';
+          should(() => {
+            data = buffer.getChannelData(k);
+          }, message).notThrow();
+
+          should(data.length, message + ' length').beEqualTo(options.length);
+        }
+
+        should(
+            () => {
+              buffer.getChannelData(options.numberOfChannels);
+            },
+            'buffer.getChannelData(' + options.numberOfChannels + ')')
+            .throw('IndexSizeError');
+
+        task.done();
+      });
+
+      audit.define('multiple contexts', (task, should) => {
+        // Test that an AudioBuffer can be used for different contexts.
+        let buffer =
+            new AudioBuffer({length: 128, sampleRate: context.sampleRate});
+
+        // Don't use getChannelData here because we want to be able to use
+        // |data| to compare the final results of playing out this buffer.  (If
+        // we did, |data| gets detached when the sources play.)
+        let data = new Float32Array(buffer.length);
+        for (let k = 0; k < data.length; ++k)
+          data[k] = 1 + k;
+        buffer.copyToChannel(data, 0);
+
+        let c1 = new OfflineAudioContext(1, 128, context.sampleRate);
+        let c2 = new OfflineAudioContext(1, 128, context.sampleRate);
+
+        let s1 = new AudioBufferSourceNode(c1, {buffer: buffer});
+        let s2 = new AudioBufferSourceNode(c2, {buffer: buffer});
+
+        s1.connect(c1.destination);
+        s2.connect(c2.destination);
+
+        s1.start();
+        s2.start();
+
+        Promise
+            .all([
+              c1.startRendering().then(function(resultBuffer) {
+                return should(resultBuffer.getChannelData(0), 'c1 result')
+                    .beEqualToArray(data);
+              }),
+              c2.startRendering().then(function(resultBuffer) {
+                return should(resultBuffer.getChannelData(0), 'c2 result')
+                    .beEqualToArray(data);
+              }),
+            ])
+            .then(returnValues => {
+              should(
+                  returnValues[0] && returnValues[1],
+                  'AudioBuffer shared between two different contexts')
+                  .message('correctly', 'incorrectly');
+              task.done();
+            });
+      });
+
+      audit.run();
+    </script>
+  </body>
+</html>