henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * Copyright 2012 Google Inc. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4 | * |
| 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.org | 33584f9 | 2013-07-25 16:43:30 +0000 | [diff] [blame] | 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 21 | * 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öm | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 33 | #include "talk/app/webrtc/test/fakedtlsidentitystore.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 34 | #include "talk/app/webrtc/test/fakevideotrackrenderer.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 35 | #include "talk/app/webrtc/videosourceinterface.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 36 | #include "talk/media/base/fakevideocapturer.h" |
| 37 | #include "talk/media/webrtc/webrtccommon.h" |
| 38 | #include "talk/media/webrtc/webrtcvoe.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 39 | #include "webrtc/base/gunit.h" |
| 40 | #include "webrtc/base/scoped_ptr.h" |
| 41 | #include "webrtc/base/thread.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 42 | |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 43 | using webrtc::DataChannelInterface; |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 44 | using webrtc::DtlsIdentityStoreInterface; |
| 45 | using webrtc::FakeVideoTrackRenderer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | using webrtc::MediaStreamInterface; |
| 47 | using webrtc::PeerConnectionFactoryInterface; |
| 48 | using webrtc::PeerConnectionInterface; |
| 49 | using webrtc::PeerConnectionObserver; |
| 50 | using webrtc::PortAllocatorFactoryInterface; |
| 51 | using webrtc::VideoSourceInterface; |
| 52 | using webrtc::VideoTrackInterface; |
| 53 | |
| 54 | namespace { |
| 55 | |
| 56 | typedef std::vector<PortAllocatorFactoryInterface::StunConfiguration> |
| 57 | StunConfigurations; |
| 58 | typedef std::vector<PortAllocatorFactoryInterface::TurnConfiguration> |
| 59 | TurnConfigurations; |
| 60 | |
| 61 | static const char kStunIceServer[] = "stun:stun.l.google.com:19302"; |
| 62 | static const char kTurnIceServer[] = "turn:test%40hello.com@test.com:1234"; |
| 63 | static const char kTurnIceServerWithTransport[] = |
| 64 | "turn:test@hello.com?transport=tcp"; |
| 65 | static const char kSecureTurnIceServer[] = |
| 66 | "turns:test@hello.com?transport=tcp"; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 67 | static const char kSecureTurnIceServerWithoutTransportParam[] = |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 68 | "turns:test_no_transport@hello.com:443"; |
| 69 | static const char kSecureTurnIceServerWithoutTransportAndPortParam[] = |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 70 | "turns:test_no_transport@hello.com"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 71 | static const char kTurnIceServerWithNoUsernameInUri[] = |
| 72 | "turn:test.com:1234"; |
| 73 | static const char kTurnPassword[] = "turnpassword"; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 74 | static const int kDefaultStunPort = 3478; |
| 75 | static const int kDefaultStunTlsPort = 5349; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | static const char kTurnUsername[] = "test"; |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 77 | static const char kStunIceServerWithIPv4Address[] = "stun:1.2.3.4:1234"; |
| 78 | static const char kStunIceServerWithIPv4AddressWithoutPort[] = "stun:1.2.3.4"; |
| 79 | static const char kStunIceServerWithIPv6Address[] = "stun:[2401:fa00:4::]:1234"; |
| 80 | static const char kStunIceServerWithIPv6AddressWithoutPort[] = |
| 81 | "stun:[2401:fa00:4::]"; |
| 82 | static const char kStunIceServerWithInvalidIPv6Address[] = |
| 83 | "stun:[2401:fa00:4:::3478"; |
| 84 | static const char kTurnIceServerWithIPv6Address[] = |
| 85 | "turn:test@[2401:fa00:4::]:1234"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 86 | |
| 87 | class NullPeerConnectionObserver : public PeerConnectionObserver { |
| 88 | public: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 89 | virtual void OnMessage(const std::string& msg) {} |
| 90 | virtual void OnSignalingMessage(const std::string& msg) {} |
| 91 | virtual void OnSignalingChange( |
| 92 | PeerConnectionInterface::SignalingState new_state) {} |
| 93 | virtual void OnAddStream(MediaStreamInterface* stream) {} |
| 94 | virtual void OnRemoveStream(MediaStreamInterface* stream) {} |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 95 | virtual void OnDataChannel(DataChannelInterface* data_channel) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 96 | virtual void OnRenegotiationNeeded() {} |
| 97 | virtual void OnIceConnectionChange( |
| 98 | PeerConnectionInterface::IceConnectionState new_state) {} |
| 99 | virtual void OnIceGatheringChange( |
| 100 | PeerConnectionInterface::IceGatheringState new_state) {} |
| 101 | virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {} |
| 102 | }; |
| 103 | |
| 104 | } // namespace |
| 105 | |
| 106 | class PeerConnectionFactoryTest : public testing::Test { |
| 107 | void SetUp() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 108 | factory_ = webrtc::CreatePeerConnectionFactory(rtc::Thread::Current(), |
| 109 | rtc::Thread::Current(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 110 | NULL, |
| 111 | NULL, |
| 112 | NULL); |
| 113 | |
| 114 | ASSERT_TRUE(factory_.get() != NULL); |
| 115 | allocator_factory_ = webrtc::FakePortAllocatorFactory::Create(); |
| 116 | } |
| 117 | |
| 118 | protected: |
| 119 | void VerifyStunConfigurations(StunConfigurations stun_config) { |
| 120 | webrtc::FakePortAllocatorFactory* allocator = |
| 121 | static_cast<webrtc::FakePortAllocatorFactory*>( |
| 122 | allocator_factory_.get()); |
| 123 | ASSERT_TRUE(allocator != NULL); |
| 124 | EXPECT_EQ(stun_config.size(), allocator->stun_configs().size()); |
| 125 | for (size_t i = 0; i < stun_config.size(); ++i) { |
| 126 | EXPECT_EQ(stun_config[i].server.ToString(), |
| 127 | allocator->stun_configs()[i].server.ToString()); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | void VerifyTurnConfigurations(TurnConfigurations turn_config) { |
| 132 | webrtc::FakePortAllocatorFactory* allocator = |
| 133 | static_cast<webrtc::FakePortAllocatorFactory*>( |
| 134 | allocator_factory_.get()); |
| 135 | ASSERT_TRUE(allocator != NULL); |
| 136 | EXPECT_EQ(turn_config.size(), allocator->turn_configs().size()); |
| 137 | for (size_t i = 0; i < turn_config.size(); ++i) { |
| 138 | EXPECT_EQ(turn_config[i].server.ToString(), |
| 139 | allocator->turn_configs()[i].server.ToString()); |
| 140 | EXPECT_EQ(turn_config[i].username, allocator->turn_configs()[i].username); |
| 141 | EXPECT_EQ(turn_config[i].password, allocator->turn_configs()[i].password); |
| 142 | EXPECT_EQ(turn_config[i].transport_type, |
| 143 | allocator->turn_configs()[i].transport_type); |
| 144 | } |
| 145 | } |
| 146 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 147 | rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 148 | NullPeerConnectionObserver observer_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 149 | rtc::scoped_refptr<PortAllocatorFactoryInterface> allocator_factory_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | // Verify creation of PeerConnection using internal ADM, video factory and |
| 153 | // internal libjingle threads. |
| 154 | TEST(PeerConnectionFactoryTestInternal, CreatePCUsingInternalModules) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 155 | rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 156 | webrtc::CreatePeerConnectionFactory()); |
| 157 | |
| 158 | NullPeerConnectionObserver observer; |
| 159 | webrtc::PeerConnectionInterface::IceServers servers; |
| 160 | |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 161 | rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( |
| 162 | new FakeDtlsIdentityStore()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 163 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 +0000 | [diff] [blame] | 164 | factory->CreatePeerConnection( |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 165 | servers, nullptr, nullptr, dtls_identity_store.Pass(), &observer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 166 | |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 167 | EXPECT_TRUE(pc.get() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | // This test verifies creation of PeerConnection with valid STUN and TURN |
| 171 | // configuration. Also verifies the URL's parsed correctly as expected. |
| 172 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServers) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 173 | PeerConnectionInterface::RTCConfiguration config; |
| 174 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 175 | ice_server.uri = kStunIceServer; |
| 176 | config.servers.push_back(ice_server); |
| 177 | ice_server.uri = kTurnIceServer; |
| 178 | ice_server.password = kTurnPassword; |
| 179 | config.servers.push_back(ice_server); |
| 180 | ice_server.uri = kTurnIceServerWithTransport; |
| 181 | ice_server.password = kTurnPassword; |
| 182 | config.servers.push_back(ice_server); |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 183 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
| 184 | new FakeDtlsIdentityStore()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 185 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 186 | factory_->CreatePeerConnection(config, nullptr, |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 187 | allocator_factory_.get(), |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 188 | dtls_identity_store.Pass(), |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 189 | &observer_)); |
| 190 | EXPECT_TRUE(pc.get() != NULL); |
| 191 | StunConfigurations stun_configs; |
| 192 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( |
| 193 | "stun.l.google.com", 19302); |
| 194 | stun_configs.push_back(stun1); |
| 195 | VerifyStunConfigurations(stun_configs); |
| 196 | TurnConfigurations turn_configs; |
| 197 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
| 198 | "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false); |
| 199 | turn_configs.push_back(turn1); |
| 200 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( |
| 201 | "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); |
| 202 | turn_configs.push_back(turn2); |
| 203 | VerifyTurnConfigurations(turn_configs); |
| 204 | } |
| 205 | |
| 206 | // This test verifies creation of PeerConnection with valid STUN and TURN |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 207 | // configuration. Also verifies the list of URL's parsed correctly as expected. |
| 208 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersUrls) { |
| 209 | PeerConnectionInterface::RTCConfiguration config; |
| 210 | webrtc::PeerConnectionInterface::IceServer ice_server; |
Joachim Bauch | d935f91 | 2015-05-29 22:14:21 +0200 | [diff] [blame] | 211 | ice_server.urls.push_back(""); // Empty URLs should be ignored. |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 212 | ice_server.urls.push_back(kStunIceServer); |
| 213 | ice_server.urls.push_back(kTurnIceServer); |
| 214 | ice_server.urls.push_back(kTurnIceServerWithTransport); |
| 215 | ice_server.password = kTurnPassword; |
| 216 | config.servers.push_back(ice_server); |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 217 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
| 218 | new FakeDtlsIdentityStore()); |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 219 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 220 | factory_->CreatePeerConnection(config, nullptr, |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 221 | allocator_factory_.get(), |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 222 | dtls_identity_store.Pass(), |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 223 | &observer_)); |
| 224 | EXPECT_TRUE(pc.get() != NULL); |
| 225 | StunConfigurations stun_configs; |
| 226 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( |
| 227 | "stun.l.google.com", 19302); |
| 228 | stun_configs.push_back(stun1); |
| 229 | VerifyStunConfigurations(stun_configs); |
| 230 | TurnConfigurations turn_configs; |
| 231 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
| 232 | "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false); |
| 233 | turn_configs.push_back(turn1); |
| 234 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( |
| 235 | "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); |
| 236 | turn_configs.push_back(turn2); |
| 237 | VerifyTurnConfigurations(turn_configs); |
| 238 | } |
| 239 | |
| 240 | // This test verifies creation of PeerConnection with valid STUN and TURN |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 241 | // configuration. Also verifies the URL's parsed correctly as expected. |
| 242 | // This version doesn't use RTCConfiguration. |
| 243 | // TODO(mallinath) - Remove this method after clients start using RTCConfig. |
| 244 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersOldSignature) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 245 | webrtc::PeerConnectionInterface::IceServers ice_servers; |
| 246 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 247 | ice_server.uri = kStunIceServer; |
| 248 | ice_servers.push_back(ice_server); |
| 249 | ice_server.uri = kTurnIceServer; |
| 250 | ice_server.password = kTurnPassword; |
| 251 | ice_servers.push_back(ice_server); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 252 | ice_server.uri = kTurnIceServerWithTransport; |
| 253 | ice_server.password = kTurnPassword; |
| 254 | ice_servers.push_back(ice_server); |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 255 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
| 256 | new FakeDtlsIdentityStore()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 257 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 258 | factory_->CreatePeerConnection(ice_servers, nullptr, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 259 | allocator_factory_.get(), |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 260 | dtls_identity_store.Pass(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 261 | &observer_)); |
| 262 | EXPECT_TRUE(pc.get() != NULL); |
| 263 | StunConfigurations stun_configs; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 264 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 265 | "stun.l.google.com", 19302); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 266 | stun_configs.push_back(stun1); |
| 267 | VerifyStunConfigurations(stun_configs); |
| 268 | TurnConfigurations turn_configs; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 269 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 270 | "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 271 | turn_configs.push_back(turn1); |
| 272 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 273 | "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 274 | turn_configs.push_back(turn2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 275 | VerifyTurnConfigurations(turn_configs); |
| 276 | } |
| 277 | |
| 278 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 279 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 280 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 281 | ice_server.uri = kStunIceServer; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 282 | config.servers.push_back(ice_server); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 283 | ice_server.uri = kTurnIceServerWithNoUsernameInUri; |
| 284 | ice_server.username = kTurnUsername; |
| 285 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 286 | config.servers.push_back(ice_server); |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 287 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
| 288 | new FakeDtlsIdentityStore()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 289 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 290 | factory_->CreatePeerConnection(config, nullptr, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 291 | allocator_factory_.get(), |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 292 | dtls_identity_store.Pass(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 293 | &observer_)); |
| 294 | EXPECT_TRUE(pc.get() != NULL); |
| 295 | TurnConfigurations turn_configs; |
| 296 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 297 | "test.com", 1234, kTurnUsername, kTurnPassword, "udp", false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 298 | turn_configs.push_back(turn); |
| 299 | VerifyTurnConfigurations(turn_configs); |
| 300 | } |
| 301 | |
| 302 | // This test verifies the PeerConnection created properly with TURN url which |
| 303 | // has transport parameter in it. |
| 304 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingTurnUrlWithTransportParam) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 305 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 306 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 307 | ice_server.uri = kTurnIceServerWithTransport; |
| 308 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 309 | config.servers.push_back(ice_server); |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 310 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
| 311 | new FakeDtlsIdentityStore()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 312 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 313 | factory_->CreatePeerConnection(config, nullptr, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 314 | allocator_factory_.get(), |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 315 | dtls_identity_store.Pass(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 316 | &observer_)); |
| 317 | EXPECT_TRUE(pc.get() != NULL); |
| 318 | TurnConfigurations turn_configs; |
| 319 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 320 | "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 321 | turn_configs.push_back(turn); |
| 322 | VerifyTurnConfigurations(turn_configs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 323 | } |
| 324 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 325 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 326 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 327 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 328 | ice_server.uri = kSecureTurnIceServer; |
| 329 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 330 | config.servers.push_back(ice_server); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 331 | ice_server.uri = kSecureTurnIceServerWithoutTransportParam; |
| 332 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 333 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 334 | ice_server.uri = kSecureTurnIceServerWithoutTransportAndPortParam; |
| 335 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 336 | config.servers.push_back(ice_server); |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 337 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
| 338 | new FakeDtlsIdentityStore()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 339 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 340 | factory_->CreatePeerConnection(config, nullptr, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 341 | allocator_factory_.get(), |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 342 | dtls_identity_store.Pass(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 343 | &observer_)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 344 | EXPECT_TRUE(pc.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 345 | TurnConfigurations turn_configs; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 346 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 347 | "hello.com", kDefaultStunTlsPort, "test", kTurnPassword, "tcp", true); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 348 | turn_configs.push_back(turn1); |
| 349 | // TURNS with transport param should be default to tcp. |
| 350 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 351 | "hello.com", 443, "test_no_transport", kTurnPassword, "tcp", true); |
| 352 | turn_configs.push_back(turn2); |
| 353 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn3( |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 354 | "hello.com", kDefaultStunTlsPort, "test_no_transport", |
| 355 | kTurnPassword, "tcp", true); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 356 | turn_configs.push_back(turn3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 357 | VerifyTurnConfigurations(turn_configs); |
| 358 | } |
| 359 | |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 360 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 361 | PeerConnectionInterface::RTCConfiguration config; |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 362 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 363 | ice_server.uri = kStunIceServerWithIPv4Address; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 364 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 365 | ice_server.uri = kStunIceServerWithIPv4AddressWithoutPort; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 366 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 367 | ice_server.uri = kStunIceServerWithIPv6Address; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 368 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 369 | ice_server.uri = kStunIceServerWithIPv6AddressWithoutPort; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 370 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 371 | ice_server.uri = kStunIceServerWithInvalidIPv6Address; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 372 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 373 | ice_server.uri = kTurnIceServerWithIPv6Address; |
| 374 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 375 | config.servers.push_back(ice_server); |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 376 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
| 377 | new FakeDtlsIdentityStore()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 378 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 379 | factory_->CreatePeerConnection(config, nullptr, |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 380 | allocator_factory_.get(), |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame^] | 381 | dtls_identity_store.Pass(), |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 382 | &observer_)); |
| 383 | EXPECT_TRUE(pc.get() != NULL); |
| 384 | StunConfigurations stun_configs; |
| 385 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( |
| 386 | "1.2.3.4", 1234); |
| 387 | stun_configs.push_back(stun1); |
| 388 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun2( |
| 389 | "1.2.3.4", 3478); |
| 390 | stun_configs.push_back(stun2); // Default port |
| 391 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun3( |
| 392 | "2401:fa00:4::", 1234); |
| 393 | stun_configs.push_back(stun3); |
| 394 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun4( |
| 395 | "2401:fa00:4::", 3478); |
| 396 | stun_configs.push_back(stun4); // Default port |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 397 | VerifyStunConfigurations(stun_configs); |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 398 | |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 399 | TurnConfigurations turn_configs; |
| 400 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
| 401 | "2401:fa00:4::", 1234, "test", kTurnPassword, "udp", false); |
| 402 | turn_configs.push_back(turn1); |
| 403 | VerifyTurnConfigurations(turn_configs); |
| 404 | } |
| 405 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 406 | // This test verifies the captured stream is rendered locally using a |
| 407 | // local video track. |
| 408 | TEST_F(PeerConnectionFactoryTest, LocalRendering) { |
| 409 | cricket::FakeVideoCapturer* capturer = new cricket::FakeVideoCapturer(); |
| 410 | // The source take ownership of |capturer|. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 411 | rtc::scoped_refptr<VideoSourceInterface> source( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 412 | factory_->CreateVideoSource(capturer, NULL)); |
| 413 | ASSERT_TRUE(source.get() != NULL); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 414 | rtc::scoped_refptr<VideoTrackInterface> track( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 415 | factory_->CreateVideoTrack("testlabel", source)); |
| 416 | ASSERT_TRUE(track.get() != NULL); |
| 417 | FakeVideoTrackRenderer local_renderer(track); |
| 418 | |
| 419 | EXPECT_EQ(0, local_renderer.num_rendered_frames()); |
| 420 | EXPECT_TRUE(capturer->CaptureFrame()); |
| 421 | EXPECT_EQ(1, local_renderer.num_rendered_frames()); |
| 422 | |
| 423 | track->set_enabled(false); |
| 424 | EXPECT_TRUE(capturer->CaptureFrame()); |
| 425 | EXPECT_EQ(1, local_renderer.num_rendered_frames()); |
| 426 | |
| 427 | track->set_enabled(true); |
| 428 | EXPECT_TRUE(capturer->CaptureFrame()); |
| 429 | EXPECT_EQ(2, local_renderer.num_rendered_frames()); |
| 430 | } |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 +0000 | [diff] [blame] | 431 | |