From 0a7317c45f0dd8c66e3172a0c90761b07e8d5441 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 9 Jul 2019 13:31:59 +0200 Subject: [PATCH] Web Audio: SharedArrayBuffer and COOP/COEP Stop making SharedArrayBuffer usage conditional as it should always be enabled. postMessage() can fail however and only works if the appropriate headers are set, so add those to the worklet test. (I'm assuming here that worklets will inherit COEP without having to declare it.) --- .../audiobuffer-copy-channel.html | 60 ++++++------ ...t-postmessage-sharedarraybuffer.https.html | 95 +++++++++---------- ...ssage-sharedarraybuffer.https.html.headers | 2 + 3 files changed, 73 insertions(+), 84 deletions(-) create mode 100644 webaudio/the-audio-api/the-audioworklet-interface/audioworklet-postmessage-sharedarraybuffer.https.html.headers diff --git a/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-copy-channel.html b/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-copy-channel.html index a1a5f3fce54e11..52447c06c9f189 100644 --- a/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-copy-channel.html +++ b/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-copy-channel.html @@ -149,22 +149,20 @@ buffer.copyFromChannel(x, 3); }, '7: buffer.copyFromChannel(x, 3)').throw(DOMException, 'IndexSizeError'); - if (window.SharedArrayBuffer) { - let shared_buffer = new Float32Array(new SharedArrayBuffer(32)); - should( - () => { - buffer.copyFromChannel(shared_buffer, 0); - }, - '8: buffer.copyFromChannel(SharedArrayBuffer view, 0)') - .throw(TypeError); - - should( - () => { - buffer.copyFromChannel(shared_buffer, 0, 0); - }, - '9: buffer.copyFromChannel(SharedArrayBuffer view, 0, 0)') - .throw(TypeError); - } + let shared_buffer = new Float32Array(new SharedArrayBuffer(32)); + should( + () => { + buffer.copyFromChannel(shared_buffer, 0); + }, + '8: buffer.copyFromChannel(SharedArrayBuffer view, 0)') + .throw(TypeError); + + should( + () => { + buffer.copyFromChannel(shared_buffer, 0, 0); + }, + '9: buffer.copyFromChannel(SharedArrayBuffer view, 0, 0)') + .throw(TypeError); task.done(); }); @@ -204,22 +202,20 @@ buffer.copyToChannel(x, 3); }, '6: buffer.copyToChannel(x, 3)').throw(DOMException, 'IndexSizeError'); - if (window.SharedArrayBuffer) { - let shared_buffer = new Float32Array(new SharedArrayBuffer(32)); - should( - () => { - buffer.copyToChannel(shared_buffer, 0); - }, - '7: buffer.copyToChannel(SharedArrayBuffer view, 0)') - .throw(TypeError); - - should( - () => { - buffer.copyToChannel(shared_buffer, 0, 0); - }, - '8: buffer.copyToChannel(SharedArrayBuffer view, 0, 0)') - .throw(TypeError); - } + let shared_buffer = new Float32Array(new SharedArrayBuffer(32)); + should( + () => { + buffer.copyToChannel(shared_buffer, 0); + }, + '7: buffer.copyToChannel(SharedArrayBuffer view, 0)') + .throw(TypeError); + + should( + () => { + buffer.copyToChannel(shared_buffer, 0, 0); + }, + '8: buffer.copyToChannel(SharedArrayBuffer view, 0, 0)') + .throw(TypeError); task.done(); }); diff --git a/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-postmessage-sharedarraybuffer.https.html b/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-postmessage-sharedarraybuffer.https.html index 8194d1977ad452..a5dd004981157c 100644 --- a/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-postmessage-sharedarraybuffer.https.html +++ b/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-postmessage-sharedarraybuffer.https.html @@ -16,65 +16,56 @@ 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'); + 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. + // 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(); + 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; + // 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; + 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; - } - }; + 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(); + workletNode.port.onmessageerror = (event) => { + should(false, 'Got messageerror from worklet').beTrue(); + task.done(); + }; }); - } context.audioWorklet.addModule(filePath).then(() => { audit.run(); diff --git a/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-postmessage-sharedarraybuffer.https.html.headers b/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-postmessage-sharedarraybuffer.https.html.headers new file mode 100644 index 00000000000000..63b60e490f47f4 --- /dev/null +++ b/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-postmessage-sharedarraybuffer.https.html.headers @@ -0,0 +1,2 @@ +Cross-Origin-Opener-Policy: same-origin +Cross-Origin-Embedder-Policy: require-corp