-
Notifications
You must be signed in to change notification settings - Fork 54
/
RTCQuicTransport.https.html
189 lines (168 loc) · 7.78 KB
/
RTCQuicTransport.https.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!doctype html>
<meta charset=utf-8>
<title>RTCQuicTransport.https.html</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="RTCIceTransport-extension-helper.js"></script>
<script src="RTCQuicTransport-helper.js"></script>
<script>
'use strict';
// These tests are based on the following specification:
// https://w3c.github.io/webrtc-quic/
// The following helper functions are called from
// RTCIceTransport-extension-helper.js:
// makeIceTransport
// makeAndGatherTwoIceTransports
// The following helper functions are called from RTCQuicTransport-helper.js:
// generateCertificate
// makeQuicTransport
// makeStandaloneQuicTransport
// makeAndStartTwoQuicTransports
// makeTwoConnectedQuicTransports
promise_test(async t => {
const certificate = await generateCertificate();
const iceTransport = makeIceTransport(t);
const quicTransport = makeQuicTransport(t, iceTransport, [ certificate ]);
assert_equals(quicTransport.transport, iceTransport,
'Expect transport to be the same as the one passed in the constructor.');
assert_equals(quicTransport.state, 'new', `Expect state to be 'new'.`);
assert_object_equals(quicTransport.getLocalParameters(),
{ role: 'auto', fingerprints: certificate.getFingerprints() },
'Expect local parameters to be initialized.');
assert_equals(quicTransport.getRemoteParameters(), null,
'Expect no remote parameters.');
assert_array_equals(quicTransport.getCertificates(), [ certificate ],
'Expect one certificate.');
assert_array_equals(quicTransport.getRemoteCertificates(), [],
'Expect no remote certificates.');
}, 'RTCQuicTransport initial properties are set.');
promise_test(async t => {
const [ firstCertificate, secondCertificate ] =
await Promise.all([ generateCertificate(), generateCertificate() ]);
const quicTransport =
makeQuicTransport(t, makeIceTransport(t),
[ firstCertificate, secondCertificate ]);
assert_array_equals(quicTransport.getCertificates(),
[ firstCertificate, secondCertificate ]);
}, 'getCertificates() returns the certificates passed in the constructor.');
promise_test(async t => {
const [ firstCertificate, secondCertificate ] =
await Promise.all([ generateCertificate(), generateCertificate() ]);
const quicTransport =
makeQuicTransport(t, makeIceTransport(t),
[ firstCertificate, secondCertificate ]);
assert_object_equals(quicTransport.getLocalParameters(), {
role: 'auto',
fingerprints:
[ firstCertificate.getFingerprints()[0],
secondCertificate.getFingerprints()[0] ],
});
assert_array_equals(quicTransport.getCertificates(),
[ firstCertificate, secondCertificate ]);
}, 'getLocalParameters() has fingerprints for all certificates passed in the ' +
'constructor.');
promise_test(async t => {
const expiredCertificate = await generateCertificate({ expires: 0 });
assert_throws(new TypeError(),
() => makeQuicTransport(t, makeIceTransport(t), [ expiredCertificate ]));
}, 'RTCQuicTransport constructor throws if passed an expired certificate.');
promise_test(async t => {
const certificate = await generateCertificate();
const iceTransport = makeIceTransport(t);
iceTransport.stop();
assert_throws('InvalidStateError',
() => makeQuicTransport(t, iceTransport, [ certificate ]));
}, 'RTCQuicTransport constructor throws if passed a closed RTCIceTransport.');
promise_test(async t => {
const certificate = await generateCertificate();
const iceTransport = makeIceTransport(t);
const firstQuicTransport =
makeQuicTransport(t, iceTransport, [ certificate ]);
assert_throws('InvalidStateError',
() => makeQuicTransport(t, iceTransport, [ certificate ]));
}, 'RTCQuicTransport constructor throws if passed an RTCIceTransport that ' +
'already has an active RTCQuicTransport.');
promise_test(async t => {
const quicTransport = await makeStandaloneQuicTransport(t);
quicTransport.stop();
assert_equals(quicTransport.state, 'closed');
}, `stop() changes state to 'closed'.`);
promise_test(async t => {
const quicTransport = await makeStandaloneQuicTransport(t);
quicTransport.transport.stop();
assert_equals(quicTransport.state, 'closed');
}, `RTCIceTransport.stop() changes RTCQuicTransport.state to 'closed'.`);
promise_test(async t => {
const quicTransport = await makeStandaloneQuicTransport(t);
quicTransport.start(quicTransport.getLocalParameters());
assert_equals(quicTransport.state, 'new');
}, 'start() with a non-started RTCIceTransport does not change state.');
promise_test(async t => {
const certificate = await generateCertificate();
const [ localIceTransport, remoteIceTransport ] =
makeAndGatherTwoIceTransports(t);
const quicTransport =
makeQuicTransport(t, localIceTransport, [ certificate ]);
quicTransport.start(quicTransport.getLocalParameters());
const iceTransportWatcher =
new EventWatcher(t, remoteIceTransport, 'icecandidate');
await iceTransportWatcher.wait_for('icecandidate');
localIceTransport.start(remoteIceTransport.getLocalParameters(),
'controlling');
assert_equals(quicTransport.state, 'connecting');
}, 'start() with a non-started RTCIceTransport later changes state to ' +
`'connecting' once the RTCIceTransport.start() is called.`);
promise_test(async t => {
const certificate = await generateCertificate();
const [ localIceTransport, remoteIceTransport ] =
makeAndGatherTwoIceTransports(t);
const quicTransport =
makeQuicTransport(t, localIceTransport, [ certificate ]);
const iceTransportWatcher =
new EventWatcher(t, remoteIceTransport, 'icecandidate');
await iceTransportWatcher.wait_for('icecandidate');
localIceTransport.start(remoteIceTransport.getLocalParameters());
quicTransport.start(quicTransport.getLocalParameters());
assert_equals(quicTransport.state, 'connecting');
}, `start() with a started RTCIceTransport changes state to 'connecting'.`);
promise_test(async t => {
const quicTransport = await makeStandaloneQuicTransport(t);
quicTransport.stop();
assert_throws('InvalidStateError',
() => quicTransport.start(quicTransport.getLocalParameters()));
}, 'start() throws if called after stop().');
promise_test(async t => {
const quicTransport = await makeStandaloneQuicTransport(t);
quicTransport.transport.stop();
assert_throws('InvalidStateError',
() => quicTransport.start(quicTransport.getLocalParameters()));
}, 'start() throws if called after the RTCIceTransport has stopped.');
promise_test(async t => {
const quicTransport = await makeStandaloneQuicTransport(t);
quicTransport.start(quicTransport.getLocalParameters());
assert_throws('InvalidStateError',
() => quicTransport.start(quicTransport.getLocalParameters()));
}, 'start() throws if called twice.');
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeAndStartTwoQuicTransports(t);
const localWatcher = new EventWatcher(t, localQuicTransport, 'statechange');
const remoteWatcher = new EventWatcher(t, remoteQuicTransport, 'statechange');
await Promise.all([
localWatcher.wait_for('statechange').then(() => {
assert_equals(localQuicTransport.state, 'connected');
}),
remoteWatcher.wait_for('statechange').then(() => {
assert_equals(remoteQuicTransport.state, 'connected');
}),
]);
}, 'Two RTCQuicTransports connect to each other.');
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeTwoConnectedQuicTransports(t);
localQuicTransport.stop();
const remoteWatcher = new EventWatcher(t, remoteQuicTransport, 'statechange');
await remoteWatcher.wait_for('statechange');
assert_equals(remoteQuicTransport.state, 'closed');
}, `stop() fires a statechange event to 'closed' on the remote transport`);
</script>