Bug 1497757 [wpt PR 13445] - Allow posting a SharedArrayBuffer to AudioWorklet, a=testonly
authorBen Smith <binji@chromium.org>
Sat, 13 Oct 2018 19:30:56 +0000
changeset 496875 a9f42748483700ec4e6d4f79bcc8ffef9f0b4824
parent 496874 3bd3e8980c2f6ce2c0ece44b1fdea4edfdd7d6b6
child 496876 fd3050c5dd4fbd589a8a3b1bf7ca8811ef494946
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1497757, 13445, 892067, 1262932, 598619
milestone64.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 1497757 [wpt PR 13445] - Allow posting a SharedArrayBuffer to AudioWorklet, a=testonly Automatic update from web-platform-testsAllow posting a SharedArrayBuffer to AudioWorklet The HTML spec only allows passing SharedArrayBuffers to an agent in the same agent cluster. Worklets currently do not belong to any agent cluster, so a SharedArrayBuffer can not be shared with a worklet. However, it is intended that this is possible; see, for example, https://github.com/w3c/css-houdini-drafts/issues/380 and the AudioWorklet article here: https://developers.google.com/web/updates/2018/06/audio-worklet-design-pattern#webaudio_powerhouse_audio_worklet_and_sharedarraybuffer This change funnels the agent cluster ID through when creating a ThreadedWorklet, so a SharedArrayBuffer can be shared as long as the creator of the Worklet's thread is in the same agent cluster. It is not clear that this is the behavior that will be specified, however. Bug: chromium:892067 Change-Id: If1a2187ae38da41f2389538c07e7b04921c6128f Reviewed-on: https://chromium-review.googlesource.com/c/1262932 Commit-Queue: Ben Smith <binji@chromium.org> Reviewed-by: Hongchan Choi <hongchan@chromium.org> Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org> Cr-Commit-Position: refs/heads/master@{#598619} -- wpt-commits: 2c89bbecfab9a69190906abd7610c3bc62303dd4 wpt-pr: 13445
testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-postmessage-sharedarraybuffer.https.html
testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/sharedarraybuffer-processor.js
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-postmessage-sharedarraybuffer.https.html
@@ -0,0 +1,85 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>
+      Test passing SharedArrayBuffer to an AudioWorklet
+    </title>
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+    <script src="/webaudio/resources/audit.js"></script>
+  </head>
+  <body>
+    <script id="layout-test-code">
+      let audit = Audit.createTaskRunner();
+
+      let context = new AudioContext();
+
+      let filePath = 'processors/sharedarraybuffer-processor.js';
+
+      if (window.SharedArrayBuffer) {
+        audit.define(
+            'Test postMessage from AudioWorkletProcessor to AudioWorkletNode',
+            (task, should) => {
+              let workletNode =
+                  new AudioWorkletNode(context, 'sharedarraybuffer-processor');
+
+              // After it is created, the worklet will send a new
+              // SharedArrayBuffer to the main thread.
+              //
+              // The worklet will then wait to receive a message from the main
+              // thread.
+              //
+              // When it receives the message, it will check whether it is a
+              // SharedArrayBuffer, and send this information back to the main
+              // thread.
+
+              workletNode.port.onmessage = (event) => {
+                let data = event.data;
+                switch (data.state) {
+                  case 'created':
+                    should(
+                        data.sab instanceof SharedArrayBuffer,
+                        'event.data.sab from worklet is an instance of SharedArrayBuffer')
+                        .beTrue();
+
+                    // Send a SharedArrayBuffer back to the worklet.
+                    let sab = new SharedArrayBuffer(8);
+                    workletNode.port.postMessage(sab);
+                    break;
+
+                  case 'received message':
+                    should(data.isSab, 'event.data from main thread is an instance of SharedArrayBuffer')
+                        .beTrue();
+                    task.done();
+                    break;
+
+                  default:
+                    should(false,
+                           `Got unexpected message from worklet: ${data.state}`)
+                        .beTrue();
+                    task.done();
+                    break;
+                }
+              };
+
+              workletNode.port.onmessageerror = (event) => {
+                should(false, 'Got messageerror from worklet').beTrue();
+                task.done();
+              };
+            });
+      } else {
+        // NOTE(binji): SharedArrayBuffer is only enabled where we have site
+        // isolation.
+        audit.define('Skipping test because SharedArrayBuffer is not defined',
+          (task, should) => {
+            task.done();
+          });
+      }
+
+      context.audioWorklet.addModule(filePath).then(() => {
+        audit.run();
+      });
+    </script>
+  </body>
+</html>
+
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/sharedarraybuffer-processor.js
@@ -0,0 +1,35 @@
+/**
+ * @class SharedArrayBufferProcessor
+ * @extends AudioWorkletProcessor
+ *
+ * This processor class demonstrates passing SharedArrayBuffers to and from
+ * workers.
+ */
+class SharedArrayBufferProcessor extends AudioWorkletProcessor {
+  constructor() {
+    super();
+    this.port.onmessage = this.handleMessage.bind(this);
+    this.port.onmessageerror = this.handleMessageError.bind(this);
+    let sab = new SharedArrayBuffer(8);
+    this.port.postMessage({state: 'created', sab});
+  }
+
+  handleMessage(event) {
+    this.port.postMessage({
+      state: 'received message',
+      isSab: event.data instanceof SharedArrayBuffer
+    });
+  }
+
+  handleMessageError(event) {
+    this.port.postMessage({
+      state: 'received messageerror'
+    });
+  }
+
+  process() {
+    return true;
+  }
+}
+
+registerProcessor('sharedarraybuffer-processor', SharedArrayBufferProcessor);