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" |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 +0000 | [diff] [blame] | 33 | #include "talk/app/webrtc/test/fakedtlsidentityservice.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 | |
| 43 | using webrtc::FakeVideoTrackRenderer; |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 44 | using webrtc::DataChannelInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | using webrtc::MediaStreamInterface; |
| 46 | using webrtc::PeerConnectionFactoryInterface; |
| 47 | using webrtc::PeerConnectionInterface; |
| 48 | using webrtc::PeerConnectionObserver; |
| 49 | using webrtc::PortAllocatorFactoryInterface; |
| 50 | using webrtc::VideoSourceInterface; |
| 51 | using webrtc::VideoTrackInterface; |
| 52 | |
| 53 | namespace { |
| 54 | |
| 55 | typedef std::vector<PortAllocatorFactoryInterface::StunConfiguration> |
| 56 | StunConfigurations; |
| 57 | typedef std::vector<PortAllocatorFactoryInterface::TurnConfiguration> |
| 58 | TurnConfigurations; |
| 59 | |
| 60 | static const char kStunIceServer[] = "stun:stun.l.google.com:19302"; |
| 61 | static const char kTurnIceServer[] = "turn:test%40hello.com@test.com:1234"; |
| 62 | static const char kTurnIceServerWithTransport[] = |
| 63 | "turn:test@hello.com?transport=tcp"; |
| 64 | static const char kSecureTurnIceServer[] = |
| 65 | "turns:test@hello.com?transport=tcp"; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 66 | static const char kSecureTurnIceServerWithoutTransportParam[] = |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 67 | "turns:test_no_transport@hello.com:443"; |
| 68 | static const char kSecureTurnIceServerWithoutTransportAndPortParam[] = |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 69 | "turns:test_no_transport@hello.com"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 70 | static const char kTurnIceServerWithNoUsernameInUri[] = |
| 71 | "turn:test.com:1234"; |
| 72 | static const char kTurnPassword[] = "turnpassword"; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 73 | static const int kDefaultStunPort = 3478; |
| 74 | static const int kDefaultStunTlsPort = 5349; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | static const char kTurnUsername[] = "test"; |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 76 | static const char kStunIceServerWithIPv4Address[] = "stun:1.2.3.4:1234"; |
| 77 | static const char kStunIceServerWithIPv4AddressWithoutPort[] = "stun:1.2.3.4"; |
| 78 | static const char kStunIceServerWithIPv6Address[] = "stun:[2401:fa00:4::]:1234"; |
| 79 | static const char kStunIceServerWithIPv6AddressWithoutPort[] = |
| 80 | "stun:[2401:fa00:4::]"; |
| 81 | static const char kStunIceServerWithInvalidIPv6Address[] = |
| 82 | "stun:[2401:fa00:4:::3478"; |
| 83 | static const char kTurnIceServerWithIPv6Address[] = |
| 84 | "turn:test@[2401:fa00:4::]:1234"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | |
| 86 | class NullPeerConnectionObserver : public PeerConnectionObserver { |
| 87 | public: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 88 | 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.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 94 | virtual void OnDataChannel(DataChannelInterface* data_channel) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | 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 | |
| 105 | class PeerConnectionFactoryTest : public testing::Test { |
| 106 | void SetUp() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 107 | factory_ = webrtc::CreatePeerConnectionFactory(rtc::Thread::Current(), |
| 108 | rtc::Thread::Current(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 109 | 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 146 | rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 147 | NullPeerConnectionObserver observer_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 148 | rtc::scoped_refptr<PortAllocatorFactoryInterface> allocator_factory_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | // Verify creation of PeerConnection using internal ADM, video factory and |
| 152 | // internal libjingle threads. |
| 153 | TEST(PeerConnectionFactoryTestInternal, CreatePCUsingInternalModules) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 154 | rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 155 | webrtc::CreatePeerConnectionFactory()); |
| 156 | |
| 157 | NullPeerConnectionObserver observer; |
| 158 | webrtc::PeerConnectionInterface::IceServers servers; |
| 159 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 160 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 +0000 | [diff] [blame] | 161 | factory->CreatePeerConnection( |
| 162 | servers, NULL, NULL, new FakeIdentityService(), &observer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 163 | |
| 164 | EXPECT_TRUE(pc.get() != NULL); |
| 165 | } |
| 166 | |
| 167 | // This test verifies creation of PeerConnection with valid STUN and TURN |
| 168 | // configuration. Also verifies the URL's parsed correctly as expected. |
| 169 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServers) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 170 | PeerConnectionInterface::RTCConfiguration config; |
| 171 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 172 | ice_server.uri = kStunIceServer; |
| 173 | config.servers.push_back(ice_server); |
| 174 | ice_server.uri = kTurnIceServer; |
| 175 | ice_server.password = kTurnPassword; |
| 176 | config.servers.push_back(ice_server); |
| 177 | ice_server.uri = kTurnIceServerWithTransport; |
| 178 | ice_server.password = kTurnPassword; |
| 179 | config.servers.push_back(ice_server); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 180 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 181 | factory_->CreatePeerConnection(config, NULL, |
| 182 | allocator_factory_.get(), |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 +0000 | [diff] [blame] | 183 | new FakeIdentityService(), |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 184 | &observer_)); |
| 185 | EXPECT_TRUE(pc.get() != NULL); |
| 186 | StunConfigurations stun_configs; |
| 187 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( |
| 188 | "stun.l.google.com", 19302); |
| 189 | stun_configs.push_back(stun1); |
| 190 | VerifyStunConfigurations(stun_configs); |
| 191 | TurnConfigurations turn_configs; |
| 192 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
| 193 | "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false); |
| 194 | turn_configs.push_back(turn1); |
| 195 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( |
| 196 | "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); |
| 197 | turn_configs.push_back(turn2); |
| 198 | VerifyTurnConfigurations(turn_configs); |
| 199 | } |
| 200 | |
| 201 | // This test verifies creation of PeerConnection with valid STUN and TURN |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 202 | // configuration. Also verifies the list of URL's parsed correctly as expected. |
| 203 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersUrls) { |
| 204 | PeerConnectionInterface::RTCConfiguration config; |
| 205 | webrtc::PeerConnectionInterface::IceServer ice_server; |
Joachim Bauch | d935f91 | 2015-05-29 22:14:21 +0200 | [diff] [blame^] | 206 | ice_server.urls.push_back(""); // Empty URLs should be ignored. |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 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); |
| 212 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
| 213 | factory_->CreatePeerConnection(config, NULL, |
| 214 | allocator_factory_.get(), |
| 215 | new FakeIdentityService(), |
| 216 | &observer_)); |
| 217 | 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.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 234 | // 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. |
| 237 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersOldSignature) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 238 | 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.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 245 | ice_server.uri = kTurnIceServerWithTransport; |
| 246 | ice_server.password = kTurnPassword; |
| 247 | ice_servers.push_back(ice_server); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 248 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 249 | factory_->CreatePeerConnection(ice_servers, NULL, |
| 250 | allocator_factory_.get(), |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 +0000 | [diff] [blame] | 251 | new FakeIdentityService(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 252 | &observer_)); |
| 253 | EXPECT_TRUE(pc.get() != NULL); |
| 254 | StunConfigurations stun_configs; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 255 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 256 | "stun.l.google.com", 19302); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 257 | stun_configs.push_back(stun1); |
| 258 | VerifyStunConfigurations(stun_configs); |
| 259 | TurnConfigurations turn_configs; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 260 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 261 | "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 262 | turn_configs.push_back(turn1); |
| 263 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 264 | "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 265 | turn_configs.push_back(turn2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 266 | VerifyTurnConfigurations(turn_configs); |
| 267 | } |
| 268 | |
| 269 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 270 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 271 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 272 | ice_server.uri = kStunIceServer; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 273 | config.servers.push_back(ice_server); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 274 | ice_server.uri = kTurnIceServerWithNoUsernameInUri; |
| 275 | ice_server.username = kTurnUsername; |
| 276 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 277 | config.servers.push_back(ice_server); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 278 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 279 | factory_->CreatePeerConnection(config, NULL, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 280 | allocator_factory_.get(), |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 +0000 | [diff] [blame] | 281 | new FakeIdentityService(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 282 | &observer_)); |
| 283 | EXPECT_TRUE(pc.get() != NULL); |
| 284 | TurnConfigurations turn_configs; |
| 285 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 286 | "test.com", 1234, kTurnUsername, kTurnPassword, "udp", false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 287 | 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. |
| 293 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingTurnUrlWithTransportParam) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 294 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 295 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 296 | ice_server.uri = kTurnIceServerWithTransport; |
| 297 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 298 | config.servers.push_back(ice_server); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 299 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 300 | factory_->CreatePeerConnection(config, NULL, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 301 | allocator_factory_.get(), |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 +0000 | [diff] [blame] | 302 | new FakeIdentityService(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 303 | &observer_)); |
| 304 | EXPECT_TRUE(pc.get() != NULL); |
| 305 | TurnConfigurations turn_configs; |
| 306 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 307 | "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 308 | turn_configs.push_back(turn); |
| 309 | VerifyTurnConfigurations(turn_configs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 310 | } |
| 311 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 312 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 313 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 314 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 315 | ice_server.uri = kSecureTurnIceServer; |
| 316 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 317 | config.servers.push_back(ice_server); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 318 | ice_server.uri = kSecureTurnIceServerWithoutTransportParam; |
| 319 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 320 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 321 | ice_server.uri = kSecureTurnIceServerWithoutTransportAndPortParam; |
| 322 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 323 | config.servers.push_back(ice_server); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 324 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 325 | factory_->CreatePeerConnection(config, NULL, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 326 | allocator_factory_.get(), |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 +0000 | [diff] [blame] | 327 | new FakeIdentityService(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 328 | &observer_)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 329 | EXPECT_TRUE(pc.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 330 | TurnConfigurations turn_configs; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 331 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 332 | "hello.com", kDefaultStunTlsPort, "test", kTurnPassword, "tcp", true); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 333 | turn_configs.push_back(turn1); |
| 334 | // TURNS with transport param should be default to tcp. |
| 335 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 336 | "hello.com", 443, "test_no_transport", kTurnPassword, "tcp", true); |
| 337 | turn_configs.push_back(turn2); |
| 338 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn3( |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 339 | "hello.com", kDefaultStunTlsPort, "test_no_transport", |
| 340 | kTurnPassword, "tcp", true); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 341 | turn_configs.push_back(turn3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 342 | VerifyTurnConfigurations(turn_configs); |
| 343 | } |
| 344 | |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 345 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 346 | PeerConnectionInterface::RTCConfiguration config; |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 347 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 348 | ice_server.uri = kStunIceServerWithIPv4Address; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 349 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 350 | ice_server.uri = kStunIceServerWithIPv4AddressWithoutPort; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 351 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 352 | ice_server.uri = kStunIceServerWithIPv6Address; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 353 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 354 | ice_server.uri = kStunIceServerWithIPv6AddressWithoutPort; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 355 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 356 | ice_server.uri = kStunIceServerWithInvalidIPv6Address; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 357 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 358 | ice_server.uri = kTurnIceServerWithIPv6Address; |
| 359 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 360 | config.servers.push_back(ice_server); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 361 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 362 | factory_->CreatePeerConnection(config, NULL, |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 363 | allocator_factory_.get(), |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 +0000 | [diff] [blame] | 364 | new FakeIdentityService(), |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 365 | &observer_)); |
| 366 | EXPECT_TRUE(pc.get() != NULL); |
| 367 | StunConfigurations stun_configs; |
| 368 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( |
| 369 | "1.2.3.4", 1234); |
| 370 | stun_configs.push_back(stun1); |
| 371 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun2( |
| 372 | "1.2.3.4", 3478); |
| 373 | stun_configs.push_back(stun2); // Default port |
| 374 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun3( |
| 375 | "2401:fa00:4::", 1234); |
| 376 | stun_configs.push_back(stun3); |
| 377 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun4( |
| 378 | "2401:fa00:4::", 3478); |
| 379 | stun_configs.push_back(stun4); // Default port |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 380 | VerifyStunConfigurations(stun_configs); |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 381 | |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 382 | TurnConfigurations turn_configs; |
| 383 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
| 384 | "2401:fa00:4::", 1234, "test", kTurnPassword, "udp", false); |
| 385 | turn_configs.push_back(turn1); |
| 386 | VerifyTurnConfigurations(turn_configs); |
| 387 | } |
| 388 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 389 | // This test verifies the captured stream is rendered locally using a |
| 390 | // local video track. |
| 391 | TEST_F(PeerConnectionFactoryTest, LocalRendering) { |
| 392 | cricket::FakeVideoCapturer* capturer = new cricket::FakeVideoCapturer(); |
| 393 | // The source take ownership of |capturer|. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 394 | rtc::scoped_refptr<VideoSourceInterface> source( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 395 | factory_->CreateVideoSource(capturer, NULL)); |
| 396 | ASSERT_TRUE(source.get() != NULL); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 397 | rtc::scoped_refptr<VideoTrackInterface> track( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 398 | factory_->CreateVideoTrack("testlabel", source)); |
| 399 | ASSERT_TRUE(track.get() != NULL); |
| 400 | FakeVideoTrackRenderer local_renderer(track); |
| 401 | |
| 402 | EXPECT_EQ(0, local_renderer.num_rendered_frames()); |
| 403 | EXPECT_TRUE(capturer->CaptureFrame()); |
| 404 | EXPECT_EQ(1, local_renderer.num_rendered_frames()); |
| 405 | |
| 406 | track->set_enabled(false); |
| 407 | EXPECT_TRUE(capturer->CaptureFrame()); |
| 408 | EXPECT_EQ(1, local_renderer.num_rendered_frames()); |
| 409 | |
| 410 | track->set_enabled(true); |
| 411 | EXPECT_TRUE(capturer->CaptureFrame()); |
| 412 | EXPECT_EQ(2, local_renderer.num_rendered_frames()); |
| 413 | } |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 +0000 | [diff] [blame] | 414 | |