blob: a1bdbf5af5bf45de7d61b1e065c7edb0e316d212 [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"
19#include "media/base/fakevideocapturer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "p2p/base/fakeportallocator.h"
21#include "pc/peerconnectionfactory.h"
henrika919dc2e2017-10-12 14:24:55 +020022#include "pc/test/fakeaudiocapturemodule.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "rtc_base/gunit.h"
Patrik Höglund563934e2017-09-15 09:04:28 +020024
ossu7bb87ee2017-01-23 04:56:25 -080025#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "pc/test/androidtestinitializer.h"
ossu7bb87ee2017-01-23 04:56:25 -080027#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "pc/test/fakertccertificategenerator.h"
29#include "pc/test/fakevideotrackrenderer.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +000031using webrtc::DataChannelInterface;
Henrik Boström5e56c592015-08-11 10:33:13 +020032using webrtc::FakeVideoTrackRenderer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033using webrtc::MediaStreamInterface;
34using webrtc::PeerConnectionFactoryInterface;
35using webrtc::PeerConnectionInterface;
36using webrtc::PeerConnectionObserver;
perkja3ede6c2016-03-08 01:27:48 +010037using webrtc::VideoTrackSourceInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038using webrtc::VideoTrackInterface;
39
40namespace {
41
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042static const char kStunIceServer[] = "stun:stun.l.google.com:19302";
43static const char kTurnIceServer[] = "turn:test%40hello.com@test.com:1234";
44static const char kTurnIceServerWithTransport[] =
45 "turn:test@hello.com?transport=tcp";
46static const char kSecureTurnIceServer[] =
47 "turns:test@hello.com?transport=tcp";
wu@webrtc.org78187522013-10-07 23:32:02 +000048static const char kSecureTurnIceServerWithoutTransportParam[] =
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +000049 "turns:test_no_transport@hello.com:443";
50static const char kSecureTurnIceServerWithoutTransportAndPortParam[] =
wu@webrtc.org78187522013-10-07 23:32:02 +000051 "turns:test_no_transport@hello.com";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052static const char kTurnIceServerWithNoUsernameInUri[] =
53 "turn:test.com:1234";
54static 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 {}
81 void OnIceCandidate(
82 const webrtc::IceCandidateInterface* candidate) override {}
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(
henrika919dc2e2017-10-12 14:24:55 +020096 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +020097 FakeAudioCaptureModule::Create(),
98 webrtc::CreateBuiltinAudioEncoderFactory(),
99 webrtc::CreateBuiltinAudioDecoderFactory(), nullptr, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
101 ASSERT_TRUE(factory_.get() != NULL);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800102 port_allocator_.reset(
103 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
104 raw_port_allocator_ = port_allocator_.get();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105 }
106
107 protected:
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800108 void VerifyStunServers(cricket::ServerAddresses stun_servers) {
109 EXPECT_EQ(stun_servers, raw_port_allocator_->stun_servers());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110 }
111
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800112 void VerifyTurnServers(std::vector<cricket::RelayServerConfig> turn_servers) {
113 EXPECT_EQ(turn_servers.size(), raw_port_allocator_->turn_servers().size());
114 for (size_t i = 0; i < turn_servers.size(); ++i) {
115 ASSERT_EQ(1u, turn_servers[i].ports.size());
116 EXPECT_EQ(1u, raw_port_allocator_->turn_servers()[i].ports.size());
117 EXPECT_EQ(
118 turn_servers[i].ports[0].address.ToString(),
119 raw_port_allocator_->turn_servers()[i].ports[0].address.ToString());
120 EXPECT_EQ(turn_servers[i].ports[0].proto,
121 raw_port_allocator_->turn_servers()[i].ports[0].proto);
122 EXPECT_EQ(turn_servers[i].credentials.username,
123 raw_port_allocator_->turn_servers()[i].credentials.username);
124 EXPECT_EQ(turn_servers[i].credentials.password,
125 raw_port_allocator_->turn_servers()[i].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126 }
127 }
128
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000129 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130 NullPeerConnectionObserver observer_;
kwibergd1fe2812016-04-27 06:47:29 -0700131 std::unique_ptr<cricket::FakePortAllocator> port_allocator_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800132 // Since the PC owns the port allocator after it's been initialized,
133 // this should only be used when known to be safe.
134 cricket::FakePortAllocator* raw_port_allocator_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135};
136
137// Verify creation of PeerConnection using internal ADM, video factory and
138// internal libjingle threads.
henrika919dc2e2017-10-12 14:24:55 +0200139// TODO(henrika): disabling this test since relying on real audio can result in
140// flaky tests and focus on details that are out of scope for you might expect
141// for a PeerConnectionFactory unit test.
142// See https://bugs.chromium.org/p/webrtc/issues/detail?id=7806 for details.
143TEST(PeerConnectionFactoryTestInternal, DISABLED_CreatePCUsingInternalModules) {
phoglund37ebcf02016-01-08 05:04:57 -0800144#ifdef WEBRTC_ANDROID
145 webrtc::InitializeAndroidObjects();
146#endif
147
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000148 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
Karl Wiberg1b0eae32017-10-17 14:48:54 +0200149 webrtc::CreatePeerConnectionFactory(
150 webrtc::CreateBuiltinAudioEncoderFactory(),
151 webrtc::CreateBuiltinAudioDecoderFactory()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152
153 NullPeerConnectionObserver observer;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800154 webrtc::PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155
Henrik Boströmd79599d2016-06-01 13:58:50 +0200156 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
157 new FakeRTCCertificateGenerator());
158 rtc::scoped_refptr<PeerConnectionInterface> pc(factory->CreatePeerConnection(
159 config, nullptr, nullptr, std::move(cert_generator), &observer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000160
Henrik Boström5e56c592015-08-11 10:33:13 +0200161 EXPECT_TRUE(pc.get() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162}
163
164// This test verifies creation of PeerConnection with valid STUN and TURN
165// configuration. Also verifies the URL's parsed correctly as expected.
166TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServers) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000167 PeerConnectionInterface::RTCConfiguration config;
168 webrtc::PeerConnectionInterface::IceServer ice_server;
169 ice_server.uri = kStunIceServer;
170 config.servers.push_back(ice_server);
171 ice_server.uri = kTurnIceServer;
172 ice_server.password = kTurnPassword;
173 config.servers.push_back(ice_server);
174 ice_server.uri = kTurnIceServerWithTransport;
175 ice_server.password = kTurnPassword;
176 config.servers.push_back(ice_server);
Henrik Boströmd79599d2016-06-01 13:58:50 +0200177 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
178 new FakeRTCCertificateGenerator());
179 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
180 config, nullptr, std::move(port_allocator_), std::move(cert_generator),
181 &observer_));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800182 ASSERT_TRUE(pc.get() != NULL);
183 cricket::ServerAddresses stun_servers;
184 rtc::SocketAddress stun1("stun.l.google.com", 19302);
185 stun_servers.insert(stun1);
186 VerifyStunServers(stun_servers);
187 std::vector<cricket::RelayServerConfig> turn_servers;
188 cricket::RelayServerConfig turn1("test.com", 1234, "test@hello.com",
hnsl277b2502016-12-13 05:17:23 -0800189 kTurnPassword, cricket::PROTO_UDP);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800190 turn_servers.push_back(turn1);
191 cricket::RelayServerConfig turn2("hello.com", kDefaultStunPort, "test",
hnsl277b2502016-12-13 05:17:23 -0800192 kTurnPassword, cricket::PROTO_TCP);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800193 turn_servers.push_back(turn2);
194 VerifyTurnServers(turn_servers);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000195}
196
197// This test verifies creation of PeerConnection with valid STUN and TURN
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200198// configuration. Also verifies the list of URL's parsed correctly as expected.
199TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersUrls) {
200 PeerConnectionInterface::RTCConfiguration config;
201 webrtc::PeerConnectionInterface::IceServer ice_server;
202 ice_server.urls.push_back(kStunIceServer);
203 ice_server.urls.push_back(kTurnIceServer);
204 ice_server.urls.push_back(kTurnIceServerWithTransport);
205 ice_server.password = kTurnPassword;
206 config.servers.push_back(ice_server);
Henrik Boströmd79599d2016-06-01 13:58:50 +0200207 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
208 new FakeRTCCertificateGenerator());
209 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
210 config, nullptr, std::move(port_allocator_), std::move(cert_generator),
211 &observer_));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800212 ASSERT_TRUE(pc.get() != NULL);
213 cricket::ServerAddresses stun_servers;
214 rtc::SocketAddress stun1("stun.l.google.com", 19302);
215 stun_servers.insert(stun1);
216 VerifyStunServers(stun_servers);
217 std::vector<cricket::RelayServerConfig> turn_servers;
218 cricket::RelayServerConfig turn1("test.com", 1234, "test@hello.com",
hnsl277b2502016-12-13 05:17:23 -0800219 kTurnPassword, cricket::PROTO_UDP);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800220 turn_servers.push_back(turn1);
221 cricket::RelayServerConfig turn2("hello.com", kDefaultStunPort, "test",
hnsl277b2502016-12-13 05:17:23 -0800222 kTurnPassword, cricket::PROTO_TCP);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800223 turn_servers.push_back(turn2);
224 VerifyTurnServers(turn_servers);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225}
226
227TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000228 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 webrtc::PeerConnectionInterface::IceServer ice_server;
230 ice_server.uri = kStunIceServer;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000231 config.servers.push_back(ice_server);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 ice_server.uri = kTurnIceServerWithNoUsernameInUri;
233 ice_server.username = kTurnUsername;
234 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000235 config.servers.push_back(ice_server);
Henrik Boströmd79599d2016-06-01 13:58:50 +0200236 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
237 new FakeRTCCertificateGenerator());
238 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
239 config, nullptr, std::move(port_allocator_), std::move(cert_generator),
240 &observer_));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800241 ASSERT_TRUE(pc.get() != NULL);
242 std::vector<cricket::RelayServerConfig> turn_servers;
243 cricket::RelayServerConfig turn("test.com", 1234, kTurnUsername,
hnsl277b2502016-12-13 05:17:23 -0800244 kTurnPassword, cricket::PROTO_UDP);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800245 turn_servers.push_back(turn);
246 VerifyTurnServers(turn_servers);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247}
248
249// This test verifies the PeerConnection created properly with TURN url which
250// has transport parameter in it.
251TEST_F(PeerConnectionFactoryTest, CreatePCUsingTurnUrlWithTransportParam) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000252 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 webrtc::PeerConnectionInterface::IceServer ice_server;
254 ice_server.uri = kTurnIceServerWithTransport;
255 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000256 config.servers.push_back(ice_server);
Henrik Boströmd79599d2016-06-01 13:58:50 +0200257 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
258 new FakeRTCCertificateGenerator());
259 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
260 config, nullptr, std::move(port_allocator_), std::move(cert_generator),
261 &observer_));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800262 ASSERT_TRUE(pc.get() != NULL);
263 std::vector<cricket::RelayServerConfig> turn_servers;
264 cricket::RelayServerConfig turn("hello.com", kDefaultStunPort, "test",
hnsl277b2502016-12-13 05:17:23 -0800265 kTurnPassword, cricket::PROTO_TCP);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800266 turn_servers.push_back(turn);
267 VerifyTurnServers(turn_servers);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268}
269
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000271 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 webrtc::PeerConnectionInterface::IceServer ice_server;
273 ice_server.uri = kSecureTurnIceServer;
274 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000275 config.servers.push_back(ice_server);
wu@webrtc.org78187522013-10-07 23:32:02 +0000276 ice_server.uri = kSecureTurnIceServerWithoutTransportParam;
277 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000278 config.servers.push_back(ice_server);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000279 ice_server.uri = kSecureTurnIceServerWithoutTransportAndPortParam;
280 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000281 config.servers.push_back(ice_server);
Henrik Boströmd79599d2016-06-01 13:58:50 +0200282 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
283 new FakeRTCCertificateGenerator());
284 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
285 config, nullptr, std::move(port_allocator_), std::move(cert_generator),
286 &observer_));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800287 ASSERT_TRUE(pc.get() != NULL);
288 std::vector<cricket::RelayServerConfig> turn_servers;
289 cricket::RelayServerConfig turn1("hello.com", kDefaultStunTlsPort, "test",
hnsl277b2502016-12-13 05:17:23 -0800290 kTurnPassword, cricket::PROTO_TLS);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800291 turn_servers.push_back(turn1);
wu@webrtc.org78187522013-10-07 23:32:02 +0000292 // TURNS with transport param should be default to tcp.
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800293 cricket::RelayServerConfig turn2("hello.com", 443, "test_no_transport",
hnsl277b2502016-12-13 05:17:23 -0800294 kTurnPassword, cricket::PROTO_TLS);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800295 turn_servers.push_back(turn2);
296 cricket::RelayServerConfig turn3("hello.com", kDefaultStunTlsPort,
297 "test_no_transport", kTurnPassword,
hnsl277b2502016-12-13 05:17:23 -0800298 cricket::PROTO_TLS);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800299 turn_servers.push_back(turn3);
300 VerifyTurnServers(turn_servers);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301}
302
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000303TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000304 PeerConnectionInterface::RTCConfiguration config;
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000305 webrtc::PeerConnectionInterface::IceServer ice_server;
306 ice_server.uri = kStunIceServerWithIPv4Address;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000307 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000308 ice_server.uri = kStunIceServerWithIPv4AddressWithoutPort;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000309 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000310 ice_server.uri = kStunIceServerWithIPv6Address;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000311 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000312 ice_server.uri = kStunIceServerWithIPv6AddressWithoutPort;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000313 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000314 ice_server.uri = kTurnIceServerWithIPv6Address;
315 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000316 config.servers.push_back(ice_server);
Henrik Boströmd79599d2016-06-01 13:58:50 +0200317 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
318 new FakeRTCCertificateGenerator());
319 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
320 config, nullptr, std::move(port_allocator_), std::move(cert_generator),
321 &observer_));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800322 ASSERT_TRUE(pc.get() != NULL);
323 cricket::ServerAddresses stun_servers;
324 rtc::SocketAddress stun1("1.2.3.4", 1234);
325 stun_servers.insert(stun1);
326 rtc::SocketAddress stun2("1.2.3.4", 3478);
327 stun_servers.insert(stun2); // Default port
328 rtc::SocketAddress stun3("2401:fa00:4::", 1234);
329 stun_servers.insert(stun3);
330 rtc::SocketAddress stun4("2401:fa00:4::", 3478);
331 stun_servers.insert(stun4); // Default port
332 VerifyStunServers(stun_servers);
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000333
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800334 std::vector<cricket::RelayServerConfig> turn_servers;
335 cricket::RelayServerConfig turn1("2401:fa00:4::", 1234, "test", kTurnPassword,
hnsl277b2502016-12-13 05:17:23 -0800336 cricket::PROTO_UDP);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800337 turn_servers.push_back(turn1);
338 VerifyTurnServers(turn_servers);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000339}
340
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341// This test verifies the captured stream is rendered locally using a
342// local video track.
343TEST_F(PeerConnectionFactoryTest, LocalRendering) {
344 cricket::FakeVideoCapturer* capturer = new cricket::FakeVideoCapturer();
deadbeef112b2e92017-02-10 20:13:37 -0800345 // The source takes ownership of |capturer|, but we keep a raw pointer to
346 // inject fake frames.
perkja3ede6c2016-03-08 01:27:48 +0100347 rtc::scoped_refptr<VideoTrackSourceInterface> source(
deadbeef112b2e92017-02-10 20:13:37 -0800348 factory_->CreateVideoSource(
349 std::unique_ptr<cricket::VideoCapturer>(capturer), NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 ASSERT_TRUE(source.get() != NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000351 rtc::scoped_refptr<VideoTrackInterface> track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 factory_->CreateVideoTrack("testlabel", source));
353 ASSERT_TRUE(track.get() != NULL);
354 FakeVideoTrackRenderer local_renderer(track);
355
356 EXPECT_EQ(0, local_renderer.num_rendered_frames());
357 EXPECT_TRUE(capturer->CaptureFrame());
358 EXPECT_EQ(1, local_renderer.num_rendered_frames());
nisse81354f52016-01-19 00:23:24 -0800359 EXPECT_FALSE(local_renderer.black_frame());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360
361 track->set_enabled(false);
362 EXPECT_TRUE(capturer->CaptureFrame());
nisse81354f52016-01-19 00:23:24 -0800363 EXPECT_EQ(2, local_renderer.num_rendered_frames());
364 EXPECT_TRUE(local_renderer.black_frame());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000365
366 track->set_enabled(true);
367 EXPECT_TRUE(capturer->CaptureFrame());
nisse81354f52016-01-19 00:23:24 -0800368 EXPECT_EQ(3, local_renderer.num_rendered_frames());
369 EXPECT_FALSE(local_renderer.black_frame());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370}