diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/webaudio/the-audio-api/the-offlineaudiocontext-interface | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webaudio/the-audio-api/the-offlineaudiocontext-interface')
4 files changed, 278 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-offlineaudiocontext-interface/ctor-offlineaudiocontext.html b/testing/web-platform/tests/webaudio/the-audio-api/the-offlineaudiocontext-interface/ctor-offlineaudiocontext.html new file mode 100644 index 0000000000..4b68631036 --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-offlineaudiocontext-interface/ctor-offlineaudiocontext.html @@ -0,0 +1,203 @@ +<!doctype html> +<html> + <head> + <title>Test Constructor: OfflineAudioContext</title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/webaudio/resources/audit.js"></script> + <script src="/webaudio/resources/audit-util.js"></script> + <script src="/webaudio/resources/audionodeoptions.js"></script> + </head> + + <body> + <script> + let audit = Audit.createTaskRunner(); + + // Just a simple test of the 3-arg constructor; This should be + // well-covered by other layout tests that use the 3-arg constructor. + audit.define( + {label: 'basic', description: 'Old-style constructor'}, + (task, should) => { + let context; + + // First and only arg should be a dictionary. + should(() => { + new OfflineAudioContext(3); + }, 'new OfflineAudioContext(3)').throw(TypeError); + + // Constructor needs 1 or 3 args, so 2 should throw. + should(() => { + new OfflineAudioContext(3, 42); + }, 'new OfflineAudioContext(3, 42)').throw(TypeError); + + // Valid constructor + should(() => { + context = new OfflineAudioContext(3, 42, 12345); + }, 'context = new OfflineAudioContext(3, 42, 12345)').notThrow(); + + // Verify that the context was constructed correctly. + should(context.length, 'context.length').beEqualTo(42); + should(context.sampleRate, 'context.sampleRate').beEqualTo(12345); + should( + context.destination.channelCount, + 'context.destination.channelCount') + .beEqualTo(3); + should( + context.destination.channelCountMode, + 'context.destination.channelCountMode') + .beEqualTo('explicit'); + should( + context.destination.channelInterpretation, + 'context.destination.channelInterpretation') + .beEqualTo('speakers'); + task.done(); + }); + + // Test constructor throws an error if the required members of the + // dictionary are not given. + audit.define( + {label: 'options-1', description: 'Required options'}, + (task, should) => { + let context2; + + // No args should throw + should(() => { + new OfflineAudioContext(); + }, 'new OfflineAudioContext()').throw(TypeError); + + // Empty OfflineAudioContextOptions should throw + should(() => { + new OfflineAudioContext({}); + }, 'new OfflineAudioContext({})').throw(TypeError); + + let options = {length: 42}; + // sampleRate is required. + should( + () => { + new OfflineAudioContext(options); + }, + 'new OfflineAudioContext(' + JSON.stringify(options) + ')') + .throw(TypeError); + + options = {sampleRate: 12345}; + // length is required. + should( + () => { + new OfflineAudioContext(options); + }, + 'new OfflineAudioContext(' + JSON.stringify(options) + ')') + .throw(TypeError); + + // Valid constructor. Verify that the resulting context has the + // correct values. + options = {length: 42, sampleRate: 12345}; + should( + () => { + context2 = new OfflineAudioContext(options); + }, + 'c2 = new OfflineAudioContext(' + JSON.stringify(options) + ')') + .notThrow(); + should( + context2.destination.channelCount, + 'c2.destination.channelCount') + .beEqualTo(1); + should(context2.length, 'c2.length').beEqualTo(options.length); + should(context2.sampleRate, 'c2.sampleRate') + .beEqualTo(options.sampleRate); + should( + context2.destination.channelCountMode, + 'c2.destination.channelCountMode') + .beEqualTo('explicit'); + should( + context2.destination.channelInterpretation, + 'c2.destination.channelInterpretation') + .beEqualTo('speakers'); + + task.done(); + }); + + // Constructor should throw errors for invalid values specified by + // OfflineAudioContextOptions. + audit.define( + {label: 'options-2', description: 'Invalid options'}, + (task, should) => { + let options = {length: 42, sampleRate: 8000, numberOfChannels: 33}; + + // channelCount too large. + should( + () => { + new OfflineAudioContext(options); + }, + 'new OfflineAudioContext(' + JSON.stringify(options) + ')') + .throw(DOMException, 'NotSupportedError'); + + // length cannot be 0 + options = {length: 0, sampleRate: 8000}; + should( + () => { + new OfflineAudioContext(options); + }, + 'new OfflineAudioContext(' + JSON.stringify(options) + ')') + .throw(DOMException, 'NotSupportedError'); + + // sampleRate outside valid range + options = {length: 1, sampleRate: 1}; + should( + () => { + new OfflineAudioContext(options); + }, + 'new OfflineAudioContext(' + JSON.stringify(options) + ')') + .throw(DOMException, 'NotSupportedError'); + + task.done(); + }); + + audit.define( + {label: 'options-3', description: 'Valid options'}, + (task, should) => { + let context; + let options = { + length: 1, + sampleRate: 8000, + }; + + // Verify context with valid constructor has the correct values. + should( + () => { + context = new OfflineAudioContext(options); + }, + 'c = new OfflineAudioContext' + JSON.stringify(options) + ')') + .notThrow(); + should(context.length, 'c.length').beEqualTo(options.length); + should(context.sampleRate, 'c.sampleRate') + .beEqualTo(options.sampleRate); + should( + context.destination.channelCount, 'c.destination.channelCount') + .beEqualTo(1); + should( + context.destination.channelCountMode, + 'c.destination.channelCountMode') + .beEqualTo('explicit'); + should( + context.destination.channelInterpretation, + 'c.destination.channelCountMode') + .beEqualTo('speakers'); + + options.numberOfChannels = 7; + should( + () => { + context = new OfflineAudioContext(options); + }, + 'c = new OfflineAudioContext' + JSON.stringify(options) + ')') + .notThrow(); + should( + context.destination.channelCount, 'c.destination.channelCount') + .beEqualTo(options.numberOfChannels); + + task.done(); + }); + + audit.run(); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-offlineaudiocontext-interface/current-time-block-size.html b/testing/web-platform/tests/webaudio/the-audio-api/the-offlineaudiocontext-interface/current-time-block-size.html new file mode 100644 index 0000000000..ee976f7f72 --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-offlineaudiocontext-interface/current-time-block-size.html @@ -0,0 +1,17 @@ +<!DOCTYPE html> +<title>Test currentTime at completion of OfflineAudioContext rendering</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +promise_test(function() { + // sampleRate is a power of two so that time can be represented exactly + // in double currentTime. + var context = new OfflineAudioContext(1, 1, 65536); + return context.startRendering(). + then(function(buffer) { + assert_equals(buffer.length, 1, "buffer length"); + assert_equals(context.currentTime, 128 / context.sampleRate, + "currentTime at completion"); + }); +}); +</script> diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-offlineaudiocontext-interface/offlineaudiocontext-detached-execution-context.html b/testing/web-platform/tests/webaudio/the-audio-api/the-offlineaudiocontext-interface/offlineaudiocontext-detached-execution-context.html new file mode 100644 index 0000000000..6eafd15fd2 --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-offlineaudiocontext-interface/offlineaudiocontext-detached-execution-context.html @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<html> + <head> + <title> + Testing behavior OfflineAudioContext after execution context is detached + </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"> + const audit = Audit.createTaskRunner(); + + audit.define('decoding-on-detached-iframe', (task, should) => { + const iframe = + document.createElementNS("http://www.w3.org/1999/xhtml", "iframe"); + document.body.appendChild(iframe); + + // Use the lowest value possible for the faster test. + let context = + new iframe.contentWindow.OfflineAudioContext(1, 1, 8000); + + document.body.removeChild(iframe); + + return should(context.decodeAudioData(new ArrayBuffer(1)), + 'decodeAudioData() upon a detached iframe') + .beRejectedWith('InvalidStateError'); + }); + + audit.run(); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-offlineaudiocontext-interface/startrendering-after-discard.html b/testing/web-platform/tests/webaudio/the-audio-api/the-offlineaudiocontext-interface/startrendering-after-discard.html new file mode 100644 index 0000000000..dd610ec335 --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-offlineaudiocontext-interface/startrendering-after-discard.html @@ -0,0 +1,24 @@ +<!doctype html> +<title>Test for rejected promise from startRendering() on an + OfflineAudioContext in a discarded browsing context</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<body></body> +<script> +let context; +let childDOMException; +setup(() => { + const frame = document.createElement('iframe'); + document.body.appendChild(frame); + context = new frame.contentWindow.OfflineAudioContext( + {length: 1, sampleRate: 48000}); + childDOMException = frame.contentWindow.DOMException; + frame.remove(); +}); + +promise_test((t) => promise_rejects_dom( + t, 'InvalidStateError', childDOMException, context.startRendering()), + 'startRendering()'); +// decodeAudioData() is tested in +// offlineaudiocontext-detached-execution-context.html +</script> |