Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Unified Diff: third_party/WebKit/LayoutTests/webaudio/decodeAudioData/decode-audio-data-neuter.html

Issue 2746913003: Detach buffer in decodeAudioData (Closed)
Patch Set: Address review comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/webaudio/decodeAudioData/decode-audio-data-neuter.html
diff --git a/third_party/WebKit/LayoutTests/webaudio/decodeAudioData/decode-audio-data-neuter.html b/third_party/WebKit/LayoutTests/webaudio/decodeAudioData/decode-audio-data-neuter.html
new file mode 100644
index 0000000000000000000000000000000000000000..8c5dd34e5d7fc0fbccc01aa8a880de18fc960205
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/webaudio/decodeAudioData/decode-audio-data-neuter.html
@@ -0,0 +1,87 @@
+<!doctype html>
+<html>
+ <head>
+ <script src="../../resources/testharness.js"></script>
+ <script src="../../resources/testharnessreport.js"></script>
+ <script src="../resources/audit.js"></script>
+ <title>Test Neutering by decodeAudioData </title>
+ </head>
+
+ <body>
+ <script>
+ // Any valid rate will do. Just need something to create an offline
+ // context.
+ let sampleRate = 44100;
+
+ let audit = Audit.createTaskRunner();
+
+ // Context to use for decodeAudioData
+ let context;
+ // The encoded audio file that we want to decode.
+ let encodedAudio;
+
+ audit.define('initialize', (task, should) => {
+ // Create the context and load up any valid encoded audio file.
+ should(() => {
+ context = new OfflineAudioContext(1, 1, sampleRate);
+ }, 'Context creation').notThrow();
+
+ should(
+ Promise
+ .all([Audit.loadFileFromUrl(
+ '../resources/hyper-reality/laughter.wav')])
+ .then((arrayBuffers) => {
+ encodedAudio = arrayBuffers[0];
+ }),
+ 'Loading of audio file')
+ .beResolved()
+ .then(() => task.done());
+ });
+
+ audit.define('decode-audio-neuters', (task, should) => {
+ // Decode the audio file and verify that it neuters the array, so that
+ // it can't be transfered somewhere else.
+ p = context.decodeAudioData(encodedAudio);
+ should(() => {
+ postMessage('', '*', [encodedAudio]);
+ }, 'Transfer of audio buffer').throw('DataCloneError');
+ should(p, 'Decoding of audio').beResolved().then(() => task.done());
+ });
+
+ audit.define('neutered buffer', (task, should) => {
+ // Any non-empy ArrayBuffer will work. We're going to transfer that
+ // array before calling decodeAudioData.
+ let buffer = new ArrayBuffer(1000);
+
+ should(() => {
+ postMessage('', '*', [buffer]);
+ }, 'Transfer buffer').notThrow();
+
+ should(
+ context.decodeAudioData(buffer),
+ 'decodeAudioData on neutered buffer')
+ .beRejected()
+ .then(() => task.done());
+ });
+
+ audit.define('shared-array-buffer', (task, should) => {
+ // Only run the test if SharedArrayBuffer is available
+ if (window.SharedArrayBuffer) {
+ let b = new SharedArrayBuffer(1000);
+ should(
+ context.decodeAudioData(b),
+ 'decodeAudioData on SharedArrayBuffer')
+ .beRejected('TypeError')
+ .then(() => task.done());
+ } else {
+ should(false, 'SharedArrayBuffer')
+ .message(
+ '', 'not tested because SharedArrayBuffer not available');
+ task.done();
+ }
+ });
+
+ audit.run();
+ </script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698