blob: 9b1854e5ac3104152b2273a28b0e316e0ef9b859 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kwibergd1fe2812016-04-27 06:47:29 -070011#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080013#include <utility>
Steve Anton36b29d12017-10-30 09:57:42 -070014#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015
Karl Wiberg1b0eae32017-10-17 14:48:54 +020016#include "api/audio_codecs/builtin_audio_decoder_factory.h"
17#include "api/audio_codecs/builtin_audio_encoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/mediastreaminterface.h"
Anders Carlsson67537952018-05-03 11:28:29 +020019#include "api/video_codecs/builtin_video_decoder_factory.h"
20#include "api/video_codecs/builtin_video_encoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "media/base/fakevideocapturer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "p2p/base/fakeportallocator.h"
23#include "pc/peerconnectionfactory.h"
henrika919dc2e2017-10-12 14:24:55 +020024#include "pc/test/fakeaudiocapturemodule.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "rtc_base/gunit.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020026
ossu7bb87ee2017-01-23 04:56:25 -080027#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "pc/test/androidtestinitializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080029#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "pc/test/fakertccertificategenerator.h"
31#include "pc/test/fakevideotrackrenderer.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +000033using webrtc::DataChannelInterface;
Henrik Boström5e56c592015-08-11 10:33:13 +020034using webrtc::FakeVideoTrackRenderer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035using webrtc::MediaStreamInterface;
36using webrtc::PeerConnectionFactoryInterface;
37using webrtc::PeerConnectionInterface;
38using webrtc::PeerConnectionObserver;
perkja3ede6c2016-03-08 01:27:48 +010039using webrtc::VideoTrackSourceInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040using webrtc::VideoTrackInterface;
41
42namespace {
43
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044static const char kStunIceServer[] = "stun:stun.l.google.com:19302";
45static const char kTurnIceServer[] = "turn:test%40hello.com@test.com:1234";
46static const char kTurnIceServerWithTransport[] =
47 "turn:test@hello.com?transport=tcp";
Yves Gerey665174f2018-06-19 15:03:05 +020048static const char kSecureTurnIceServer[] = "turns:test@hello.com?transport=tcp";
wu@webrtc.org78187522013-10-07 23:32:02 +000049static const char kSecureTurnIceServerWithoutTransportParam[] =
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +000050 "turns:test_no_transport@hello.com:443";
51static const char kSecureTurnIceServerWithoutTransportAndPortParam[] =
wu@webrtc.org78187522013-10-07 23:32:02 +000052 "turns:test_no_transport@hello.com";
Yves Gerey665174f2018-06-19 15:03:05 +020053static const char kTurnIceServerWithNoUsernameInUri[] = "turn:test.com:1234";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054static const char kTurnPassword[] = "turnpassword";
wu@webrtc.org91053e72013-08-10 07:18:04 +000055static const int kDefaultStunPort = 3478;
56static const int kDefaultStunTlsPort = 5349;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057static const char kTurnUsername[] = "test";
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +000058static const char kStunIceServerWithIPv4Address[] = "stun:1.2.3.4:1234";
59static const char kStunIceServerWithIPv4AddressWithoutPort[] = "stun:1.2.3.4";
60static const char kStunIceServerWithIPv6Address[] = "stun:[2401:fa00:4::]:1234";
61static const char kStunIceServerWithIPv6AddressWithoutPort[] =
62 "stun:[2401:fa00:4::]";
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +000063static const char kTurnIceServerWithIPv6Address[] =
64 "turn:test@[2401:fa00:4::]:1234";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065
66class NullPeerConnectionObserver : public PeerConnectionObserver {
67 public:
Henrik Kjellander3fe372d2016-05-12 08:10:52 +020068 virtual ~NullPeerConnectionObserver() = default;
nisse63b14b72017-01-31 03:34:01 -080069 void OnSignalingChange(
70 PeerConnectionInterface::SignalingState new_state) override {}
71 void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override {}
72 void OnRemoveStream(
73 rtc::scoped_refptr<MediaStreamInterface> stream) override {}
74 void OnDataChannel(
75 rtc::scoped_refptr<DataChannelInterface> data_channel) override {}
76 void OnRenegotiationNeeded() override {}
77 void OnIceConnectionChange(
78 PeerConnectionInterface::IceConnectionState new_state) override {}
79 void OnIceGatheringChange(
80 PeerConnectionInterface::IceGatheringState new_state) override {}
Yves Gerey665174f2018-06-19 15:03:05 +020081 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
82 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083};
84
85} // namespace
86
87class PeerConnectionFactoryTest : public testing::Test {
88 void SetUp() {
phoglund37ebcf02016-01-08 05:04:57 -080089#ifdef WEBRTC_ANDROID
90 webrtc::InitializeAndroidObjects();
91#endif
henrika919dc2e2017-10-12 14:24:55 +020092 // Use fake audio device module since we're only testing the interface
93 // level, and using a real one could make tests flaky e.g. when run in
94 // parallel.
danilchape9021a32016-05-17 01:52:02 -070095 factory_ = webrtc::CreatePeerConnectionFactory(
Anders Carlsson67537952018-05-03 11:28:29 +020096 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
97 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
98 FakeAudioCaptureModule::Create()),
Karl Wiberg1b0eae32017-10-17 14:48:54 +020099 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +0200100 webrtc::CreateBuiltinAudioDecoderFactory(),
101 webrtc::CreateBuiltinVideoEncoderFactory(),
102 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
103 nullptr /* audio_processing */);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104
105 ASSERT_TRUE(factory_.get() != NULL);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800106 port_allocator_.reset(
107 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
108 raw_port_allocator_ = port_allocator_.get();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109 }
110
111 protected:
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800112 void VerifyStunServers(cricket::ServerAddresses stun_servers) {
113 EXPECT_EQ(stun_servers, raw_port_allocator_->stun_servers());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114 }
115
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800116 void VerifyTurnServers(std::vector<cricket::RelayServerConfig> turn_servers) {
117 EXPECT_EQ(turn_servers.size(), raw_port_allocator_->turn_servers().size());
118 for (size_t i = 0; i < turn_servers.size(); ++i) {
119 ASSERT_EQ(1u, turn_servers[i].ports.size());
120 EXPECT_EQ(1u, raw_port_allocator_->turn_servers()[i].ports.size());
121 EXPECT_EQ(
122 turn_servers[i].ports[0].address.ToString(),
123 raw_port_allocator_->turn_servers()[i].ports[0].address.ToString());
124 EXPECT_EQ(turn_servers[i].ports[0].proto,
125 raw_port_allocator_->turn_servers()[i].ports[0].proto);
126 EXPECT_EQ(turn_servers[i].credentials.username,
127 raw_port_allocator_->turn_servers()[i].credentials.username);
128 EXPECT_EQ(turn_servers[i].credentials.password,
129 raw_port_allocator_->turn_servers()[i].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130 }
131 }
132
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000133 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000134 NullPeerConnectionObserver observer_;
kwibergd1fe2812016-04-27 06:47:29 -0700135 std::unique_ptr<cricket::FakePortAllocator> port_allocator_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800136 // Since the PC owns the port allocator after it's been initialized,
137 // this should only be used when known to be safe.
138 cricket::FakePortAllocator* raw_port_allocator_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139};
140
141// Verify creation of PeerConnection using internal ADM, video factory and
142// internal libjingle threads.
henrika919dc2e2017-10-12 14:24:55 +0200143// TODO(henrika): disabling this test since relying on real audio can result in
144// flaky tests and focus on details that are out of scope for you might expect
145// for a PeerConnectionFactory unit test.
146// See https://bugs.chromium.org/p/webrtc/issues/detail?id=7806 for details.
147TEST(PeerConnectionFactoryTestInternal, DISABLED_CreatePCUsingInternalModules) {
phoglund37ebcf02016-01-08 05:04:57 -0800148#ifdef WEBRTC_ANDROID
149 webrtc::InitializeAndroidObjects();
150#endif
151
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000152 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
Karl Wiberg1b0eae32017-10-17 14:48:54 +0200153 webrtc::CreatePeerConnectionFactory(
Anders Carlsson67537952018-05-03 11:28:29 +0200154 nullptr /* network_thread */, nullptr /* worker_thread */,
155 nullptr /* signaling_thread */, nullptr /* default_adm */,
Karl Wiberg1b0eae32017-10-17 14:48:54 +0200156 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +0200157 webrtc::CreateBuiltinAudioDecoderFactory(),
158 webrtc::CreateBuiltinVideoEncoderFactory(),
159 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
160 nullptr /* audio_processing */));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161
162 NullPeerConnectionObserver observer;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800163 webrtc::PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164
Henrik Boströmd79599d2016-06-01 13:58:50 +0200165 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
166 new FakeRTCCertificateGenerator());
167 rtc::scoped_refptr<PeerConnectionInterface> pc(factory->CreatePeerConnection(
168 config, nullptr, nullptr, std::move(cert_generator), &observer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169
Henrik Boström5e56c592015-08-11 10:33:13 +0200170 EXPECT_TRUE(pc.get() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171}
172
173// This test verifies creation of PeerConnection with valid STUN and TURN
174// configuration. Also verifies the URL's parsed correctly as expected.
175TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServers) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000176 PeerConnectionInterface::RTCConfiguration config;
177 webrtc::PeerConnectionInterface::IceServer ice_server;
178 ice_server.uri = kStunIceServer;
179 config.servers.push_back(ice_server);
180 ice_server.uri = kTurnIceServer;
181 ice_server.password = kTurnPassword;
182 config.servers.push_back(ice_server);
183 ice_server.uri = kTurnIceServerWithTransport;
184 ice_server.password = kTurnPassword;
185 config.servers.push_back(ice_server);
Henrik Boströmd79599d2016-06-01 13:58:50 +0200186 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
187 new FakeRTCCertificateGenerator());
188 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
189 config, nullptr, std::move(port_allocator_), std::move(cert_generator),
190 &observer_));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800191 ASSERT_TRUE(pc.get() != NULL);
192 cricket::ServerAddresses stun_servers;
193 rtc::SocketAddress stun1("stun.l.google.com", 19302);
194 stun_servers.insert(stun1);
195 VerifyStunServers(stun_servers);
196 std::vector<cricket::RelayServerConfig> turn_servers;
197 cricket::RelayServerConfig turn1("test.com", 1234, "test@hello.com",
hnsl277b2502016-12-13 05:17:23 -0800198 kTurnPassword, cricket::PROTO_UDP);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800199 turn_servers.push_back(turn1);
200 cricket::RelayServerConfig turn2("hello.com", kDefaultStunPort, "test",
hnsl277b2502016-12-13 05:17:23 -0800201 kTurnPassword, cricket::PROTO_TCP);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800202 turn_servers.push_back(turn2);
203 VerifyTurnServers(turn_servers);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000204}
205
206// This test verifies creation of PeerConnection with valid STUN and TURN
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200207// configuration. Also verifies the list of URL's parsed correctly as expected.
208TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersUrls) {
209 PeerConnectionInterface::RTCConfiguration config;
210 webrtc::PeerConnectionInterface::IceServer ice_server;
211 ice_server.urls.push_back(kStunIceServer);
212 ice_server.urls.push_back(kTurnIceServer);
213 ice_server.urls.push_back(kTurnIceServerWithTransport);
214 ice_server.password = kTurnPassword;
215 config.servers.push_back(ice_server);
Henrik Boströmd79599d2016-06-01 13:58:50 +0200216 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
217 new FakeRTCCertificateGenerator());
218 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
219 config, nullptr, std::move(port_allocator_), std::move(cert_generator),
220 &observer_));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800221 ASSERT_TRUE(pc.get() != NULL);
222 cricket::ServerAddresses stun_servers;
223 rtc::SocketAddress stun1("stun.l.google.com", 19302);
224 stun_servers.insert(stun1);
225 VerifyStunServers(stun_servers);
226 std::vector<cricket::RelayServerConfig> turn_servers;
227 cricket::RelayServerConfig turn1("test.com", 1234, "test@hello.com",
hnsl277b2502016-12-13 05:17:23 -0800228 kTurnPassword, cricket::PROTO_UDP);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800229 turn_servers.push_back(turn1);
230 cricket::RelayServerConfig turn2("hello.com", kDefaultStunPort, "test",
hnsl277b2502016-12-13 05:17:23 -0800231 kTurnPassword, cricket::PROTO_TCP);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800232 turn_servers.push_back(turn2);
233 VerifyTurnServers(turn_servers);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234}
235
236TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000237 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 webrtc::PeerConnectionInterface::IceServer ice_server;
239 ice_server.uri = kStunIceServer;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000240 config.servers.push_back(ice_server);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 ice_server.uri = kTurnIceServerWithNoUsernameInUri;
242 ice_server.username = kTurnUsername;
243 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000244 config.servers.push_back(ice_server);
Henrik Boströmd79599d2016-06-01 13:58:50 +0200245 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
246 new FakeRTCCertificateGenerator());
247 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
248 config, nullptr, std::move(port_allocator_), std::move(cert_generator),
249 &observer_));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800250 ASSERT_TRUE(pc.get() != NULL);
251 std::vector<cricket::RelayServerConfig> turn_servers;
252 cricket::RelayServerConfig turn("test.com", 1234, kTurnUsername,
hnsl277b2502016-12-13 05:17:23 -0800253 kTurnPassword, cricket::PROTO_UDP);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800254 turn_servers.push_back(turn);
255 VerifyTurnServers(turn_servers);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256}
257
258// This test verifies the PeerConnection created properly with TURN url which
259// has transport parameter in it.
260TEST_F(PeerConnectionFactoryTest, CreatePCUsingTurnUrlWithTransportParam) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000261 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262 webrtc::PeerConnectionInterface::IceServer ice_server;
263 ice_server.uri = kTurnIceServerWithTransport;
264 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000265 config.servers.push_back(ice_server);
Henrik Boströmd79599d2016-06-01 13:58:50 +0200266 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
267 new FakeRTCCertificateGenerator());
268 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
269 config, nullptr, std::move(port_allocator_), std::move(cert_generator),
270 &observer_));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800271 ASSERT_TRUE(pc.get() != NULL);
272 std::vector<cricket::RelayServerConfig> turn_servers;
273 cricket::RelayServerConfig turn("hello.com", kDefaultStunPort, "test",
hnsl277b2502016-12-13 05:17:23 -0800274 kTurnPassword, cricket::PROTO_TCP);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800275 turn_servers.push_back(turn);
276 VerifyTurnServers(turn_servers);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277}
278
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000280 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281 webrtc::PeerConnectionInterface::IceServer ice_server;
282 ice_server.uri = kSecureTurnIceServer;
283 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000284 config.servers.push_back(ice_server);
wu@webrtc.org78187522013-10-07 23:32:02 +0000285 ice_server.uri = kSecureTurnIceServerWithoutTransportParam;
286 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000287 config.servers.push_back(ice_server);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000288 ice_server.uri = kSecureTurnIceServerWithoutTransportAndPortParam;
289 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000290 config.servers.push_back(ice_server);
Henrik Boströmd79599d2016-06-01 13:58:50 +0200291 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
292 new FakeRTCCertificateGenerator());
293 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
294 config, nullptr, std::move(port_allocator_), std::move(cert_generator),
295 &observer_));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800296 ASSERT_TRUE(pc.get() != NULL);
297 std::vector<cricket::RelayServerConfig> turn_servers;
298 cricket::RelayServerConfig turn1("hello.com", kDefaultStunTlsPort, "test",
hnsl277b2502016-12-13 05:17:23 -0800299 kTurnPassword, cricket::PROTO_TLS);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800300 turn_servers.push_back(turn1);
wu@webrtc.org78187522013-10-07 23:32:02 +0000301 // TURNS with transport param should be default to tcp.
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800302 cricket::RelayServerConfig turn2("hello.com", 443, "test_no_transport",
hnsl277b2502016-12-13 05:17:23 -0800303 kTurnPassword, cricket::PROTO_TLS);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800304 turn_servers.push_back(turn2);
305 cricket::RelayServerConfig turn3("hello.com", kDefaultStunTlsPort,
306 "test_no_transport", kTurnPassword,
hnsl277b2502016-12-13 05:17:23 -0800307 cricket::PROTO_TLS);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800308 turn_servers.push_back(turn3);
309 VerifyTurnServers(turn_servers);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310}
311
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000312TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000313 PeerConnectionInterface::RTCConfiguration config;
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000314 webrtc::PeerConnectionInterface::IceServer ice_server;
315 ice_server.uri = kStunIceServerWithIPv4Address;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000316 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000317 ice_server.uri = kStunIceServerWithIPv4AddressWithoutPort;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000318 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000319 ice_server.uri = kStunIceServerWithIPv6Address;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000320 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000321 ice_server.uri = kStunIceServerWithIPv6AddressWithoutPort;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000322 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000323 ice_server.uri = kTurnIceServerWithIPv6Address;
324 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000325 config.servers.push_back(ice_server);
Henrik Boströmd79599d2016-06-01 13:58:50 +0200326 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
327 new FakeRTCCertificateGenerator());
328 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
329 config, nullptr, std::move(port_allocator_), std::move(cert_generator),
330 &observer_));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800331 ASSERT_TRUE(pc.get() != NULL);
332 cricket::ServerAddresses stun_servers;
333 rtc::SocketAddress stun1("1.2.3.4", 1234);
334 stun_servers.insert(stun1);
335 rtc::SocketAddress stun2("1.2.3.4", 3478);
336 stun_servers.insert(stun2); // Default port
337 rtc::SocketAddress stun3("2401:fa00:4::", 1234);
338 stun_servers.insert(stun3);
339 rtc::SocketAddress stun4("2401:fa00:4::", 3478);
340 stun_servers.insert(stun4); // Default port
341 VerifyStunServers(stun_servers);
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000342
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800343 std::vector<cricket::RelayServerConfig> turn_servers;
344 cricket::RelayServerConfig turn1("2401:fa00:4::", 1234, "test", kTurnPassword,
hnsl277b2502016-12-13 05:17:23 -0800345 cricket::PROTO_UDP);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800346 turn_servers.push_back(turn1);
347 VerifyTurnServers(turn_servers);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000348}
349
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350// This test verifies the captured stream is rendered locally using a
351// local video track.
352TEST_F(PeerConnectionFactoryTest, LocalRendering) {
Tommi1829af62018-02-06 09:29:17 +0100353 cricket::FakeVideoCapturerWithTaskQueue* capturer =
354 new cricket::FakeVideoCapturerWithTaskQueue();
deadbeef112b2e92017-02-10 20:13:37 -0800355 // The source takes ownership of |capturer|, but we keep a raw pointer to
356 // inject fake frames.
perkja3ede6c2016-03-08 01:27:48 +0100357 rtc::scoped_refptr<VideoTrackSourceInterface> source(
deadbeef112b2e92017-02-10 20:13:37 -0800358 factory_->CreateVideoSource(
359 std::unique_ptr<cricket::VideoCapturer>(capturer), NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 ASSERT_TRUE(source.get() != NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000361 rtc::scoped_refptr<VideoTrackInterface> track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 factory_->CreateVideoTrack("testlabel", source));
363 ASSERT_TRUE(track.get() != NULL);
364 FakeVideoTrackRenderer local_renderer(track);
365
366 EXPECT_EQ(0, local_renderer.num_rendered_frames());
367 EXPECT_TRUE(capturer->CaptureFrame());
368 EXPECT_EQ(1, local_renderer.num_rendered_frames());
nisse81354f52016-01-19 00:23:24 -0800369 EXPECT_FALSE(local_renderer.black_frame());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370
371 track->set_enabled(false);
372 EXPECT_TRUE(capturer->CaptureFrame());
nisse81354f52016-01-19 00:23:24 -0800373 EXPECT_EQ(2, local_renderer.num_rendered_frames());
374 EXPECT_TRUE(local_renderer.black_frame());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375
376 track->set_enabled(true);
377 EXPECT_TRUE(capturer->CaptureFrame());
nisse81354f52016-01-19 00:23:24 -0800378 EXPECT_EQ(3, local_renderer.num_rendered_frames());
379 EXPECT_FALSE(local_renderer.black_frame());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380}