blob: f1d5353abd008a72b650a416cdf303ce3339dbce [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
fischman@webrtc.org33584f92013-07-25 16:43:30 +000019 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000021 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <string>
29
30#include "talk/app/webrtc/fakeportallocatorfactory.h"
31#include "talk/app/webrtc/mediastreaminterface.h"
32#include "talk/app/webrtc/peerconnectionfactory.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020033#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034#include "talk/app/webrtc/test/fakevideotrackrenderer.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000035#include "talk/app/webrtc/videosourceinterface.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036#include "talk/media/base/fakevideocapturer.h"
37#include "talk/media/webrtc/webrtccommon.h"
38#include "talk/media/webrtc/webrtcvoe.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000039#include "webrtc/base/gunit.h"
40#include "webrtc/base/scoped_ptr.h"
41#include "webrtc/base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +000043using webrtc::DataChannelInterface;
Henrik Boström5e56c592015-08-11 10:33:13 +020044using webrtc::DtlsIdentityStoreInterface;
45using webrtc::FakeVideoTrackRenderer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046using webrtc::MediaStreamInterface;
47using webrtc::PeerConnectionFactoryInterface;
48using webrtc::PeerConnectionInterface;
49using webrtc::PeerConnectionObserver;
50using webrtc::PortAllocatorFactoryInterface;
51using webrtc::VideoSourceInterface;
52using webrtc::VideoTrackInterface;
53
54namespace {
55
56typedef std::vector<PortAllocatorFactoryInterface::StunConfiguration>
57 StunConfigurations;
58typedef std::vector<PortAllocatorFactoryInterface::TurnConfiguration>
59 TurnConfigurations;
60
61static const char kStunIceServer[] = "stun:stun.l.google.com:19302";
62static const char kTurnIceServer[] = "turn:test%40hello.com@test.com:1234";
63static const char kTurnIceServerWithTransport[] =
64 "turn:test@hello.com?transport=tcp";
65static const char kSecureTurnIceServer[] =
66 "turns:test@hello.com?transport=tcp";
wu@webrtc.org78187522013-10-07 23:32:02 +000067static const char kSecureTurnIceServerWithoutTransportParam[] =
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +000068 "turns:test_no_transport@hello.com:443";
69static const char kSecureTurnIceServerWithoutTransportAndPortParam[] =
wu@webrtc.org78187522013-10-07 23:32:02 +000070 "turns:test_no_transport@hello.com";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071static const char kTurnIceServerWithNoUsernameInUri[] =
72 "turn:test.com:1234";
73static const char kTurnPassword[] = "turnpassword";
wu@webrtc.org91053e72013-08-10 07:18:04 +000074static const int kDefaultStunPort = 3478;
75static const int kDefaultStunTlsPort = 5349;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076static const char kTurnUsername[] = "test";
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +000077static const char kStunIceServerWithIPv4Address[] = "stun:1.2.3.4:1234";
78static const char kStunIceServerWithIPv4AddressWithoutPort[] = "stun:1.2.3.4";
79static const char kStunIceServerWithIPv6Address[] = "stun:[2401:fa00:4::]:1234";
80static const char kStunIceServerWithIPv6AddressWithoutPort[] =
81 "stun:[2401:fa00:4::]";
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +000082static const char kTurnIceServerWithIPv6Address[] =
83 "turn:test@[2401:fa00:4::]:1234";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084
85class NullPeerConnectionObserver : public PeerConnectionObserver {
86 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087 virtual void OnMessage(const std::string& msg) {}
88 virtual void OnSignalingMessage(const std::string& msg) {}
89 virtual void OnSignalingChange(
90 PeerConnectionInterface::SignalingState new_state) {}
91 virtual void OnAddStream(MediaStreamInterface* stream) {}
92 virtual void OnRemoveStream(MediaStreamInterface* stream) {}
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +000093 virtual void OnDataChannel(DataChannelInterface* data_channel) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094 virtual void OnRenegotiationNeeded() {}
95 virtual void OnIceConnectionChange(
96 PeerConnectionInterface::IceConnectionState new_state) {}
97 virtual void OnIceGatheringChange(
98 PeerConnectionInterface::IceGatheringState new_state) {}
99 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {}
100};
101
102} // namespace
103
104class PeerConnectionFactoryTest : public testing::Test {
105 void SetUp() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000106 factory_ = webrtc::CreatePeerConnectionFactory(rtc::Thread::Current(),
107 rtc::Thread::Current(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108 NULL,
109 NULL,
110 NULL);
111
112 ASSERT_TRUE(factory_.get() != NULL);
113 allocator_factory_ = webrtc::FakePortAllocatorFactory::Create();
114 }
115
116 protected:
117 void VerifyStunConfigurations(StunConfigurations stun_config) {
118 webrtc::FakePortAllocatorFactory* allocator =
119 static_cast<webrtc::FakePortAllocatorFactory*>(
120 allocator_factory_.get());
121 ASSERT_TRUE(allocator != NULL);
122 EXPECT_EQ(stun_config.size(), allocator->stun_configs().size());
123 for (size_t i = 0; i < stun_config.size(); ++i) {
124 EXPECT_EQ(stun_config[i].server.ToString(),
125 allocator->stun_configs()[i].server.ToString());
126 }
127 }
128
129 void VerifyTurnConfigurations(TurnConfigurations turn_config) {
130 webrtc::FakePortAllocatorFactory* allocator =
131 static_cast<webrtc::FakePortAllocatorFactory*>(
132 allocator_factory_.get());
133 ASSERT_TRUE(allocator != NULL);
134 EXPECT_EQ(turn_config.size(), allocator->turn_configs().size());
135 for (size_t i = 0; i < turn_config.size(); ++i) {
136 EXPECT_EQ(turn_config[i].server.ToString(),
137 allocator->turn_configs()[i].server.ToString());
138 EXPECT_EQ(turn_config[i].username, allocator->turn_configs()[i].username);
139 EXPECT_EQ(turn_config[i].password, allocator->turn_configs()[i].password);
140 EXPECT_EQ(turn_config[i].transport_type,
141 allocator->turn_configs()[i].transport_type);
142 }
143 }
144
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000145 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146 NullPeerConnectionObserver observer_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000147 rtc::scoped_refptr<PortAllocatorFactoryInterface> allocator_factory_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148};
149
150// Verify creation of PeerConnection using internal ADM, video factory and
151// internal libjingle threads.
152TEST(PeerConnectionFactoryTestInternal, CreatePCUsingInternalModules) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000153 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154 webrtc::CreatePeerConnectionFactory());
155
156 NullPeerConnectionObserver observer;
157 webrtc::PeerConnectionInterface::IceServers servers;
158
Henrik Boström5e56c592015-08-11 10:33:13 +0200159 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
160 new FakeDtlsIdentityStore());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000161 rtc::scoped_refptr<PeerConnectionInterface> pc(
jiayl@webrtc.orgd83f4ef2015-03-13 21:26:12 +0000162 factory->CreatePeerConnection(
Henrik Boström5e56c592015-08-11 10:33:13 +0200163 servers, nullptr, nullptr, dtls_identity_store.Pass(), &observer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164
Henrik Boström5e56c592015-08-11 10:33:13 +0200165 EXPECT_TRUE(pc.get() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166}
167
168// This test verifies creation of PeerConnection with valid STUN and TURN
169// configuration. Also verifies the URL's parsed correctly as expected.
170TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServers) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000171 PeerConnectionInterface::RTCConfiguration config;
172 webrtc::PeerConnectionInterface::IceServer ice_server;
173 ice_server.uri = kStunIceServer;
174 config.servers.push_back(ice_server);
175 ice_server.uri = kTurnIceServer;
176 ice_server.password = kTurnPassword;
177 config.servers.push_back(ice_server);
178 ice_server.uri = kTurnIceServerWithTransport;
179 ice_server.password = kTurnPassword;
180 config.servers.push_back(ice_server);
Henrik Boström5e56c592015-08-11 10:33:13 +0200181 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
182 new FakeDtlsIdentityStore());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000183 rtc::scoped_refptr<PeerConnectionInterface> pc(
Henrik Boström5e56c592015-08-11 10:33:13 +0200184 factory_->CreatePeerConnection(config, nullptr,
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000185 allocator_factory_.get(),
Henrik Boström5e56c592015-08-11 10:33:13 +0200186 dtls_identity_store.Pass(),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000187 &observer_));
188 EXPECT_TRUE(pc.get() != NULL);
189 StunConfigurations stun_configs;
190 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1(
191 "stun.l.google.com", 19302);
192 stun_configs.push_back(stun1);
193 VerifyStunConfigurations(stun_configs);
194 TurnConfigurations turn_configs;
195 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1(
196 "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false);
197 turn_configs.push_back(turn1);
198 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2(
199 "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false);
200 turn_configs.push_back(turn2);
201 VerifyTurnConfigurations(turn_configs);
202}
203
204// This test verifies creation of PeerConnection with valid STUN and TURN
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200205// configuration. Also verifies the list of URL's parsed correctly as expected.
206TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersUrls) {
207 PeerConnectionInterface::RTCConfiguration config;
208 webrtc::PeerConnectionInterface::IceServer ice_server;
209 ice_server.urls.push_back(kStunIceServer);
210 ice_server.urls.push_back(kTurnIceServer);
211 ice_server.urls.push_back(kTurnIceServerWithTransport);
212 ice_server.password = kTurnPassword;
213 config.servers.push_back(ice_server);
Henrik Boström5e56c592015-08-11 10:33:13 +0200214 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
215 new FakeDtlsIdentityStore());
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200216 rtc::scoped_refptr<PeerConnectionInterface> pc(
Henrik Boström5e56c592015-08-11 10:33:13 +0200217 factory_->CreatePeerConnection(config, nullptr,
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200218 allocator_factory_.get(),
Henrik Boström5e56c592015-08-11 10:33:13 +0200219 dtls_identity_store.Pass(),
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200220 &observer_));
221 EXPECT_TRUE(pc.get() != NULL);
222 StunConfigurations stun_configs;
223 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1(
224 "stun.l.google.com", 19302);
225 stun_configs.push_back(stun1);
226 VerifyStunConfigurations(stun_configs);
227 TurnConfigurations turn_configs;
228 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1(
229 "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false);
230 turn_configs.push_back(turn1);
231 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2(
232 "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false);
233 turn_configs.push_back(turn2);
234 VerifyTurnConfigurations(turn_configs);
235}
236
237// This test verifies creation of PeerConnection with valid STUN and TURN
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000238// configuration. Also verifies the URL's parsed correctly as expected.
239// This version doesn't use RTCConfiguration.
240// TODO(mallinath) - Remove this method after clients start using RTCConfig.
241TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersOldSignature) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 webrtc::PeerConnectionInterface::IceServers ice_servers;
243 webrtc::PeerConnectionInterface::IceServer ice_server;
244 ice_server.uri = kStunIceServer;
245 ice_servers.push_back(ice_server);
246 ice_server.uri = kTurnIceServer;
247 ice_server.password = kTurnPassword;
248 ice_servers.push_back(ice_server);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000249 ice_server.uri = kTurnIceServerWithTransport;
250 ice_server.password = kTurnPassword;
251 ice_servers.push_back(ice_server);
Henrik Boström5e56c592015-08-11 10:33:13 +0200252 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
253 new FakeDtlsIdentityStore());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000254 rtc::scoped_refptr<PeerConnectionInterface> pc(
Henrik Boström5e56c592015-08-11 10:33:13 +0200255 factory_->CreatePeerConnection(ice_servers, nullptr,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 allocator_factory_.get(),
Henrik Boström5e56c592015-08-11 10:33:13 +0200257 dtls_identity_store.Pass(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 &observer_));
259 EXPECT_TRUE(pc.get() != NULL);
260 StunConfigurations stun_configs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1(
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000262 "stun.l.google.com", 19302);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263 stun_configs.push_back(stun1);
264 VerifyStunConfigurations(stun_configs);
265 TurnConfigurations turn_configs;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000266 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1(
wu@webrtc.org91053e72013-08-10 07:18:04 +0000267 "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000268 turn_configs.push_back(turn1);
269 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2(
wu@webrtc.org91053e72013-08-10 07:18:04 +0000270 "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000271 turn_configs.push_back(turn2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 VerifyTurnConfigurations(turn_configs);
273}
274
275TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000276 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 webrtc::PeerConnectionInterface::IceServer ice_server;
278 ice_server.uri = kStunIceServer;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000279 config.servers.push_back(ice_server);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280 ice_server.uri = kTurnIceServerWithNoUsernameInUri;
281 ice_server.username = kTurnUsername;
282 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000283 config.servers.push_back(ice_server);
Henrik Boström5e56c592015-08-11 10:33:13 +0200284 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
285 new FakeDtlsIdentityStore());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000286 rtc::scoped_refptr<PeerConnectionInterface> pc(
Henrik Boström5e56c592015-08-11 10:33:13 +0200287 factory_->CreatePeerConnection(config, nullptr,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288 allocator_factory_.get(),
Henrik Boström5e56c592015-08-11 10:33:13 +0200289 dtls_identity_store.Pass(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290 &observer_));
291 EXPECT_TRUE(pc.get() != NULL);
292 TurnConfigurations turn_configs;
293 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn(
wu@webrtc.org91053e72013-08-10 07:18:04 +0000294 "test.com", 1234, kTurnUsername, kTurnPassword, "udp", false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295 turn_configs.push_back(turn);
296 VerifyTurnConfigurations(turn_configs);
297}
298
299// This test verifies the PeerConnection created properly with TURN url which
300// has transport parameter in it.
301TEST_F(PeerConnectionFactoryTest, CreatePCUsingTurnUrlWithTransportParam) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000302 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303 webrtc::PeerConnectionInterface::IceServer ice_server;
304 ice_server.uri = kTurnIceServerWithTransport;
305 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000306 config.servers.push_back(ice_server);
Henrik Boström5e56c592015-08-11 10:33:13 +0200307 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
308 new FakeDtlsIdentityStore());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000309 rtc::scoped_refptr<PeerConnectionInterface> pc(
Henrik Boström5e56c592015-08-11 10:33:13 +0200310 factory_->CreatePeerConnection(config, nullptr,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 allocator_factory_.get(),
Henrik Boström5e56c592015-08-11 10:33:13 +0200312 dtls_identity_store.Pass(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 &observer_));
314 EXPECT_TRUE(pc.get() != NULL);
315 TurnConfigurations turn_configs;
316 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn(
wu@webrtc.org91053e72013-08-10 07:18:04 +0000317 "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318 turn_configs.push_back(turn);
319 VerifyTurnConfigurations(turn_configs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320}
321
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000323 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 webrtc::PeerConnectionInterface::IceServer ice_server;
325 ice_server.uri = kSecureTurnIceServer;
326 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000327 config.servers.push_back(ice_server);
wu@webrtc.org78187522013-10-07 23:32:02 +0000328 ice_server.uri = kSecureTurnIceServerWithoutTransportParam;
329 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000330 config.servers.push_back(ice_server);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000331 ice_server.uri = kSecureTurnIceServerWithoutTransportAndPortParam;
332 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000333 config.servers.push_back(ice_server);
Henrik Boström5e56c592015-08-11 10:33:13 +0200334 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
335 new FakeDtlsIdentityStore());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000336 rtc::scoped_refptr<PeerConnectionInterface> pc(
Henrik Boström5e56c592015-08-11 10:33:13 +0200337 factory_->CreatePeerConnection(config, nullptr,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 allocator_factory_.get(),
Henrik Boström5e56c592015-08-11 10:33:13 +0200339 dtls_identity_store.Pass(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340 &observer_));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000341 EXPECT_TRUE(pc.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 TurnConfigurations turn_configs;
wu@webrtc.org78187522013-10-07 23:32:02 +0000343 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1(
wu@webrtc.org91053e72013-08-10 07:18:04 +0000344 "hello.com", kDefaultStunTlsPort, "test", kTurnPassword, "tcp", true);
wu@webrtc.org78187522013-10-07 23:32:02 +0000345 turn_configs.push_back(turn1);
346 // TURNS with transport param should be default to tcp.
347 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2(
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000348 "hello.com", 443, "test_no_transport", kTurnPassword, "tcp", true);
349 turn_configs.push_back(turn2);
350 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn3(
wu@webrtc.org78187522013-10-07 23:32:02 +0000351 "hello.com", kDefaultStunTlsPort, "test_no_transport",
352 kTurnPassword, "tcp", true);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000353 turn_configs.push_back(turn3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 VerifyTurnConfigurations(turn_configs);
355}
356
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000357TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000358 PeerConnectionInterface::RTCConfiguration config;
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000359 webrtc::PeerConnectionInterface::IceServer ice_server;
360 ice_server.uri = kStunIceServerWithIPv4Address;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000361 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000362 ice_server.uri = kStunIceServerWithIPv4AddressWithoutPort;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000363 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000364 ice_server.uri = kStunIceServerWithIPv6Address;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000365 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000366 ice_server.uri = kStunIceServerWithIPv6AddressWithoutPort;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000367 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000368 ice_server.uri = kTurnIceServerWithIPv6Address;
369 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000370 config.servers.push_back(ice_server);
Henrik Boström5e56c592015-08-11 10:33:13 +0200371 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
372 new FakeDtlsIdentityStore());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000373 rtc::scoped_refptr<PeerConnectionInterface> pc(
Henrik Boström5e56c592015-08-11 10:33:13 +0200374 factory_->CreatePeerConnection(config, nullptr,
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000375 allocator_factory_.get(),
Henrik Boström5e56c592015-08-11 10:33:13 +0200376 dtls_identity_store.Pass(),
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000377 &observer_));
378 EXPECT_TRUE(pc.get() != NULL);
379 StunConfigurations stun_configs;
380 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1(
381 "1.2.3.4", 1234);
382 stun_configs.push_back(stun1);
383 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun2(
384 "1.2.3.4", 3478);
385 stun_configs.push_back(stun2); // Default port
386 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun3(
387 "2401:fa00:4::", 1234);
388 stun_configs.push_back(stun3);
389 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun4(
390 "2401:fa00:4::", 3478);
391 stun_configs.push_back(stun4); // Default port
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000392 VerifyStunConfigurations(stun_configs);
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000393
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000394 TurnConfigurations turn_configs;
395 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1(
396 "2401:fa00:4::", 1234, "test", kTurnPassword, "udp", false);
397 turn_configs.push_back(turn1);
398 VerifyTurnConfigurations(turn_configs);
399}
400
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000401// This test verifies the captured stream is rendered locally using a
402// local video track.
403TEST_F(PeerConnectionFactoryTest, LocalRendering) {
404 cricket::FakeVideoCapturer* capturer = new cricket::FakeVideoCapturer();
405 // The source take ownership of |capturer|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000406 rtc::scoped_refptr<VideoSourceInterface> source(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407 factory_->CreateVideoSource(capturer, NULL));
408 ASSERT_TRUE(source.get() != NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000409 rtc::scoped_refptr<VideoTrackInterface> track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410 factory_->CreateVideoTrack("testlabel", source));
411 ASSERT_TRUE(track.get() != NULL);
412 FakeVideoTrackRenderer local_renderer(track);
413
414 EXPECT_EQ(0, local_renderer.num_rendered_frames());
415 EXPECT_TRUE(capturer->CaptureFrame());
416 EXPECT_EQ(1, local_renderer.num_rendered_frames());
417
418 track->set_enabled(false);
419 EXPECT_TRUE(capturer->CaptureFrame());
420 EXPECT_EQ(1, local_renderer.num_rendered_frames());
421
422 track->set_enabled(true);
423 EXPECT_TRUE(capturer->CaptureFrame());
424 EXPECT_EQ(2, local_renderer.num_rendered_frames());
425}
jiayl@webrtc.orgd83f4ef2015-03-13 21:26:12 +0000426