<!doctype html>
<title>Test RTCPeerConnection.prototype.addIceCandidate with TCP candidates</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="resources/RTCPeerConnection-helper.js"></script>
<script>
'use strict';
const sdp = `v=0
o=- 166855176514521964 2 IN IP4 127.0.0.1
s=-
t=0 0
a=msid-semantic:WMS *
m=audio 9 UDP/TLS/RTP/SAVPF 111
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:655Y
a=ice-pwd:somelongpwdwithenoughrandomness
a=fingerprint:sha-256 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
a=setup:actpass
a=mid:audio1
a=sendonly
a=rtcp-mux
a=rtcp-rsize
a=rtpmap:111 opus/48000/2
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=ssrc:1001 cname:some
`;
// This test is intended to exercise the code that blocks ports on
// the blocked port list. The difference between the three cases can
// only be observed by reading the logs, so the main point of the
// test is to ensure that the code does not cause a crash.
const kLowNumberedPort = 37;
const kBlockListPort = 2049;
const kNotBlockListPort = 8001;
for (const port of [kLowNumberedPort, kBlockListPort, kNotBlockListPort]) {
const candidate = 'a=candidate:2983561038 1 tcp 1518214911 127.0.0.1 ' +
port +
' typ host tcptype passive generation 0 ufrag 655Y network-id 1 network-cost 10';
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
await pc.setRemoteDescription({type: 'offer', sdp: sdp});
const answer = await pc.createAnswer();
await pc.setLocalDescription(answer);
await pc.addIceCandidate(new RTCIceCandidate({candidate: candidate,
sdpMid: 'audio1'}));
pc.onicestatechange = t.unreached_func();
await new Promise(resolve => t.step_timeout(resolve, 100));
}, 'TCP candidate aimed at port ' + port + ' ignored');
}
</script>