gecko-dev/testing/web-platform/tests/webrtc/RTCIceCandidate-constructor.html
Stephen McGruer c67612824c Bug 1610938 [wpt PR 21354] - Replace some "assert_throws(new FooError(), stuff)" calls with assert_throws_js, a=testonly
Automatic update from web-platform-tests
Replace some "assert_throws(new FooError(), stuff)" calls with assert_throws_js. (#21354)

This diff was generated by running:

  find . -type f -print0 | xargs -0 perl -pi -e 'BEGIN { $/ = undef; } s/assert_throws\(([ \n]*)new ([A-Za-z]*Error) *\(\) *(, *.)/assert_throws_js(\1\2\3/gs'

and then:

1) Manually adjusting fullscreen/rendering/fullscreen-pseudo-class-support.html
to test for the right sort of exceptions ("SyntaxError" DOMException, not a JS
SyntaxError).

2) Manually adjusting performance-timeline/po-observe-type.any.js to test for
the right sort of exceptions ("SyntaxError" DOMException, not a JS
SyntaxError).

3) Manually adjusting performance-timeline/po-observe.any.js to test for
the right sort of exceptions ("SyntaxError" DOMException, not a JS
SyntaxError).

4) Manually adjusting user-timing/mark_exceptions.html to test for the right
sort of exceptions ("SyntaxError" DOMException, not a JS SyntaxError).

5) Manually adjusting user-timing/measure_syntax_err.any.js to test for the right
sort of exceptions ("SyntaxError" DOMException, not a JS SyntaxError).

6) Manually adjusting domxpath/lexical-structure.html to test for a
"SyntaxError" DOMException, since that's what all browsers throw and there is no
clear spec for this.

7) Manually adjusting workers/constructors/Worker/Worker-constructor.html to
test for the right sort of exceptions ("SyntaxError" DOMException, not a JS
SyntaxError).

8) Backing out the changes to resources/idlharness.js because some tests pass
objects from a different window to it, and we end up with the wrong TypeError
constructor in those cases.

This does affect indentation poorly in cases when the first arg was on the same
line as the assert_throws, there was a newline after the ',' after the first
arg, and the following args were lined up with the first arg.  Fixing that,
especially when there are multiple lines after the first arg, is not trivial
with a regexp.

Co-authored-by: Boris Zbarsky <bzbarsky@mit.edu>
Co-authored-by: Stephen McGruer <smcgruer@chromium.org>

--

wpt-commits: 2c5c3c4c27d27a419c1fdba3e9879c2d22037074
wpt-pr: 21354
2020-01-27 15:35:57 +00:00

234 lines
9.3 KiB
HTML

