Skip to content

Commit fb70fe8

Browse files
committed
Fix type of exceptions thrown in the WebAudio API
https://bugs.webkit.org/show_bug.cgi?id=227959 Reviewed by Yusuke Suzuki. LayoutTests/imported/w3c: Resync WebAudio WPT tests from upstream 04ab41d to gain test coverage and rebaseline those tests. * web-platform-tests/webaudio/resources/audit.js: (Should.prototype.throw): * web-platform-tests/webaudio/the-audio-api/the-analysernode-interface/ctor-analyser-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontextoptions-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontextoptions.html: * web-platform-tests/webaudio/the-audio-api/the-audionode-interface/audionode-connect-method-chaining-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-audionode-interface/audionode-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-audionode-interface/different-contexts-expected.txt: Added. * web-platform-tests/webaudio/the-audio-api/the-audionode-interface/different-contexts.html: Added. * web-platform-tests/webaudio/the-audio-api/the-audionode-interface/w3c-import.log: * web-platform-tests/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-registerprocessor-dynamic.https-expected.txt: Added. * web-platform-tests/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-registerprocessor-dynamic.https.html: Added. * web-platform-tests/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-constructor-options.https-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-audioworklet-interface/processors/dynamic-register-processor.js: Added. (ProcessorA.prototype.process): (ProcessorA): (ProcessorB): (ProcessorB.prototype.process): * web-platform-tests/webaudio/the-audio-api/the-audioworklet-interface/processors/w3c-import.log: * web-platform-tests/webaudio/the-audio-api/the-audioworklet-interface/w3c-import.log: * web-platform-tests/webaudio/the-audio-api/the-biquadfilternode-interface/biquad-basic-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-biquadfilternode-interface/ctor-biquadfilter-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-channelsplitternode-interface/ctor-channelsplitter-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-channelsplitternode-interface/ctor-channelsplitter.html: * web-platform-tests/webaudio/the-audio-api/the-delaynode-interface/ctor-delay-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-gainnode-interface/ctor-gain-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-iirfilternode-interface/ctor-iirfilter-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-mediastreamaudiodestinationnode-interface/ctor-mediastreamaudiodestination-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-offlineaudiocontext-interface/ctor-offlineaudiocontext-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/ctor-oscillator-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-waveshapernode-interface/ctor-waveshaper-expected.txt: Source/WebCore: The upstream webaudio web-platform-tests were updated to validate the types of exceptions thrown by various WebAudio APIs. It became obvious that our implementation was not always throwing the right exception type and didn't match other browsers. This patch updates our WebAudio implementation to keep the WebAudio WPT tests passing now that they properly validate exception types. No new tests, re-sync'd and rebaselined existing WPT webaudio tests. * Modules/webaudio/AudioContext.cpp: (WebCore::AudioContext::create): * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::connect): (WebCore::AudioNode::setChannelCount): * Modules/webaudio/BaseAudioContext.cpp: (WebCore::BaseAudioContext::createScriptProcessor): * Modules/webaudio/BiquadFilterNode.cpp: (WebCore::BiquadFilterNode::getFrequencyResponse): * Modules/webaudio/ChannelSplitterNode.cpp: (WebCore::ChannelSplitterNode::setChannelCount): * Modules/webaudio/OfflineAudioContext.cpp: (WebCore::OfflineAudioContext::create): * Modules/webaudio/ScriptProcessorNode.cpp: (WebCore::ScriptProcessorNode::setChannelCount): LayoutTests: Resync audit.js from upstream WPT and rebaseline webaudio tests. * webaudio/OfflineAudioContext/offlineaudiocontext-constructor-expected.txt: * webaudio/dom-exceptions-expected.txt: * webaudio/resources/audit.js: (Should.prototype.throw): Canonical link: https://commits.webkit.org/239666@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@279917 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent e091065 commit fb70fe8

40 files changed

Lines changed: 362 additions & 64 deletions

File tree

