gecko-dev/testing/web-platform/tests/webrtc/RTCTrackEvent-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

159 lines
4.9 KiB
HTML

<!doctype html>
<meta charset=utf-8>
<title>RTCTrackEvent constructor</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';
// Test is based on the following editor draft:
// https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html
/*
5.7. RTCTrackEvent
[Constructor(DOMString type, RTCTrackEventInit eventInitDict)]
interface RTCTrackEvent : Event {
readonly attribute RTCRtpReceiver receiver;
readonly attribute MediaStreamTrack track;
[SameObject]
readonly attribute FrozenArray<MediaStream> streams;
readonly attribute RTCRtpTransceiver transceiver;
};
dictionary RTCTrackEventInit : EventInit {
required RTCRtpReceiver receiver;
required MediaStreamTrack track;
sequence<MediaStream> streams = [];
required RTCRtpTransceiver transceiver;
};
*/
test(t => {
const pc = new RTCPeerConnection();
const transceiver = pc.addTransceiver('audio');
const { receiver } = transceiver;
const { track } = receiver;
const trackEvent = new RTCTrackEvent('track', {
receiver, track, transceiver
});
assert_equals(trackEvent.receiver, receiver);
assert_equals(trackEvent.track, track);
assert_array_equals(trackEvent.streams, []);
assert_equals(trackEvent.streams, trackEvent.streams, '[SameObject]');
assert_equals(trackEvent.transceiver, transceiver);
assert_equals(trackEvent.type, 'track');
assert_false(trackEvent.bubbles);
assert_false(trackEvent.cancelable);
}, `new RTCTrackEvent() with valid receiver, track, transceiver should succeed`);
test(t => {
const pc = new RTCPeerConnection();
const transceiver = pc.addTransceiver('audio');
const { receiver } = transceiver;
const { track } = receiver;
const stream = new MediaStream([track]);
const trackEvent = new RTCTrackEvent('track', {
receiver, track, transceiver,
streams: [stream]
});
assert_equals(trackEvent.receiver, receiver);
assert_equals(trackEvent.track, track);
assert_array_equals(trackEvent.streams, [stream]);
assert_equals(trackEvent.transceiver, transceiver);
}, `new RTCTrackEvent() with valid receiver, track, streams, transceiver should succeed`);
test(t => {
const pc = new RTCPeerConnection();
const transceiver = pc.addTransceiver('audio');
const { receiver } = transceiver;
const { track } = receiver;
const stream1 = new MediaStream([track]);
const stream2 = new MediaStream([track]);
const trackEvent = new RTCTrackEvent('track', {
receiver, track, transceiver,
streams: [stream1, stream2]
});
assert_equals(trackEvent.receiver, receiver);
assert_equals(trackEvent.track, track);
assert_array_equals(trackEvent.streams, [stream1, stream2]);
assert_equals(trackEvent.transceiver, transceiver);
}, `new RTCTrackEvent() with valid receiver, track, multiple streams, transceiver should succeed`);
test(t => {
const pc = new RTCPeerConnection();
const transceiver = pc.addTransceiver('audio');
const receiver = pc.addTransceiver('audio').receiver;
const track = pc.addTransceiver('audio').receiver.track;
const stream = new MediaStream();
const trackEvent = new RTCTrackEvent('track', {
receiver, track, transceiver,
streams: [stream]
});
assert_equals(trackEvent.receiver, receiver);
assert_equals(trackEvent.track, track);
assert_array_equals(trackEvent.streams, [stream]);
assert_equals(trackEvent.transceiver, transceiver);
}, `new RTCTrackEvent() with unrelated receiver, track, streams, transceiver should succeed`);
test(t => {
const pc = new RTCPeerConnection();
const transceiver = pc.addTransceiver('audio');
const { receiver } = transceiver;
const { track } = receiver;
assert_throws_js(TypeError, () =>
new RTCTrackEvent('track', {
receiver, track
}));
}, `new RTCTrackEvent() with no transceiver should throw TypeError`);
test(t => {
const pc = new RTCPeerConnection();
const transceiver = pc.addTransceiver('audio');
const { receiver } = transceiver;
assert_throws_js(TypeError, () =>
new RTCTrackEvent('track', {
receiver, transceiver
}));
}, `new RTCTrackEvent() with no track should throw TypeError`);
test(t => {
const pc = new RTCPeerConnection();
const transceiver = pc.addTransceiver('audio');
const { receiver } = transceiver;
const { track } = receiver;
assert_throws_js(TypeError, () =>
new RTCTrackEvent('track', {
track, transceiver
}));
}, `new RTCTrackEvent() with no receiver should throw TypeError`);
/*
Coverage Report
Interface tests are counted as 1 trivial test
Tested 1
Total 1
*/
</script>