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" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 33 | #include "talk/app/webrtc/test/fakevideotrackrenderer.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 34 | #include "talk/app/webrtc/videosourceinterface.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 35 | #include "talk/media/base/fakevideocapturer.h" |
| 36 | #include "talk/media/webrtc/webrtccommon.h" |
| 37 | #include "talk/media/webrtc/webrtcvoe.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 38 | #include "webrtc/base/gunit.h" |
| 39 | #include "webrtc/base/scoped_ptr.h" |
| 40 | #include "webrtc/base/thread.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 41 | |
| 42 | using webrtc::FakeVideoTrackRenderer; |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 43 | using webrtc::DataChannelInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | using webrtc::MediaStreamInterface; |
| 45 | using webrtc::PeerConnectionFactoryInterface; |
| 46 | using webrtc::PeerConnectionInterface; |
| 47 | using webrtc::PeerConnectionObserver; |
| 48 | using webrtc::PortAllocatorFactoryInterface; |
| 49 | using webrtc::VideoSourceInterface; |
| 50 | using webrtc::VideoTrackInterface; |
| 51 | |
| 52 | namespace { |
| 53 | |
| 54 | typedef std::vector<PortAllocatorFactoryInterface::StunConfiguration> |
| 55 | StunConfigurations; |
| 56 | typedef std::vector<PortAllocatorFactoryInterface::TurnConfiguration> |
| 57 | TurnConfigurations; |
| 58 | |
| 59 | static const char kStunIceServer[] = "stun:stun.l.google.com:19302"; |
| 60 | static const char kTurnIceServer[] = "turn:test%40hello.com@test.com:1234"; |
| 61 | static const char kTurnIceServerWithTransport[] = |
| 62 | "turn:test@hello.com?transport=tcp"; |
| 63 | static const char kSecureTurnIceServer[] = |
| 64 | "turns:test@hello.com?transport=tcp"; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 65 | static const char kSecureTurnIceServerWithoutTransportParam[] = |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 66 | "turns:test_no_transport@hello.com:443"; |
| 67 | static const char kSecureTurnIceServerWithoutTransportAndPortParam[] = |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 68 | "turns:test_no_transport@hello.com"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 69 | static const char kTurnIceServerWithNoUsernameInUri[] = |
| 70 | "turn:test.com:1234"; |
| 71 | static const char kTurnPassword[] = "turnpassword"; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 72 | static const int kDefaultStunPort = 3478; |
| 73 | static const int kDefaultStunTlsPort = 5349; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | static const char kTurnUsername[] = "test"; |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 75 | static const char kStunIceServerWithIPv4Address[] = "stun:1.2.3.4:1234"; |
| 76 | static const char kStunIceServerWithIPv4AddressWithoutPort[] = "stun:1.2.3.4"; |
| 77 | static const char kStunIceServerWithIPv6Address[] = "stun:[2401:fa00:4::]:1234"; |
| 78 | static const char kStunIceServerWithIPv6AddressWithoutPort[] = |
| 79 | "stun:[2401:fa00:4::]"; |
| 80 | static const char kStunIceServerWithInvalidIPv6Address[] = |
| 81 | "stun:[2401:fa00:4:::3478"; |
| 82 | static const char kTurnIceServerWithIPv6Address[] = |
| 83 | "turn:test@[2401:fa00:4::]:1234"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | |
| 85 | class NullPeerConnectionObserver : public PeerConnectionObserver { |
| 86 | public: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 87 | 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.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 93 | virtual void OnDataChannel(DataChannelInterface* data_channel) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 94 | 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 | |
| 104 | class PeerConnectionFactoryTest : public testing::Test { |
| 105 | void SetUp() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 106 | factory_ = webrtc::CreatePeerConnectionFactory(rtc::Thread::Current(), |
| 107 | rtc::Thread::Current(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 145 | rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 146 | NullPeerConnectionObserver observer_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 147 | rtc::scoped_refptr<PortAllocatorFactoryInterface> allocator_factory_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | // Verify creation of PeerConnection using internal ADM, video factory and |
| 151 | // internal libjingle threads. |
| 152 | TEST(PeerConnectionFactoryTestInternal, CreatePCUsingInternalModules) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 153 | rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 154 | webrtc::CreatePeerConnectionFactory()); |
| 155 | |
| 156 | NullPeerConnectionObserver observer; |
| 157 | webrtc::PeerConnectionInterface::IceServers servers; |
| 158 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 159 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 160 | factory->CreatePeerConnection(servers, NULL, NULL, NULL, &observer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 161 | |
| 162 | EXPECT_TRUE(pc.get() != NULL); |
| 163 | } |
| 164 | |
| 165 | // This test verifies creation of PeerConnection with valid STUN and TURN |
| 166 | // configuration. Also verifies the URL's parsed correctly as expected. |
| 167 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServers) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 168 | PeerConnectionInterface::RTCConfiguration config; |
| 169 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 170 | ice_server.uri = kStunIceServer; |
| 171 | config.servers.push_back(ice_server); |
| 172 | ice_server.uri = kTurnIceServer; |
| 173 | ice_server.password = kTurnPassword; |
| 174 | config.servers.push_back(ice_server); |
| 175 | ice_server.uri = kTurnIceServerWithTransport; |
| 176 | ice_server.password = kTurnPassword; |
| 177 | config.servers.push_back(ice_server); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 178 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 179 | factory_->CreatePeerConnection(config, NULL, |
| 180 | allocator_factory_.get(), |
| 181 | NULL, |
| 182 | &observer_)); |
| 183 | EXPECT_TRUE(pc.get() != NULL); |
| 184 | StunConfigurations stun_configs; |
| 185 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( |
| 186 | "stun.l.google.com", 19302); |
| 187 | stun_configs.push_back(stun1); |
| 188 | VerifyStunConfigurations(stun_configs); |
| 189 | TurnConfigurations turn_configs; |
| 190 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
| 191 | "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false); |
| 192 | turn_configs.push_back(turn1); |
| 193 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( |
| 194 | "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); |
| 195 | turn_configs.push_back(turn2); |
| 196 | VerifyTurnConfigurations(turn_configs); |
| 197 | } |
| 198 | |
| 199 | // This test verifies creation of PeerConnection with valid STUN and TURN |
| 200 | // configuration. Also verifies the URL's parsed correctly as expected. |
| 201 | // This version doesn't use RTCConfiguration. |
| 202 | // TODO(mallinath) - Remove this method after clients start using RTCConfig. |
| 203 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersOldSignature) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 204 | webrtc::PeerConnectionInterface::IceServers ice_servers; |
| 205 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 206 | ice_server.uri = kStunIceServer; |
| 207 | ice_servers.push_back(ice_server); |
| 208 | ice_server.uri = kTurnIceServer; |
| 209 | ice_server.password = kTurnPassword; |
| 210 | ice_servers.push_back(ice_server); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 211 | ice_server.uri = kTurnIceServerWithTransport; |
| 212 | ice_server.password = kTurnPassword; |
| 213 | ice_servers.push_back(ice_server); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 214 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 215 | factory_->CreatePeerConnection(ice_servers, NULL, |
| 216 | allocator_factory_.get(), |
| 217 | NULL, |
| 218 | &observer_)); |
| 219 | EXPECT_TRUE(pc.get() != NULL); |
| 220 | StunConfigurations stun_configs; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 221 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 222 | "stun.l.google.com", 19302); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 223 | stun_configs.push_back(stun1); |
| 224 | VerifyStunConfigurations(stun_configs); |
| 225 | TurnConfigurations turn_configs; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 226 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 227 | "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 228 | turn_configs.push_back(turn1); |
| 229 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 230 | "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 231 | turn_configs.push_back(turn2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 232 | VerifyTurnConfigurations(turn_configs); |
| 233 | } |
| 234 | |
| 235 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 236 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 237 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 238 | ice_server.uri = kStunIceServer; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 239 | config.servers.push_back(ice_server); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 240 | ice_server.uri = kTurnIceServerWithNoUsernameInUri; |
| 241 | ice_server.username = kTurnUsername; |
| 242 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 243 | config.servers.push_back(ice_server); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 244 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 245 | factory_->CreatePeerConnection(config, NULL, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 246 | allocator_factory_.get(), |
| 247 | NULL, |
| 248 | &observer_)); |
| 249 | EXPECT_TRUE(pc.get() != NULL); |
| 250 | TurnConfigurations turn_configs; |
| 251 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 252 | "test.com", 1234, kTurnUsername, kTurnPassword, "udp", false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 253 | turn_configs.push_back(turn); |
| 254 | VerifyTurnConfigurations(turn_configs); |
| 255 | } |
| 256 | |
| 257 | // This test verifies the PeerConnection created properly with TURN url which |
| 258 | // has transport parameter in it. |
| 259 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingTurnUrlWithTransportParam) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 260 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 261 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 262 | ice_server.uri = kTurnIceServerWithTransport; |
| 263 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 264 | config.servers.push_back(ice_server); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 265 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 266 | factory_->CreatePeerConnection(config, NULL, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 267 | allocator_factory_.get(), |
| 268 | NULL, |
| 269 | &observer_)); |
| 270 | EXPECT_TRUE(pc.get() != NULL); |
| 271 | TurnConfigurations turn_configs; |
| 272 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 273 | "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 274 | turn_configs.push_back(turn); |
| 275 | VerifyTurnConfigurations(turn_configs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 276 | } |
| 277 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 278 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) { |
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 = kSecureTurnIceServer; |
| 282 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 283 | config.servers.push_back(ice_server); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 284 | ice_server.uri = kSecureTurnIceServerWithoutTransportParam; |
| 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); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 287 | ice_server.uri = kSecureTurnIceServerWithoutTransportAndPortParam; |
| 288 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 289 | config.servers.push_back(ice_server); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 290 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 291 | factory_->CreatePeerConnection(config, NULL, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 292 | allocator_factory_.get(), |
| 293 | NULL, |
| 294 | &observer_)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 295 | EXPECT_TRUE(pc.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 296 | TurnConfigurations turn_configs; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 297 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 298 | "hello.com", kDefaultStunTlsPort, "test", kTurnPassword, "tcp", true); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 299 | turn_configs.push_back(turn1); |
| 300 | // TURNS with transport param should be default to tcp. |
| 301 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 302 | "hello.com", 443, "test_no_transport", kTurnPassword, "tcp", true); |
| 303 | turn_configs.push_back(turn2); |
| 304 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn3( |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 305 | "hello.com", kDefaultStunTlsPort, "test_no_transport", |
| 306 | kTurnPassword, "tcp", true); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 307 | turn_configs.push_back(turn3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 308 | VerifyTurnConfigurations(turn_configs); |
| 309 | } |
| 310 | |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 311 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 312 | PeerConnectionInterface::RTCConfiguration config; |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 313 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 314 | ice_server.uri = kStunIceServerWithIPv4Address; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 315 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 316 | ice_server.uri = kStunIceServerWithIPv4AddressWithoutPort; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 317 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 318 | ice_server.uri = kStunIceServerWithIPv6Address; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 319 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 320 | ice_server.uri = kStunIceServerWithIPv6AddressWithoutPort; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 321 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 322 | ice_server.uri = kStunIceServerWithInvalidIPv6Address; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 323 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 324 | ice_server.uri = kTurnIceServerWithIPv6Address; |
| 325 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 326 | config.servers.push_back(ice_server); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 327 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 328 | factory_->CreatePeerConnection(config, NULL, |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 329 | allocator_factory_.get(), |
| 330 | NULL, |
| 331 | &observer_)); |
| 332 | EXPECT_TRUE(pc.get() != NULL); |
| 333 | StunConfigurations stun_configs; |
| 334 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( |
| 335 | "1.2.3.4", 1234); |
| 336 | stun_configs.push_back(stun1); |
| 337 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun2( |
| 338 | "1.2.3.4", 3478); |
| 339 | stun_configs.push_back(stun2); // Default port |
| 340 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun3( |
| 341 | "2401:fa00:4::", 1234); |
| 342 | stun_configs.push_back(stun3); |
| 343 | webrtc::PortAllocatorFactoryInterface::StunConfiguration stun4( |
| 344 | "2401:fa00:4::", 3478); |
| 345 | stun_configs.push_back(stun4); // Default port |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 346 | VerifyStunConfigurations(stun_configs); |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 347 | |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 348 | TurnConfigurations turn_configs; |
| 349 | webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
| 350 | "2401:fa00:4::", 1234, "test", kTurnPassword, "udp", false); |
| 351 | turn_configs.push_back(turn1); |
| 352 | VerifyTurnConfigurations(turn_configs); |
| 353 | } |
| 354 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 355 | // This test verifies the captured stream is rendered locally using a |
| 356 | // local video track. |
| 357 | TEST_F(PeerConnectionFactoryTest, LocalRendering) { |
| 358 | cricket::FakeVideoCapturer* capturer = new cricket::FakeVideoCapturer(); |
| 359 | // The source take ownership of |capturer|. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 360 | rtc::scoped_refptr<VideoSourceInterface> source( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 361 | factory_->CreateVideoSource(capturer, NULL)); |
| 362 | ASSERT_TRUE(source.get() != NULL); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 363 | rtc::scoped_refptr<VideoTrackInterface> track( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 364 | factory_->CreateVideoTrack("testlabel", source)); |
| 365 | ASSERT_TRUE(track.get() != NULL); |
| 366 | FakeVideoTrackRenderer local_renderer(track); |
| 367 | |
| 368 | EXPECT_EQ(0, local_renderer.num_rendered_frames()); |
| 369 | EXPECT_TRUE(capturer->CaptureFrame()); |
| 370 | EXPECT_EQ(1, local_renderer.num_rendered_frames()); |
| 371 | |
| 372 | track->set_enabled(false); |
| 373 | EXPECT_TRUE(capturer->CaptureFrame()); |
| 374 | EXPECT_EQ(1, local_renderer.num_rendered_frames()); |
| 375 | |
| 376 | track->set_enabled(true); |
| 377 | EXPECT_TRUE(capturer->CaptureFrame()); |
| 378 | EXPECT_EQ(2, local_renderer.num_rendered_frames()); |
| 379 | } |