LayoutTests/ChangeLog

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
2021-07-14 Chris Dumez <cdumez@apple.com>
2+
3+
Fix type of exceptions thrown in the WebAudio API
4+
https://bugs.webkit.org/show_bug.cgi?id=227959
5+
6+
Reviewed by Yusuke Suzuki.
7+
8+
Resync audit.js from upstream WPT and rebaseline webaudio tests.
9+
10+
* webaudio/OfflineAudioContext/offlineaudiocontext-constructor-expected.txt:
11+
* webaudio/dom-exceptions-expected.txt:
12+
* webaudio/resources/audit.js:
13+
(Should.prototype.throw):
14+
115
2021-07-14 Eric Hutchison <ehutchison@apple.com>
216

317
Update test expectations for storage/indexeddb/detached-iframe.html.

LayoutTests/imported/w3c/ChangeLog

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
1+
2021-07-14 Chris Dumez <cdumez@apple.com>
2+
3+
Fix type of exceptions thrown in the WebAudio API
4+
https://bugs.webkit.org/show_bug.cgi?id=227959
5+
6+
Reviewed by Yusuke Suzuki.
7+
8+
Resync WebAudio WPT tests from upstream 04ab41dced1f354873cab0 to gain test coverage and
9+
rebaseline those tests.
10+
11+
* web-platform-tests/webaudio/resources/audit.js:
12+
(Should.prototype.throw):
13+
* web-platform-tests/webaudio/the-audio-api/the-analysernode-interface/ctor-analyser-expected.txt:
14+
* web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontextoptions-expected.txt:
15+
* web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontextoptions.html:
16+
* web-platform-tests/webaudio/the-audio-api/the-audionode-interface/audionode-connect-method-chaining-expected.txt:
17+
* web-platform-tests/webaudio/the-audio-api/the-audionode-interface/audionode-expected.txt:
18+
* web-platform-tests/webaudio/the-audio-api/the-audionode-interface/different-contexts-expected.txt: Added.
19+
* web-platform-tests/webaudio/the-audio-api/the-audionode-interface/different-contexts.html: Added.
20+
* web-platform-tests/webaudio/the-audio-api/the-audionode-interface/w3c-import.log:
21+
* web-platform-tests/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-registerprocessor-dynamic.https-expected.txt: Added.
22+
* web-platform-tests/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-registerprocessor-dynamic.https.html: Added.
23+
* web-platform-tests/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-constructor-options.https-expected.txt:
24+
* web-platform-tests/webaudio/the-audio-api/the-audioworklet-interface/processors/dynamic-register-processor.js: Added.
25+
(ProcessorA.prototype.process):
26+
(ProcessorA):
27+
(ProcessorB):
28+
(ProcessorB.prototype.process):
29+
* web-platform-tests/webaudio/the-audio-api/the-audioworklet-interface/processors/w3c-import.log:
30+
* web-platform-tests/webaudio/the-audio-api/the-audioworklet-interface/w3c-import.log:
31+
* web-platform-tests/webaudio/the-audio-api/the-biquadfilternode-interface/biquad-basic-expected.txt:
32+
* web-platform-tests/webaudio/the-audio-api/the-biquadfilternode-interface/ctor-biquadfilter-expected.txt:
33+
* web-platform-tests/webaudio/the-audio-api/the-channelsplitternode-interface/ctor-channelsplitter-expected.txt:
34+
* web-platform-tests/webaudio/the-audio-api/the-channelsplitternode-interface/ctor-channelsplitter.html:
35+
* web-platform-tests/webaudio/the-audio-api/the-delaynode-interface/ctor-delay-expected.txt:
36+
* web-platform-tests/webaudio/the-audio-api/the-gainnode-interface/ctor-gain-expected.txt:
37+
* web-platform-tests/webaudio/the-audio-api/the-iirfilternode-interface/ctor-iirfilter-expected.txt:
38+
* web-platform-tests/webaudio/the-audio-api/the-mediastreamaudiodestinationnode-interface/ctor-mediastreamaudiodestination-expected.txt:
39+
* web-platform-tests/webaudio/the-audio-api/the-offlineaudiocontext-interface/ctor-offlineaudiocontext-expected.txt:
40+
* web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/ctor-oscillator-expected.txt:
41+
* web-platform-tests/webaudio/the-audio-api/the-waveshapernode-interface/ctor-waveshaper-expected.txt:
42+
143
2021-07-13 Alex Christensen <achristensen@webkit.org>
244

345
Update and fix URL WPT tests

