commit 0b4b72b16fe3ba389075aa31aea573fdd72666d4
parent 4dd232594c61988c90cafa8a23003b65522f93f6
Author: punithbnayak <punithbnayak@chromium.org>
Date: Mon, 27 Oct 2025 10:08:14 +0000
Bug 1996322 [wpt PR 55642] - [webaudio-testharness] Migrate constant-source-basic.html, a=testonly
Automatic update from web-platform-tests
[webaudio-testharness] Migrate constant-source-basic.html
Convert constant-source-basic.html from the legacy
audit.js runner to pure testharness.js
Change-Id: Ice8c52151a6af7af01fece2166cc2c64576695e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7005123
Reviewed-by: Michael Wilson <mjwilson@chromium.org>
Reviewed-by: Hongchan Choi <hongchan@chromium.org>
Commit-Queue: Punith Nayak <punithbnayak@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1535114}
--
wpt-commits: 4df7ff76f96c648b920f665cbf80c13b31b4a70d
wpt-pr: 55642
Diffstat:
2 files changed, 101 insertions(+), 67 deletions(-)
diff --git a/testing/web-platform/tests/webaudio/resources/start-stop-exceptions.js b/testing/web-platform/tests/webaudio/resources/start-stop-exceptions.js
@@ -43,3 +43,58 @@ function testStartStop(should, node, options) {
});
}
+/**
+ * @function
+ * @param {AudioScheduledSourceNode} node - The AudioScheduledSourceNode (e.g.,
+ * ConstantSourceNode, AudioBufferSourceNode) to test.
+ * @param {Array<Object>} [options] - Optional: An array of test objects for
+ * additional start() exceptions. Each object should have:
+ * - `errorType`: The expected error constructor(e.g., TypeError,
+ * RangeError).
+ * - `args`: An array of arguments to pass to the `node.start()` method.
+ * @description Tests that AudioScheduledSourceNode's `start()` and `stop()`
+ * methods throw the correct exceptions for invalid input values and states,
+ * according to the Web Audio API specification. This function uses
+ * `testharness.js` assertions.
+ */
+const testStartStop_W3CTH = (node, options) => {
+ // Test non-finite values for start. These should all throw a TypeError
+ const nonFiniteValues = [NaN, Infinity, -Infinity];
+
+ nonFiniteValues.forEach((time) => {
+ assert_throws_js(TypeError, () => {
+ node.start(time);
+ }, `start(${time})`);
+ });
+
+ assert_throws_dom('InvalidStateError', () => {
+ node.stop();
+ }, 'Calling stop() before start()');
+
+ assert_throws_js(RangeError, () => {
+ node.start(-1);
+ }, 'start(-1)');
+
+ if (options) {
+ options.forEach((test) => {
+ assert_throws_js(test.errorType, () => {
+ node.start(...test.args);
+ }, `start(${test.args})`);
+ });
+ }
+
+ node.start();
+ assert_throws_dom('InvalidStateError', () => {
+ node.start();
+ }, 'Calling start() twice');
+ assert_throws_js(RangeError, () => {
+ node.stop(-1);
+ }, 'stop(-1)');
+
+ // Test non-finite stop times
+ nonFiniteValues.forEach((time) => {
+ assert_throws_js(TypeError, () => {
+ node.stop(time);
+ }, `stop(${time})`);
+ });
+}
diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-constantsourcenode-interface/constant-source-basic.html b/testing/web-platform/tests/webaudio/the-audio-api/the-constantsourcenode-interface/constant-source-basic.html
@@ -1,85 +1,64 @@
<!DOCTYPE html>
<html>
<head>
- <title>
- Basic ConstantSourceNode Tests
- </title>
+ <title>Basic ConstantSourceNode Tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
- <script src="../../resources/audit-util.js"></script>
- <script src="../../resources/audit.js"></script>
<script src="../../resources/start-stop-exceptions.js"></script>
</head>
<body>
- <script id="layout-test-code">
- let context = new AudioContext();
+ <script>
+ const context = new AudioContext();
- let audit = Audit.createTaskRunner();
+ test(() => {
+ const node = new ConstantSourceNode(context);
+ verifyNodeDefaults(node);
+ }, `ConstantSourceNode constructor creates a valid node `+
+ `with correct defaults`);
- audit.define('createConstantSource()', (task, should) => {
- let node;
- let prefix = 'Factory method: ';
+ test(() => {
+ const node = new ConstantSourceNode(context);
+ testStartStop_W3CTH(node);
+ }, `ConstantSourceNode start()/stop() should throw correct `+
+ `exceptions per spec`);
- should(() => {
- node = context.createConstantSource();
- }, prefix + 'node = context.createConstantSource()').notThrow();
- should(
- node instanceof ConstantSourceNode,
- prefix + 'node instance of ConstantSourceNode')
- .beEqualTo(true);
+ test(() => {
+ const node = context.createConstantSource();
+ assert_true(node instanceof ConstantSourceNode,
+ 'Factory should return a ConstantSourceNode');
+ verifyNodeDefaults(node);
+ }, `context.createConstantSource() creates a ConstantSourceNode `+
+ `with correct defaults`);
- verifyNodeDefaults(should, node, prefix);
+ test(() => {
+ const node = context.createConstantSource();
+ testStartStop_W3CTH(node);
+ }, `context.createConstantSource() node start()/stop() should `+
+ `throw correct exceptions per spec`);
- task.done();
- });
+ function verifyNodeDefaults(node) {
+ assert_equals(node.numberOfInputs, 0, 'numberOfInputs should be 0');
+ assert_equals(node.numberOfOutputs, 1, 'numberOfOutputs should be 1');
+ assert_equals(node.channelCount, 2, 'channelCount should be 2');
+ assert_equals(
+ node.channelCountMode, 'max', 'channelCountMode should be "max"');
+ assert_equals(
+ node.channelInterpretation,
+ 'speakers',
+ 'channelInterpretation should be "speakers"');
- audit.define('new ConstantSourceNode()', (task, should) => {
- let node;
- let prefix = 'Constructor: ';
-
- should(() => {
- node = new ConstantSourceNode(context);
- }, prefix + 'node = new ConstantSourceNode()').notThrow();
- should(
- node instanceof ConstantSourceNode,
- prefix + 'node instance of ConstantSourceNode')
- .beEqualTo(true);
-
-
- verifyNodeDefaults(should, node, prefix);
-
- task.done();
- });
-
- audit.define('start/stop exceptions', (task, should) => {
- let node = new ConstantSourceNode(context);
-
- testStartStop(should, node);
- task.done();
- });
-
- function verifyNodeDefaults(should, node, prefix) {
- should(node.numberOfInputs, prefix + 'node.numberOfInputs')
- .beEqualTo(0);
- should(node.numberOfOutputs, prefix + 'node.numberOfOutputs')
- .beEqualTo(1);
- should(node.channelCount, prefix + 'node.channelCount').beEqualTo(2);
- should(node.channelCountMode, prefix + 'node.channelCountMode')
- .beEqualTo('max');
- should(
- node.channelInterpretation, prefix + 'node.channelInterpretation')
- .beEqualTo('speakers');
-
- should(node.offset.value, prefix + 'node.offset.value').beEqualTo(1);
- should(node.offset.defaultValue, prefix + 'node.offset.defaultValue')
- .beEqualTo(1);
- should(node.offset.minValue, prefix + 'node.offset.minValue')
- .beEqualTo(Math.fround(-3.4028235e38));
- should(node.offset.maxValue, prefix + 'node.offset.maxValue')
- .beEqualTo(Math.fround(3.4028235e38));
+ assert_equals(node.offset.value, 1, 'offset.value should be 1');
+ assert_equals(
+ node.offset.defaultValue, 1, 'offset.defaultValue should be 1');
+ assert_equals(
+ node.offset.minValue,
+ Math.fround(-3.4028235e38),
+ 'offset.minValue should match spec');
+ assert_equals(
+ node.offset.maxValue,
+ Math.fround(3.4028235e38),
+ 'offset.maxValue should match spec');
}
-
- audit.run();
</script>
</body>
</html>