blob: d0018d9897c1b96010aa2e8a676d119cae209e99 [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>
kwiberg0eb15ed2015-12-17 03:04:15 -080029#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030
31#include "talk/app/webrtc/fakeportallocatorfactory.h"
32#include "talk/app/webrtc/mediastreaminterface.h"
33#include "talk/app/webrtc/peerconnectionfactory.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020034#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035#include "talk/app/webrtc/test/fakevideotrackrenderer.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000036#include "talk/app/webrtc/videosourceinterface.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/media/base/fakevideocapturer.h"
38#include "talk/media/webrtc/webrtccommon.h"
39#include "talk/media/webrtc/webrtcvoe.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000040#include "webrtc/base/gunit.h"
41#include "webrtc/base/scoped_ptr.h"
42#include "webrtc/base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +000044using webrtc::DataChannelInterface;
Henrik Boström5e56c592015-08-11 10:33:13 +020045using webrtc::DtlsIdentityStoreInterface;
46using webrtc::FakeVideoTrackRenderer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047using webrtc::MediaStreamInterface;
48using webrtc::PeerConnectionFactoryInterface;
49using webrtc::PeerConnectionInterface;
50using webrtc::PeerConnectionObserver;
51using webrtc::PortAllocatorFactoryInterface;
52using webrtc::VideoSourceInterface;
53using webrtc::VideoTrackInterface;
54
55namespace {
56
57typedef std::vector<PortAllocatorFactoryInterface::StunConfiguration>
58 StunConfigurations;
59typedef std::vector<PortAllocatorFactoryInterface::TurnConfiguration>
60 TurnConfigurations;
61
62static const char kStunIceServer[] = "stun:stun.l.google.com:19302";
63static const char kTurnIceServer[] = "turn:test%40hello.com@test.com:1234";
64static const char kTurnIceServerWithTransport[] =
65 "turn:test@hello.com?transport=tcp";
66static const char kSecureTurnIceServer[] =
67 "turns:test@hello.com?transport=tcp";
wu@webrtc.org78187522013-10-07 23:32:02 +000068static const char kSecureTurnIceServerWithoutTransportParam[] =
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +000069 "turns:test_no_transport@hello.com:443";
70static const char kSecureTurnIceServerWithoutTransportAndPortParam[] =
wu@webrtc.org78187522013-10-07 23:32:02 +000071 "turns:test_no_transport@hello.com";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072static const char kTurnIceServerWithNoUsernameInUri[] =
73 "turn:test.com:1234";
74static const char kTurnPassword[] = "turnpassword";
wu@webrtc.org91053e72013-08-10 07:18:04 +000075static const int kDefaultStunPort = 3478;
76static const int kDefaultStunTlsPort = 5349;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077static const char kTurnUsername[] = "test";
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +000078static const char kStunIceServerWithIPv4Address[] = "stun:1.2.3.4:1234";
79static const char kStunIceServerWithIPv4AddressWithoutPort[] = "stun:1.2.3.4";
80static const char kStunIceServerWithIPv6Address[] = "stun:[2401:fa00:4::]:1234";
81static const char kStunIceServerWithIPv6AddressWithoutPort[] =
82 "stun:[2401:fa00:4::]";
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +000083static const char kTurnIceServerWithIPv6Address[] =
84 "turn:test@[2401:fa00:4::]:1234";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085
86class NullPeerConnectionObserver : public PeerConnectionObserver {
87 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088 virtual void OnMessage(const std::string& msg) {}
89 virtual void OnSignalingMessage(const std::string& msg) {}
90 virtual void OnSignalingChange(
91 PeerConnectionInterface::SignalingState new_state) {}
92 virtual void OnAddStream(MediaStreamInterface* stream) {}
93 virtual void OnRemoveStream(MediaStreamInterface* stream) {}
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +000094 virtual void OnDataChannel(DataChannelInterface* data_channel) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095 virtual void OnRenegotiationNeeded() {}
96 virtual void OnIceConnectionChange(
97 PeerConnectionInterface::IceConnectionState new_state) {}
98 virtual void OnIceGatheringChange(
99 PeerConnectionInterface::IceGatheringState new_state) {}
100 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {}
101};
102
103} // namespace
104
105class PeerConnectionFactoryTest : public testing::Test {
106 void SetUp() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000107 factory_ = webrtc::CreatePeerConnectionFactory(rtc::Thread::Current(),
108 rtc::Thread::Current(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109 NULL,
110 NULL,
111 NULL);
112
113 ASSERT_TRUE(factory_.get() != NULL);
114 allocator_factory_ = webrtc::FakePortAllocatorFactory::Create();
115 }
116
117 protected:
118 void VerifyStunConfigurations(StunConfigurations stun_config) {
119 webrtc::FakePortAllocatorFactory* allocator =
120 static_cast<webrtc::FakePortAllocatorFactory*>(
121 allocator_factory_.get());
122 ASSERT_TRUE(allocator != NULL);
123 EXPECT_EQ(stun_config.size(), allocator->stun_configs().size());
124 for (size_t i = 0; i < stun_config.size(); ++i) {
125 EXPECT_EQ(stun_config[i].server.ToString(),
126 allocator->stun_configs()[i].server.ToString());
127 }
128 }
129
130 void VerifyTurnConfigurations(TurnConfigurations turn_config) {
131 webrtc::FakePortAllocatorFactory* allocator =
132 static_cast<webrtc::FakePortAllocatorFactory*>(
133 allocator_factory_.get());
134 ASSERT_TRUE(allocator != NULL);
135 EXPECT_EQ(turn_config.size(), allocator->turn_configs().size());
136 for (size_t i = 0; i < turn_config.size(); ++i) {
137 EXPECT_EQ(turn_config[i].server.ToString(),
138 allocator->turn_configs()[i].server.ToString());
139 EXPECT_EQ(turn_config[i].username, allocator->turn_configs()[i].username);
140 EXPECT_EQ(turn_config[i].password, allocator->turn_configs()[i].password);
141 EXPECT_EQ(turn_config[i].transport_type,
142 allocator->turn_configs()[i].transport_type);
143 }
144 }
145
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000146 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147 NullPeerConnectionObserver observer_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000148 rtc::scoped_refptr<PortAllocatorFactoryInterface> allocator_factory_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149};
150
151// Verify creation of PeerConnection using internal ADM, video factory and
152// internal libjingle threads.
153TEST(PeerConnectionFactoryTestInternal, CreatePCUsingInternalModules) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000154 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 webrtc::CreatePeerConnectionFactory());
156
157 NullPeerConnectionObserver observer;
158 webrtc::PeerConnectionInterface::IceServers servers;
159
Henrik Boström5e56c592015-08-11 10:33:13 +0200160 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
161 new FakeDtlsIdentityStore());
kwiberg0eb15ed2015-12-17 03:04:15 -0800162 rtc::scoped_refptr<PeerConnectionInterface> pc(factory->CreatePeerConnection(
163 servers, nullptr, nullptr, std::move(dtls_identity_store), &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());
kwiberg0eb15ed2015-12-17 03:04:15 -0800183 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
184 config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
185 &observer_));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000186 EXPECT_TRUE(pc.get() != NULL);
187 StunConfigurations stun_configs;
188 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1(
189 "stun.l.google.com", 19302);
190 stun_configs.push_back(stun1);
191 VerifyStunConfigurations(stun_configs);
192 TurnConfigurations turn_configs;
193 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1(
194 "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false);
195 turn_configs.push_back(turn1);
196 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2(
197 "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false);
198 turn_configs.push_back(turn2);
199 VerifyTurnConfigurations(turn_configs);
200}
201
202// This test verifies creation of PeerConnection with valid STUN and TURN
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200203// configuration. Also verifies the list of URL's parsed correctly as expected.
204TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersUrls) {
205 PeerConnectionInterface::RTCConfiguration config;
206 webrtc::PeerConnectionInterface::IceServer ice_server;
207 ice_server.urls.push_back(kStunIceServer);
208 ice_server.urls.push_back(kTurnIceServer);
209 ice_server.urls.push_back(kTurnIceServerWithTransport);
210 ice_server.password = kTurnPassword;
211 config.servers.push_back(ice_server);
Henrik Boström5e56c592015-08-11 10:33:13 +0200212 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
213 new FakeDtlsIdentityStore());
kwiberg0eb15ed2015-12-17 03:04:15 -0800214 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
215 config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
216 &observer_));
Joachim Bauch7c4e7452015-05-28 23:06:30 +0200217 EXPECT_TRUE(pc.get() != NULL);
218 StunConfigurations stun_configs;
219 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1(
220 "stun.l.google.com", 19302);
221 stun_configs.push_back(stun1);
222 VerifyStunConfigurations(stun_configs);
223 TurnConfigurations turn_configs;
224 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1(
225 "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false);
226 turn_configs.push_back(turn1);
227 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2(
228 "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false);
229 turn_configs.push_back(turn2);
230 VerifyTurnConfigurations(turn_configs);
231}
232
233// This test verifies creation of PeerConnection with valid STUN and TURN
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000234// configuration. Also verifies the URL's parsed correctly as expected.
235// This version doesn't use RTCConfiguration.
236// TODO(mallinath) - Remove this method after clients start using RTCConfig.
237TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersOldSignature) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 webrtc::PeerConnectionInterface::IceServers ice_servers;
239 webrtc::PeerConnectionInterface::IceServer ice_server;
240 ice_server.uri = kStunIceServer;
241 ice_servers.push_back(ice_server);
242 ice_server.uri = kTurnIceServer;
243 ice_server.password = kTurnPassword;
244 ice_servers.push_back(ice_server);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000245 ice_server.uri = kTurnIceServerWithTransport;
246 ice_server.password = kTurnPassword;
247 ice_servers.push_back(ice_server);
Henrik Boström5e56c592015-08-11 10:33:13 +0200248 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
249 new FakeDtlsIdentityStore());
kwiberg0eb15ed2015-12-17 03:04:15 -0800250 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
251 ice_servers, nullptr, allocator_factory_.get(),
252 std::move(dtls_identity_store), &observer_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 EXPECT_TRUE(pc.get() != NULL);
254 StunConfigurations stun_configs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1(
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000256 "stun.l.google.com", 19302);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 stun_configs.push_back(stun1);
258 VerifyStunConfigurations(stun_configs);
259 TurnConfigurations turn_configs;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000260 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1(
wu@webrtc.org91053e72013-08-10 07:18:04 +0000261 "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000262 turn_configs.push_back(turn1);
263 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2(
wu@webrtc.org91053e72013-08-10 07:18:04 +0000264 "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000265 turn_configs.push_back(turn2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000266 VerifyTurnConfigurations(turn_configs);
267}
268
269TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000270 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 webrtc::PeerConnectionInterface::IceServer ice_server;
272 ice_server.uri = kStunIceServer;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000273 config.servers.push_back(ice_server);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274 ice_server.uri = kTurnIceServerWithNoUsernameInUri;
275 ice_server.username = kTurnUsername;
276 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000277 config.servers.push_back(ice_server);
Henrik Boström5e56c592015-08-11 10:33:13 +0200278 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
279 new FakeDtlsIdentityStore());
kwiberg0eb15ed2015-12-17 03:04:15 -0800280 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
281 config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
282 &observer_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283 EXPECT_TRUE(pc.get() != NULL);
284 TurnConfigurations turn_configs;
285 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn(
wu@webrtc.org91053e72013-08-10 07:18:04 +0000286 "test.com", 1234, kTurnUsername, kTurnPassword, "udp", false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000287 turn_configs.push_back(turn);
288 VerifyTurnConfigurations(turn_configs);
289}
290
291// This test verifies the PeerConnection created properly with TURN url which
292// has transport parameter in it.
293TEST_F(PeerConnectionFactoryTest, CreatePCUsingTurnUrlWithTransportParam) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000294 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295 webrtc::PeerConnectionInterface::IceServer ice_server;
296 ice_server.uri = kTurnIceServerWithTransport;
297 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000298 config.servers.push_back(ice_server);
Henrik Boström5e56c592015-08-11 10:33:13 +0200299 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
300 new FakeDtlsIdentityStore());
kwiberg0eb15ed2015-12-17 03:04:15 -0800301 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
302 config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
303 &observer_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304 EXPECT_TRUE(pc.get() != NULL);
305 TurnConfigurations turn_configs;
306 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn(
wu@webrtc.org91053e72013-08-10 07:18:04 +0000307 "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 turn_configs.push_back(turn);
309 VerifyTurnConfigurations(turn_configs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310}
311
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000313 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314 webrtc::PeerConnectionInterface::IceServer ice_server;
315 ice_server.uri = kSecureTurnIceServer;
316 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000317 config.servers.push_back(ice_server);
wu@webrtc.org78187522013-10-07 23:32:02 +0000318 ice_server.uri = kSecureTurnIceServerWithoutTransportParam;
319 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000320 config.servers.push_back(ice_server);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000321 ice_server.uri = kSecureTurnIceServerWithoutTransportAndPortParam;
322 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000323 config.servers.push_back(ice_server);
Henrik Boström5e56c592015-08-11 10:33:13 +0200324 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
325 new FakeDtlsIdentityStore());
kwiberg0eb15ed2015-12-17 03:04:15 -0800326 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
327 config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
328 &observer_));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000329 EXPECT_TRUE(pc.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 TurnConfigurations turn_configs;
wu@webrtc.org78187522013-10-07 23:32:02 +0000331 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1(
wu@webrtc.org91053e72013-08-10 07:18:04 +0000332 "hello.com", kDefaultStunTlsPort, "test", kTurnPassword, "tcp", true);
wu@webrtc.org78187522013-10-07 23:32:02 +0000333 turn_configs.push_back(turn1);
334 // TURNS with transport param should be default to tcp.
335 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2(
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000336 "hello.com", 443, "test_no_transport", kTurnPassword, "tcp", true);
337 turn_configs.push_back(turn2);
338 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn3(
wu@webrtc.org78187522013-10-07 23:32:02 +0000339 "hello.com", kDefaultStunTlsPort, "test_no_transport",
340 kTurnPassword, "tcp", true);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000341 turn_configs.push_back(turn3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 VerifyTurnConfigurations(turn_configs);
343}
344
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000345TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000346 PeerConnectionInterface::RTCConfiguration config;
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000347 webrtc::PeerConnectionInterface::IceServer ice_server;
348 ice_server.uri = kStunIceServerWithIPv4Address;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000349 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000350 ice_server.uri = kStunIceServerWithIPv4AddressWithoutPort;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000351 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000352 ice_server.uri = kStunIceServerWithIPv6Address;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000353 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000354 ice_server.uri = kStunIceServerWithIPv6AddressWithoutPort;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000355 config.servers.push_back(ice_server);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000356 ice_server.uri = kTurnIceServerWithIPv6Address;
357 ice_server.password = kTurnPassword;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000358 config.servers.push_back(ice_server);
Henrik Boström5e56c592015-08-11 10:33:13 +0200359 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
360 new FakeDtlsIdentityStore());
kwiberg0eb15ed2015-12-17 03:04:15 -0800361 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
362 config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
363 &observer_));
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000364 EXPECT_TRUE(pc.get() != NULL);
365 StunConfigurations stun_configs;
366 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1(
367 "1.2.3.4", 1234);
368 stun_configs.push_back(stun1);
369 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun2(
370 "1.2.3.4", 3478);
371 stun_configs.push_back(stun2); // Default port
372 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun3(
373 "2401:fa00:4::", 1234);
374 stun_configs.push_back(stun3);
375 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun4(
376 "2401:fa00:4::", 3478);
377 stun_configs.push_back(stun4); // Default port
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000378 VerifyStunConfigurations(stun_configs);
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000379
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000380 TurnConfigurations turn_configs;
381 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1(
382 "2401:fa00:4::", 1234, "test", kTurnPassword, "udp", false);
383 turn_configs.push_back(turn1);
384 VerifyTurnConfigurations(turn_configs);
385}
386
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387// This test verifies the captured stream is rendered locally using a
388// local video track.
389TEST_F(PeerConnectionFactoryTest, LocalRendering) {
390 cricket::FakeVideoCapturer* capturer = new cricket::FakeVideoCapturer();
391 // The source take ownership of |capturer|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000392 rtc::scoped_refptr<VideoSourceInterface> source(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000393 factory_->CreateVideoSource(capturer, NULL));
394 ASSERT_TRUE(source.get() != NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000395 rtc::scoped_refptr<VideoTrackInterface> track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000396 factory_->CreateVideoTrack("testlabel", source));
397 ASSERT_TRUE(track.get() != NULL);
398 FakeVideoTrackRenderer local_renderer(track);
399
400 EXPECT_EQ(0, local_renderer.num_rendered_frames());
401 EXPECT_TRUE(capturer->CaptureFrame());
402 EXPECT_EQ(1, local_renderer.num_rendered_frames());
403
404 track->set_enabled(false);
405 EXPECT_TRUE(capturer->CaptureFrame());
406 EXPECT_EQ(1, local_renderer.num_rendered_frames());
407
408 track->set_enabled(true);
409 EXPECT_TRUE(capturer->CaptureFrame());
410 EXPECT_EQ(2, local_renderer.num_rendered_frames());
411}
jiayl@webrtc.orgd83f4ef2015-03-13 21:26:12 +0000412