LayoutTests/imported/w3c/web-platform-tests/webaudio/resources/audit.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,16 @@ window.Audit = (function() {
320320
didThrowCorrectly = true;
321321
passDetail = '${actual} threw ' + error.name + errorMessage + '.';
322322
} else if (this._expected === DOMException &&
323-
(this._expectedDescription === undefined ||
324-
this._expectedDescription === error.name)) {
325-
// Handles DOMException with the associated name.
326-
didThrowCorrectly = true;
327-
passDetail = '${actual} threw ${expected}' + errorMessage + '.';
323+
this._expectedDescription !== undefined) {
324+
// Handles DOMException with an expected exception name.
325+
if (this._expectedDescription === error.name) {
326+
didThrowCorrectly = true;
327+
passDetail = '${actual} threw ${expected}' + errorMessage + '.';
328+
} else {
329+
didThrowCorrectly = false;
330+
failDetail =
331+
'${actual} threw "' + error.name + '" instead of ${expected}.';
332+
}
328333
} else if (this._expected == error.constructor) {
329334
// Handler other error types.
330335
didThrowCorrectly = true;

LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-analysernode-interface/ctor-analyser-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ PASS > [test AudioNodeOptions]
3434
PASS new AnalyserNode(c, {channelCount: 17}) did not throw an exception.
3535
PASS node.channelCount is equal to 17.
3636
PASS new AnalyserNode(c, {channelCount: 0}) threw NotSupportedError: "Channel count cannot be 0".
37-
PASS new AnalyserNode(c, {channelCount: 99}) threw IndexSizeError: "Channel count exceeds maximum limit".
37+
PASS new AnalyserNode(c, {channelCount: 99}) threw NotSupportedError: "Channel count exceeds maximum limit".
3838
PASS new AnalyserNode(c, {channelCountMode: "max"} did not throw an exception.
3939
PASS node.channelCountMode is equal to max.
4040
PASS new AnalyserNode(c, {channelCountMode: "max"}) did not throw an exception.

LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontextoptions-expected.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ PASS context = new AudioContext({'latencyHint': 'foo'}) threw TypeError: "Type
2828
PASS context = new AudioContext('latencyHint') threw TypeError: "Type error".
2929
PASS < [test-audiocontextoptions-latencyHint-double] All assertions passed. (total 10 assertions)
3030
PASS > [test-audiocontextoptions-sampleRate] Test creating contexts with non-default sampleRate values.
31-
PASS context = new AudioContext({sampleRate: 1}) threw SyntaxError: "sampleRate is not in range".
32-
PASS context = new AudioContext({sampleRate: 1000000}) threw SyntaxError: "sampleRate is not in range".
33-
PASS context = new AudioContext({sampleRate: -1}) threw SyntaxError: "sampleRate is not in range".
34-
PASS context = new AudioContext({sampleRate: 0}) threw SyntaxError: "sampleRate is not in range".
31+
PASS context = new AudioContext({sampleRate: 1}) threw NotSupportedError: "sampleRate is not in range".
32+
PASS context = new AudioContext({sampleRate: 1000000}) threw NotSupportedError: "sampleRate is not in range".
33+
PASS context = new AudioContext({sampleRate: -1}) threw NotSupportedError: "sampleRate is not in range".
34+
PASS context = new AudioContext({sampleRate: 0}) threw NotSupportedError: "sampleRate is not in range".
3535
PASS context = new AudioContext({sampleRate: 24000}) did not throw an exception.
3636
PASS sampleRate inrange is equal to 24000.
3737
PASS < [test-audiocontextoptions-sampleRate] All assertions passed. (total 6 assertions)

LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontextoptions.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
context = new AudioContext({sampleRate: 1})
171171
},
172172
'context = new AudioContext({sampleRate: 1})')
173-
.throw(DOMException);
173+
.throw(DOMException, 'NotSupportedError');
174174

175175
// A sampleRate of 1,000,000 is unlikely to be supported on any
176176
// browser, test that this rate is also rejected.
@@ -179,21 +179,21 @@
179179
context = new AudioContext({sampleRate: 1000000})
180180
},
181181
'context = new AudioContext({sampleRate: 1000000})')
182-
.throw(DOMException);
182+
.throw(DOMException, 'NotSupportedError');
183183
// A negative sample rate should not be accepted
184184
should(
185185
() => {
186186
context = new AudioContext({sampleRate: -1})
187187
},
188188
'context = new AudioContext({sampleRate: -1})')
189-
.throw(DOMException);
189+
.throw(DOMException, 'NotSupportedError');
190190
// A null sample rate should not be accepted
191191
should(
192192
() => {
193193
context = new AudioContext({sampleRate: 0})
194194
},
195195
'context = new AudioContext({sampleRate: 0})')
196-
.throw(DOMException);
196+
.throw(DOMException, 'NotSupportedError');
197197

