diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/webcodecs/audio-decoder.crossOriginIsolated.https.any.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webcodecs/audio-decoder.crossOriginIsolated.https.any.js')
-rw-r--r-- | testing/web-platform/tests/webcodecs/audio-decoder.crossOriginIsolated.https.any.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webcodecs/audio-decoder.crossOriginIsolated.https.any.js b/testing/web-platform/tests/webcodecs/audio-decoder.crossOriginIsolated.https.any.js new file mode 100644 index 0000000000..17009e0118 --- /dev/null +++ b/testing/web-platform/tests/webcodecs/audio-decoder.crossOriginIsolated.https.any.js @@ -0,0 +1,71 @@ +// META: global=window,dedicatedworker +// META: script=/webcodecs/utils.js + +const testData = { + src: 'sfx-aac.mp4', + config: { + codec: 'mp4a.40.2', + sampleRate: 48000, + numberOfChannels: 1, + description: {offset: 2552, size: 5}, + } +}; + +// Create a view of an ArrayBuffer. +function view(buffer, {offset, size}) { + return new Uint8Array(buffer, offset, size); +} + +function testSharedArrayBufferDescription(t, useView) { + const data = testData; + + // Don't run test if the codec is not supported. + assert_equals("function", typeof AudioDecoder.isConfigSupported); + let supported = false; + return AudioDecoder + .isConfigSupported({ + codec: data.config.codec, + sampleRate: data.config.sampleRate, + numberOfChannels: data.config.numberOfChannels + }) + .catch(_ => { + assert_implements_optional(false, data.config.codec + ' unsupported'); + }) + .then(support => { + supported = support.supported; + assert_implements_optional( + supported, data.config.codec + ' unsupported'); + return fetch(data.src); + }) + .then(response => { + return response.arrayBuffer(); + }) + .then(buf => { + config = {...data.config}; + if (data.config.description) { + let desc = new SharedArrayBuffer(data.config.description.size); + let descView = new Uint8Array(desc); + descView.set(view(buf, data.config.description)); + config.description = useView ? descView : desc; + } + + // Support was verified above, so the description shouldn't change + // that. + return AudioDecoder.isConfigSupported(config); + }) + .then(support => { + assert_true(support.supported); + + const decoder = new AudioDecoder(getDefaultCodecInit(t)); + decoder.configure(config); + assert_equals(decoder.state, 'configured', 'state'); + }); +} + +promise_test(t => { + return testSharedArrayBufferDescription(t, /*useView=*/ false); +}, 'Test isConfigSupported() and configure() using a SharedArrayBuffer'); + +promise_test(t => { + return testSharedArrayBufferDescription(t, /*useView=*/ true); +}, 'Test isConfigSupported() and configure() using a Uint8Array(SharedArrayBuffer)'); |