<!doctype html>
<title>RTCIceCandidate constructor</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
'use strict';
const candidateString = 'candidate:1905690388 1 udp 2113937151 192.168.0.1 58041 typ host generation 0 ufrag thC8 network-cost 50';
const candidateString2 = 'candidate:435653019 2 tcp 1845501695 192.168.0.196 4444 typ srflx raddr www.example.com rport 22222 tcptype active';
const arbitraryString = '<arbitrary string[0] content>;';
test(t => {
// The argument for RTCIceCandidateInit is optional (w3c/webrtc-pc #1153 #1166),
// but the constructor throws because both sdpMid and sdpMLineIndex are null by default.
// Note that current browsers pass this test but may throw TypeError for
// different reason, i.e. they don't accept empty argument.
// Further tests below are used to differentiate the errors.
assert_throws_js(TypeError, () => new RTCIceCandidate());
}, 'new RTCIceCandidate()');
test(t => {
// All fields in RTCIceCandidateInit are optional,
// but the constructor throws because both sdpMid and sdpMLineIndex are null by default.
// Note that current browsers pass this test but may throw TypeError for
// different reason, i.e. they don't allow undefined candidate string.
// Further tests below are used to differentiate the errors.
assert_throws_js(TypeError, () => new RTCIceCandidate({}));
}, 'new RTCIceCandidate({})');
test(t => {
// Checks that manually filling the default values for RTCIceCandidateInit
// still throws because both sdpMid and sdpMLineIndex are null
assert_throws_js(TypeError,
() => new RTCIceCandidate({
candidate: '',
sdpMid: null,
sdpMLineIndex: null,
usernameFragment: undefined
}));
}, 'new RTCIceCandidate({ ... }) with manually filled default values');
test(t => {
// Checks that explicitly setting both sdpMid and sdpMLineIndex null should throw
assert_throws_js(TypeError,
() => new RTCIceCandidate({
sdpMid: null,
sdpMLineIndex: null
}));
}, 'new RTCIceCandidate({ sdpMid: null, sdpMLineIndex: null })');
test(t => {
// Throws because both sdpMid and sdpMLineIndex are null by default
assert_throws_js(TypeError,
() => new RTCIceCandidate({
candidate: ''
}));
}, `new RTCIceCandidate({ candidate: '' })`);
test(t => {
// Throws because the candidate field is not nullable
assert_throws_js(TypeError,
() => new RTCIceCandidate({
candidate: null
}));
}, `new RTCIceCandidate({ candidate: null })`);
test(t => {
// Throws because both sdpMid and sdpMLineIndex are null by default
assert_throws_js(TypeError,
() => new RTCIceCandidate({
candidate: candidateString
}));
}, 'new RTCIceCandidate({ ... }) with valid candidate string only');
test(t => {
const candidate = new RTCIceCandidate({ sdpMid: 'audio' });
assert_equals(candidate.candidate, '', 'candidate');
assert_equals(candidate.sdpMid, 'audio', 'sdpMid');
assert_equals(candidate.sdpMLineIndex, null, 'sdpMLineIndex');
assert_equals(candidate.usernameFragment, null, 'usernameFragment');
}, `new RTCIceCandidate({ sdpMid: 'audio' })`);
test(t => {
const candidate = new RTCIceCandidate({ sdpMLineIndex: 0 });
assert_equals(candidate.candidate, '', 'candidate');
assert_equals(candidate.sdpMid, null, 'sdpMid');
assert_equals(candidate.sdpMLineIndex, 0, 'sdpMLineIndex');
assert_equals(candidate.usernameFragment, null, 'usernameFragment');
}, 'new RTCIceCandidate({ sdpMLineIndex: 0 })');
test(t => {
const candidate = new RTCIceCandidate({
sdpMid: 'audio',
sdpMLineIndex: 0
});
assert_equals(candidate.candidate, '', 'candidate');
assert_equals(candidate.sdpMid, 'audio', 'sdpMid');
assert_equals(candidate.sdpMLineIndex, 0, 'sdpMLineIndex');
assert_equals(candidate.usernameFragment, null, 'usernameFragment');
}, `new RTCIceCandidate({ sdpMid: 'audio', sdpMLineIndex: 0 })`);
test(t => {
const candidate = new RTCIceCandidate({
candidate: '',
sdpMid: 'audio'
});
assert_equals(candidate.candidate, '', 'candidate');
assert_equals(candidate.sdpMid, 'audio', 'sdpMid');
assert_equals(candidate.sdpMLineIndex, null, 'sdpMLineIndex');
assert_equals(candidate.usernameFragment, null, 'usernameFragment');
}, `new RTCIceCandidate({ candidate: '', sdpMid: 'audio' }`);
test(t => {
const candidate = new RTCIceCandidate({
candidate: '',
sdpMLineIndex: 0
});
assert_equals(candidate.candidate, '', 'candidate');
assert_equals(candidate.sdpMid, null, 'sdpMid', 'sdpMid');
assert_equals(candidate.sdpMLineIndex, 0, 'sdpMLineIndex');
assert_equals(candidate.usernameFragment, null, 'usernameFragment');
}, `new RTCIceCandidate({ candidate: '', sdpMLineIndex: 0 }`);
test(t => {
const candidate = new RTCIceCandidate({
candidate: candidateString,
sdpMid: 'audio'
});
assert_equals(candidate.candidate, candidateString, 'candidate');
assert_equals(candidate.sdpMid, 'audio', 'sdpMid');
assert_equals(candidate.sdpMLineIndex, null, 'sdpMLineIndex');
assert_equals(candidate.usernameFragment, null, 'usernameFragment');
}, 'new RTCIceCandidate({ ... }) with valid candidate string and sdpMid');
test(t =>{
// candidate string is not validated in RTCIceCandidate
const candidate = new RTCIceCandidate({
candidate: arbitraryString,
sdpMid: 'audio'
});
assert_equals(candidate.candidate, arbitraryString, 'candidate');
assert_equals(candidate.sdpMid, 'audio', 'sdpMid');
assert_equals(candidate.sdpMLineIndex, null, 'sdpMLineIndex');
assert_equals(candidate.usernameFragment, null, 'usernameFragment');
}, 'new RTCIceCandidate({ ... }) with invalid candidate string and sdpMid');
test(t => {
const candidate = new RTCIceCandidate({
candidate: candidateString,
sdpMid: 'video',
sdpMLineIndex: 1,
usernameFragment: 'test'
});
assert_equals(candidate.candidate, candidateString, 'candidate');
assert_equals(candidate.sdpMid, 'video', 'sdpMid');
assert_equals(candidate.sdpMLineIndex, 1, 'sdpMLineIndex');
assert_equals(candidate.usernameFragment, 'test', 'usernameFragment');
// The following fields should match those in the candidate field
assert_equals(candidate.foundation, '1905690388', 'foundation');
assert_equals(candidate.component, 'rtp', 'component');
assert_equals(candidate.priority, 2113937151, 'priority');
assert_equals(candidate.address, '192.168.0.1', 'address');
assert_equals(candidate.protocol, 'udp', 'protocol');
assert_equals(candidate.port, 58041, 'port');
assert_equals(candidate.type, 'host', 'type');
assert_equals(candidate.tcpType, '', 'tcpType');
assert_equals(candidate.relatedAddress, null, 'relatedAddress');
assert_equals(candidate.relatedPort, null, 'relatedPort');
}, 'new RTCIceCandidate({ ... }) with nondefault values for all fields');
test(t => {
const candidate = new RTCIceCandidate({
candidate: candidateString2,
sdpMid: 'video',
sdpMLineIndex: 1,
usernameFragment: 'user1'
});
assert_equals(candidate.candidate, candidateString2, 'candidate');
assert_equals(candidate.sdpMid, 'video', 'sdpMid');
assert_equals(candidate.sdpMLineIndex, 1, 'sdpMLineIndex');
assert_equals(candidate.usernameFragment, 'user1', 'usernameFragment');
// The following fields should match those in the candidate field
assert_equals(candidate.foundation, '435653019', 'foundation');
assert_equals(candidate.component, 'rtcp', 'component');
assert_equals(candidate.priority, 1845501695, 'priority');
assert_equals(candidate.address, '192.168.0.196', 'address');
assert_equals(candidate.protocol, 'tcp', 'protocol');
assert_equals(candidate.port, 4444, 'port');
assert_equals(candidate.type, 'srflx', 'type');
assert_equals(candidate.tcpType, 'active', 'tcpType');
assert_equals(candidate.relatedAddress, 'www.example.com', 'relatedAddress');
assert_equals(candidate.relatedPort, 22222, 'relatedPort');
}, 'new RTCIceCandidate({ ... }) with nondefault values for all fields, tcp candidate');
test(t => {
// sdpMid is not validated in RTCIceCandidate
const candidate = new RTCIceCandidate({
sdpMid: arbitraryString
});
assert_equals(candidate.candidate, '', 'candidate');
assert_equals(candidate.sdpMid, arbitraryString, 'sdpMid');
assert_equals(candidate.sdpMLineIndex, null, 'sdpMLineIndex');
assert_equals(candidate.usernameFragment, null, 'usernameFragment');
}, 'new RTCIceCandidate({ ... }) with invalid sdpMid');
test(t => {
// Some arbitrary large out of bound line index that practically
// do not reference any m= line in SDP.
// However sdpMLineIndex is not validated in RTCIceCandidate
// and it has no knowledge of the SDP it is associated with.
const candidate = new RTCIceCandidate({
sdpMLineIndex: 65535
});
assert_equals(candidate.candidate, '', 'candidate');
assert_equals(candidate.sdpMid, null, 'sdpMid');
assert_equals(candidate.sdpMLineIndex, 65535, 'sdpMLineIndex');
assert_equals(candidate.usernameFragment, null, 'usernameFragment');
}, 'new RTCIceCandidate({ ... }) with invalid sdpMLineIndex');
</script>