commit 2db41c23764f0fd368c643a1c8d6c4558ffec80f
parent 83d59a988ffd7062789452b6a2390c468dae782a
Author: punithbnayak <punithbnayak@chromium.org>
Date: Thu, 9 Oct 2025 16:29:03 +0000
Bug 1991175 [wpt PR 55112] - [webaudio-testharness] Migrate audioworkletnode-disconnected-input.https.html, a=testonly
Automatic update from web-platform-tests
[webaudio-testharness] Migrate audioworkletnode-disconnected-input.https.html
Convert audioworkletnode-disconnected-input.https.html from the legacy
audit.js runner to pure testharness.js
Change-Id: I5d6f6dfc5ceb89ef0e1ae8eb75c874224b613e2b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6934240
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@{#1521683}
--
wpt-commits: f475bf7d3200757c89e9ff0aefb73fd843219bad
wpt-pr: 55112
Diffstat:
1 file changed, 60 insertions(+), 71 deletions(-)
diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-disconnected-input.https.html b/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-disconnected-input.https.html
@@ -6,95 +6,84 @@
</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>
</head>
<body>
- <script id="layout-test-code">
- let audit = Audit.createTaskRunner();
-
+ <script>
// Arbitrary numbers used to align the test with render quantum boundary.
// The sample rate is a power of two to eliminate roundoff in computing
// the suspend time needed for the test.
- let sampleRate = 16384;
- let renderLength = 8 * RENDER_QUANTUM_FRAMES;
- let context;
-
- let filePath = 'processors/input-length-processor.js';
-
- let testChannelValues = [1, 2, 3];
+ const sampleRate = 16384;
+ const renderLength = 8 * RENDER_QUANTUM_FRAMES;
+ const filePath = 'processors/input-length-processor.js';
// Creates a 3-channel buffer and play with BufferSourceNode. The source
// goes through a bypass AudioWorkletNode (gain value of 1).
- audit.define(
- {
- label: 'test',
- description:
- 'Input array length should be zero for disconnected input'
- },
- (task, should) => {
- context = new OfflineAudioContext({
- numberOfChannels: 1,
- length: renderLength,
- sampleRate: sampleRate
- });
-
- context.audioWorklet.addModule(filePath).then(() => {
- let sourceNode = new ConstantSourceNode(context);
- let workletNode =
- new AudioWorkletNode(context, 'input-length-processor');
+ promise_test(async () => {
+ const context = new OfflineAudioContext({
+ numberOfChannels: 1,
+ length: renderLength,
+ sampleRate: sampleRate
+ });
- workletNode.connect(context.destination);
+ await context.audioWorklet.addModule(filePath);
- // Connect the source now.
- let connectFrame = RENDER_QUANTUM_FRAMES;
+ const sourceNode = new ConstantSourceNode(context);
+ const workletNode =
+ new AudioWorkletNode(context, 'input-length-processor');
- context.suspend(connectFrame / sampleRate)
- .then(() => {
- sourceNode.connect(workletNode);
- })
- .then(() => context.resume());
- ;
+ workletNode.connect(context.destination);
- // Then disconnect the source after a few renders
- let disconnectFrame = 3 * RENDER_QUANTUM_FRAMES;
- context.suspend(disconnectFrame / sampleRate)
- .then(() => {
- sourceNode.disconnect(workletNode);
- })
- .then(() => context.resume());
+ // Connect the source after one render quantum.
+ const connectFrame = RENDER_QUANTUM_FRAMES;
+ context.suspend(connectFrame / sampleRate).then(() => {
+ sourceNode.connect(workletNode);
+ return context.resume();
+ });
+ // Disconnect the source after three render quanta.
+ const disconnectFrame = 3 * RENDER_QUANTUM_FRAMES;
+ context.suspend(disconnectFrame / sampleRate).then(() => {
+ sourceNode.disconnect(workletNode);
+ return context.resume();
+ });
- sourceNode.start();
- context.startRendering()
- .then(resultBuffer => {
- let data = resultBuffer.getChannelData(0);
+ sourceNode.start();
+ const resultBuffer = await context.startRendering();
+ const data = resultBuffer.getChannelData(0);
- should(
- data.slice(0, connectFrame),
- 'Before connecting the source: Input array length')
- .beConstantValueOf(0);
+ // Before connecting the source: input array length should be 0.
+ assert_array_equals(
+ data.subarray(0, connectFrame),
+ new Float32Array(connectFrame),
+ 'Before connecting the source: Input array length should be 0');
- // Find where the output is no longer 0.
- let nonZeroIndex = data.findIndex(x => x > 0);
- should(nonZeroIndex, 'First non-zero output')
- .beEqualTo(connectFrame);
+ // Find where the output is no longer 0.
+ const nonZeroIndex = data.findIndex(x => x > 0);
+ assert_equals(
+ nonZeroIndex,
+ connectFrame,
+ 'First non-zero output should occur exactly at connectFrame');
- should(
- data.slice(
- nonZeroIndex,
- nonZeroIndex + (disconnectFrame - connectFrame)),
- 'While source is connected: Input array length')
- .beConstantValueOf(RENDER_QUANTUM_FRAMES);
- should(
- data.slice(disconnectFrame),
- 'After disconnecting the source: Input array length')
- .beConstantValueOf(0);
- })
- .then(() => task.done());
- });
- });
+ // While source is connected: Input array length
+ // should be RENDER_QUANTUM_FRAMES
+ {
+ const expectedLength = disconnectFrame - connectFrame;
+ const expected =
+ new Float32Array(expectedLength).fill(RENDER_QUANTUM_FRAMES);
+ assert_array_equals(
+ data.subarray(connectFrame, disconnectFrame), expected,
+ 'While source is connected: Input array length');
+ }
- audit.run();
+ // After disconnecting the source: Input array length should be zero
+ {
+ const expectedLength = data.length - disconnectFrame;
+ const expected = new Float32Array(expectedLength);
+ assert_array_equals(
+ data.subarray(disconnectFrame), expected,
+ 'After disconnecting the source: Input array length');
+ }
+ }, 'Input array length should be zero for disconnected input');
</script>
</body>
</html>