198198
should(
199199
() => {

LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audionode-interface/audionode-connect-method-chaining-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ PASS The return value of MediaStreamAudioSourceNode.connect(ChannelMergerNode,
5959
PASS < [media-group] All assertions passed. (total 6 assertions)
6060
PASS > [invalid-operation]
6161
PASS Connecting with an invalid output threw IndexSizeError: "Output index exceeds number of outputs".
62-
PASS Connecting to a node from the different context threw SyntaxError: "Source and destination nodes belong to different audio contexts".
62+
PASS Connecting to a node from the different context threw InvalidAccessError: "Source and destination nodes belong to different audio contexts".
6363
PASS < [invalid-operation] All assertions passed. (total 2 assertions)
6464
PASS > [verification]
6565
PASS The output of chained connection of gain nodes contains only the constant 0.125.

LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audionode-interface/audionode-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ PASS audioNode.connect(null, 0, 0) threw TypeError: "Argument 1 ('destination'
1212
PASS audioNode.connect(context.destination, 5, 0) threw IndexSizeError: "Output index exceeds number of outputs".
1313
PASS audioNode.connect(context.destination, 0, 5) threw IndexSizeError: "Input index exceeds number of inputs".
1414
PASS audioNode.connect(context.destination, 0, 0) did not throw an exception.
15-
PASS Connecting a node to a different context threw SyntaxError: "Source and destination nodes belong to different audio contexts".
15+
PASS Connecting a node to a different context threw InvalidAccessError: "Source and destination nodes belong to different audio contexts".
1616
PASS context3 = new AudioContext(1, 44100, 44100) threw TypeError: "Type error".
1717
PASS AudioNode is an EventTarget is true.
1818
PASS < [test] All assertions passed. (total 12 assertions)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
PASS # AUDIT TASK RUNNER STARTED.
3+
PASS Executing "setup"
4+
PASS Executing "Test 1"
5+
PASS Executing "Test 2"
6+
PASS Executing "Test 3"
7+
PASS Executing "Test 4"
8+
PASS Audit report
9+
PASS > [setup] Contexts for testing
10+
PASS c1 = new AudioContext() did not throw an exception.
11+
PASS c2 = new AudioContext() did not throw an exception.
12+
PASS < [setup] All assertions passed. (total 2 assertions)
13+
PASS > [Test 1] Connect nodes between contexts
14+
PASS Test 1: g1 = new GainNode(c1) did not throw an exception.
15+
PASS Test 1: g2 = new GainNode(c2) did not throw an exception.
16+
PASS Test 1: g2.connect(g1) threw InvalidAccessError: "Source and destination nodes belong to different audio contexts".
17+
PASS < [Test 1] All assertions passed. (total 3 assertions)
18+
PASS > [Test 2] Connect AudioParam between contexts
19+
PASS Test 2: g1 = new GainNode(c1) did not throw an exception.
20+
PASS Test 2: g2 = new GainNode(c2) did not throw an exception.
21+
PASS Test 2: g2.connect(g1.gain) threw InvalidAccessError: "Node and AudioParam belong to different audio contexts".
22+
PASS < [Test 2] All assertions passed. (total 3 assertions)
23+
PASS > [Test 3] Disconnect nodes between contexts
24+
PASS Test 3: g1 = new GainNode(c1) did not throw an exception.
25+
PASS Test 3: g2 = new GainNode(c2) did not throw an exception.
26+
PASS Test 3: g2.disconnect(g1) threw InvalidAccessError: "The given destination is not connected".
27+
PASS < [Test 3] All assertions passed. (total 3 assertions)
28+
PASS > [Test 4] Disconnect AudioParam between contexts
29+
PASS Test 4: g1 = new GainNode(c1) did not throw an exception.
30+
PASS Test 4: g2 = new GainNode(c2) did not throw an exception.
31+
PASS Test 4: g2.connect(g1.gain) threw InvalidAccessError: "The given destination is not connected".
32+
PASS < [Test 4] All assertions passed. (total 3 assertions)
33+
PASS # AUDIT TASK RUNNER FINISHED: 5 tasks ran successfully.
34+
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>
5+
Connections and disconnections with different contexts
6+
</title>
7+
<script src="/resources/testharness.js"></script>
8+
<script src="/resources/testharnessreport.js"></script>
9+
<script src="/webaudio/resources/audit-util.js"></script>
10+
<script src="/webaudio/resources/audit.js"></script>
11+
</head>
12+
<body>
13+
<script>
14+
let audit = Audit.createTaskRunner();
15+
16+
// Different contexts to be used for testing.
17+
let c1;
18+
let c2;
19+
20+
audit.define(
21+
{label: 'setup', description: 'Contexts for testing'},
22+
(task, should) => {
23+
should(() => {c1 = new AudioContext()}, 'c1 = new AudioContext()')
24+
.notThrow();
25+
should(() => {c2 = new AudioContext()}, 'c2 = new AudioContext()')
26+
.notThrow();
27+
task.done();
28+
});
29+
30+
audit.define(
31+
{label: 'Test 1', description: 'Connect nodes between contexts'},
32+
(task, should) => {
33+
let g1;
34+
let g2;
35+
should(
36+
() => {g1 = new GainNode(c1)}, 'Test 1: g1 = new GainNode(c1)')
37+
.notThrow();
38+
should(
39+
() => {g2 = new GainNode(c2)}, 'Test 1: g2 = new GainNode(c2)')
40+
.notThrow();
41+
should(() => {g2.connect(g1)}, 'Test 1: g2.connect(g1)')
42+
.throw(DOMException, 'InvalidAccessError');
43+
task.done();
44+
});
45+
46+
audit.define(
47+
{label: 'Test 2', description: 'Connect AudioParam between contexts'},
48+
(task, should) => {
49+
let g1;
50+
let g2;
51+
should(
52+
() => {g1 = new GainNode(c1)}, 'Test 2: g1 = new GainNode(c1)')
53+
.notThrow();
54+
should(
55+
() => {g2 = new GainNode(c2)}, 'Test 2: g2 = new GainNode(c2)')
56+
.notThrow();
57+
should(() => {g2.connect(g1.gain)}, 'Test 2: g2.connect(g1.gain)')
58+
.throw(DOMException, 'InvalidAccessError');
59+
task.done();
60+
});
61+
62+
audit.define(
63+
{label: 'Test 3', description: 'Disconnect nodes between contexts'},
64+
(task, should) => {
65+
let g1;
66+
let g2;
67+
should(
68+
() => {g1 = new GainNode(c1)}, 'Test 3: g1 = new GainNode(c1)')
69+
.notThrow();
70+
should(
71+
() => {g2 = new GainNode(c2)}, 'Test 3: g2 = new GainNode(c2)')
72+
.notThrow();
73+
should(() => {g2.disconnect(g1)}, 'Test 3: g2.disconnect(g1)')
74+
.throw(DOMException, 'InvalidAccessError');
75+
task.done();
76+
});
77+
78+
audit.define(
79+
{
80+
label: 'Test 4',
81+
description: 'Disconnect AudioParam between contexts'
82+
},
83+
(task, should) => {
84+
let g1;
85+
let g2;
86+
should(
87+
() => {g1 = new GainNode(c1)}, 'Test 4: g1 = new GainNode(c1)')
88+
.notThrow();
89+
should(
90+
() => {g2 = new GainNode(c2)}, 'Test 4: g2 = new GainNode(c2)')
91+
.notThrow();
92+
should(
93+
() => {g2.disconnect(g1.gain)}, 'Test 4: g2.connect(g1.gain)')
94+
.throw(DOMException, 'InvalidAccessError');
95+
task.done();
96+
});
97+
98+
audit.run();
99+
</script>
100+
</body>
101+
</html>

0 commit comments

Comments
 (0)