summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-dynamicscompressornode-interface
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/webaudio/the-audio-api/the-dynamicscompressornode-interface
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webaudio/the-audio-api/the-dynamicscompressornode-interface')
-rw-r--r--testing/web-platform/tests/webaudio/the-audio-api/the-dynamicscompressornode-interface/ctor-dynamicscompressor.html199
-rw-r--r--testing/web-platform/tests/webaudio/the-audio-api/the-dynamicscompressornode-interface/dynamicscompressor-basic.html48
2 files changed, 247 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-dynamicscompressornode-interface/ctor-dynamicscompressor.html b/testing/web-platform/tests/webaudio/the-audio-api/the-dynamicscompressornode-interface/ctor-dynamicscompressor.html
new file mode 100644
index 0000000000..c2460dfa1d
--- /dev/null
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-dynamicscompressornode-interface/ctor-dynamicscompressor.html
@@ -0,0 +1,199 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>
+ Test Constructor: DynamicsCompressor
+ </title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/webaudio/resources/audit-util.js"></script>
+ <script src="/webaudio/resources/audit.js"></script>
+ <script src="/webaudio/resources/audionodeoptions.js"></script>
+ </head>
+ <body>
+ <script id="layout-test-code">
+ let context;
+
+ let audit = Audit.createTaskRunner();
+
+ audit.define('initialize', (task, should) => {
+ context = initializeContext(should);
+ task.done();
+ });
+
+ audit.define('invalid constructor', (task, should) => {
+ testInvalidConstructor(should, 'DynamicsCompressorNode', context);
+ task.done();
+ });
+
+ audit.define('default constructor', (task, should) => {
+ let prefix = 'node0';
+ let node =
+ testDefaultConstructor(should, 'DynamicsCompressorNode', context, {
+ prefix: prefix,
+ numberOfInputs: 1,
+ numberOfOutputs: 1,
+ channelCount: 2,
+ channelCountMode: 'clamped-max',
+ channelInterpretation: 'speakers'
+ });
+
+ testDefaultAttributes(should, node, prefix, [
+ {name: 'threshold', value: -24}, {name: 'knee', value: 30},
+ {name: 'ratio', value: 12}, {name: 'reduction', value: 0},
+ {name: 'attack', value: Math.fround(0.003)},
+ {name: 'release', value: 0.25}
+ ]);
+
+ task.done();
+ });
+
+ audit.define('test AudioNodeOptions', (task, should) => {
+ // Can't use testAudioNodeOptions because the constraints for this node
+ // are not supported there.
+
+ // Array of test options to be run. Each entry is a dictionary where
+ // |testAttribute| is the name of the attribute to be tested,
+ // |testValue| is the value to be used, and |expectedErrorType| is the
+ // error type if the test is expected to throw an error.
+ // |expectedErrorType| should be set only if the test does throw.
+ let testOptions = [
+ // Test channel count
+ {
+ testAttribute: 'channelCount',
+ testValue: 1,
+ },
+ {
+ testAttribute: 'channelCount',
+ testValue: 2,
+ },
+ {
+ testAttribute: 'channelCount',
+ testValue: 0,
+ expectedErrorType: 'NotSupportedError'
+ },
+ {
+ testAttribute: 'channelCount',
+ testValue: 3,
+ expectedErrorType: 'NotSupportedError'
+ },
+ {
+ testAttribute: 'channelCount',
+ testValue: 99,
+ expectedErrorType: 'NotSupportedError'
+ },
+ // Test channel count mode
+ {
+ testAttribute: 'channelCountMode',
+ testValue: 'clamped-max',
+ },
+ {
+ testAttribute: 'channelCountMode',
+ testValue: 'explicit',
+ },
+ {
+ testAttribute: 'channelCountMode',
+ testValue: 'max',
+ expectedErrorType: 'NotSupportedError'
+ },
+ {
+ testAttribute: 'channelCountMode',
+ testValue: 'foobar',
+ expectedErrorType: TypeError
+ },
+ // Test channel interpretation
+ {
+ testAttribute: 'channelInterpretation',
+ testValue: 'speakers',
+ },
+ {
+ testAttribute: 'channelInterpretation',
+ testValue: 'discrete',
+ },
+ {
+ testAttribute: 'channelInterpretation',
+ testValue: 'foobar',
+ expectedErrorType: TypeError
+ }
+ ];
+
+ testOptions.forEach((option) => {
+ let nodeOptions = {};
+ nodeOptions[option.testAttribute] = option.testValue;
+
+ testNode(should, context, {
+ nodeOptions: nodeOptions,
+ testAttribute: option.testAttribute,
+ expectedValue: option.testValue,
+ expectedErrorType: option.expectedErrorType
+ });
+ });
+
+ task.done();
+ });
+
+ audit.define('constructor with options', (task, should) => {
+ let node;
+ let options =
+ {threshold: -33, knee: 15, ratio: 7, attack: 0.625, release: 0.125};
+
+ should(
+ () => {
+ node = new DynamicsCompressorNode(context, options);
+ },
+ 'node1 = new DynamicsCompressorNode(c, ' + JSON.stringify(options) +
+ ')')
+ .notThrow();
+ should(
+ node instanceof DynamicsCompressorNode,
+ 'node1 instanceof DynamicsCompressorNode')
+ .beEqualTo(true);
+
+ should(node.threshold.value, 'node1.threshold.value')
+ .beEqualTo(options.threshold);
+ should(node.knee.value, 'node1.knee.value').beEqualTo(options.knee);
+ should(node.ratio.value, 'node1.ratio.value').beEqualTo(options.ratio);
+ should(node.attack.value, 'node1.attack.value')
+ .beEqualTo(options.attack);
+ should(node.release.value, 'node1.release.value')
+ .beEqualTo(options.release);
+
+ should(node.channelCount, 'node1.channelCount').beEqualTo(2);
+ should(node.channelCountMode, 'node1.channelCountMode')
+ .beEqualTo('clamped-max');
+ should(node.channelInterpretation, 'node1.channelInterpretation')
+ .beEqualTo('speakers');
+
+ task.done();
+ });
+
+ audit.run();
+
+ // Test possible options for DynamicsCompressor constructor.
+ function testNode(should, context, options) {
+ // Node to be tested
+ let node;
+
+ let createNodeFunction = () => {
+ return () => node =
+ new DynamicsCompressorNode(context, options.nodeOptions);
+ };
+
+ let message = 'new DynamicsCompressorNode(c, ' +
+ JSON.stringify(options.nodeOptions) + ')';
+
+ if (options.expectedErrorType === TypeError) {
+ should(createNodeFunction(), message)
+ .throw(options.expectedErrorType);
+ } else if (options.expectedErrorType === 'NotSupportedError') {
+ should(createNodeFunction(), message)
+ .throw(DOMException, 'NotSupportedError');
+ } else {
+ should(createNodeFunction(), message).notThrow();
+ should(node[options.testAttribute], 'node.' + options.testAttribute)
+ .beEqualTo(options.expectedValue);
+ }
+ }
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-dynamicscompressornode-interface/dynamicscompressor-basic.html b/testing/web-platform/tests/webaudio/the-audio-api/the-dynamicscompressornode-interface/dynamicscompressor-basic.html
new file mode 100644
index 0000000000..6c602010d0
--- /dev/null
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-dynamicscompressornode-interface/dynamicscompressor-basic.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>
+ dynamicscompressor-basic.html
+ </title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/webaudio/resources/audit-util.js"></script>
+ <script src="/webaudio/resources/audit.js"></script>
+ </head>
+ <body>
+ <script id="layout-test-code">
+ let audit = Audit.createTaskRunner();
+ let context;
+ let compressor;
+
+ audit.define(
+ {
+ label: 'test',
+ description: 'Basic tests for DynamicsCompressorNode API'
+ },
+ function(task, should) {
+
+ context = new AudioContext();
+ compressor = context.createDynamicsCompressor();
+
+ should(compressor.threshold.value, 'compressor.threshold.value')
+ .beEqualTo(-24);
+ should(compressor.knee.value, 'compressor.knee.value')
+ .beEqualTo(30);
+ should(compressor.ratio.value, 'compressor.ratio.value')
+ .beEqualTo(12);
+ should(compressor.attack.value, 'compressor.attack.value')
+ .beEqualTo(Math.fround(0.003));
+ should(compressor.release.value, 'compressor.release.value')
+ .beEqualTo(0.25);
+ should(typeof compressor.reduction, 'typeof compressor.reduction')
+ .beEqualTo('number');
+ should(compressor.reduction, 'compressor.reduction').beEqualTo(0);
+
+ task.done();
+ });
+
+ audit.run();
+ </script>
+ </body>
+</html>