henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 11 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | #include <string> |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 13 | #include <utility> |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 14 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 15 | |
Karl Wiberg | 1b0eae3 | 2017-10-17 14:48:54 +0200 | [diff] [blame] | 16 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
| 17 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "api/mediastreaminterface.h" |
| 19 | #include "media/base/fakevideocapturer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "p2p/base/fakeportallocator.h" |
| 21 | #include "pc/peerconnectionfactory.h" |
henrika | 919dc2e | 2017-10-12 14:24:55 +0200 | [diff] [blame] | 22 | #include "pc/test/fakeaudiocapturemodule.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "rtc_base/gunit.h" |
Patrik Höglund | 563934e | 2017-09-15 09:04:28 +0200 | [diff] [blame] | 24 | |
ossu | 7bb87ee | 2017-01-23 04:56:25 -0800 | [diff] [blame] | 25 | #ifdef WEBRTC_ANDROID |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "pc/test/androidtestinitializer.h" |
ossu | 7bb87ee | 2017-01-23 04:56:25 -0800 | [diff] [blame] | 27 | #endif |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 28 | #include "pc/test/fakertccertificategenerator.h" |
| 29 | #include "pc/test/fakevideotrackrenderer.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 30 | |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 31 | using webrtc::DataChannelInterface; |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 32 | using webrtc::FakeVideoTrackRenderer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 33 | using webrtc::MediaStreamInterface; |
| 34 | using webrtc::PeerConnectionFactoryInterface; |
| 35 | using webrtc::PeerConnectionInterface; |
| 36 | using webrtc::PeerConnectionObserver; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 37 | using webrtc::VideoTrackSourceInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 38 | using webrtc::VideoTrackInterface; |
| 39 | |
| 40 | namespace { |
| 41 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 42 | static const char kStunIceServer[] = "stun:stun.l.google.com:19302"; |
| 43 | static const char kTurnIceServer[] = "turn:test%40hello.com@test.com:1234"; |
| 44 | static const char kTurnIceServerWithTransport[] = |
| 45 | "turn:test@hello.com?transport=tcp"; |
| 46 | static const char kSecureTurnIceServer[] = |
| 47 | "turns:test@hello.com?transport=tcp"; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 48 | static const char kSecureTurnIceServerWithoutTransportParam[] = |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 49 | "turns:test_no_transport@hello.com:443"; |
| 50 | static const char kSecureTurnIceServerWithoutTransportAndPortParam[] = |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 51 | "turns:test_no_transport@hello.com"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 52 | static const char kTurnIceServerWithNoUsernameInUri[] = |
| 53 | "turn:test.com:1234"; |
| 54 | static const char kTurnPassword[] = "turnpassword"; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 55 | static const int kDefaultStunPort = 3478; |
| 56 | static const int kDefaultStunTlsPort = 5349; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 57 | static const char kTurnUsername[] = "test"; |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 58 | static const char kStunIceServerWithIPv4Address[] = "stun:1.2.3.4:1234"; |
| 59 | static const char kStunIceServerWithIPv4AddressWithoutPort[] = "stun:1.2.3.4"; |
| 60 | static const char kStunIceServerWithIPv6Address[] = "stun:[2401:fa00:4::]:1234"; |
| 61 | static const char kStunIceServerWithIPv6AddressWithoutPort[] = |
| 62 | "stun:[2401:fa00:4::]"; |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 63 | static const char kTurnIceServerWithIPv6Address[] = |
| 64 | "turn:test@[2401:fa00:4::]:1234"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | |
| 66 | class NullPeerConnectionObserver : public PeerConnectionObserver { |
| 67 | public: |
Henrik Kjellander | 3fe372d | 2016-05-12 08:10:52 +0200 | [diff] [blame] | 68 | virtual ~NullPeerConnectionObserver() = default; |
nisse | 63b14b7 | 2017-01-31 03:34:01 -0800 | [diff] [blame] | 69 | void OnSignalingChange( |
| 70 | PeerConnectionInterface::SignalingState new_state) override {} |
| 71 | void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override {} |
| 72 | void OnRemoveStream( |
| 73 | rtc::scoped_refptr<MediaStreamInterface> stream) override {} |
| 74 | void OnDataChannel( |
| 75 | rtc::scoped_refptr<DataChannelInterface> data_channel) override {} |
| 76 | void OnRenegotiationNeeded() override {} |
| 77 | void OnIceConnectionChange( |
| 78 | PeerConnectionInterface::IceConnectionState new_state) override {} |
| 79 | void OnIceGatheringChange( |
| 80 | PeerConnectionInterface::IceGatheringState new_state) override {} |
| 81 | void OnIceCandidate( |
| 82 | const webrtc::IceCandidateInterface* candidate) override {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | } // namespace |
| 86 | |
| 87 | class PeerConnectionFactoryTest : public testing::Test { |
| 88 | void SetUp() { |
phoglund | 37ebcf0 | 2016-01-08 05:04:57 -0800 | [diff] [blame] | 89 | #ifdef WEBRTC_ANDROID |
| 90 | webrtc::InitializeAndroidObjects(); |
| 91 | #endif |
henrika | 919dc2e | 2017-10-12 14:24:55 +0200 | [diff] [blame] | 92 | // Use fake audio device module since we're only testing the interface |
| 93 | // level, and using a real one could make tests flaky e.g. when run in |
| 94 | // parallel. |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 95 | factory_ = webrtc::CreatePeerConnectionFactory( |
henrika | 919dc2e | 2017-10-12 14:24:55 +0200 | [diff] [blame] | 96 | rtc::Thread::Current(), rtc::Thread::Current(), |
Karl Wiberg | 1b0eae3 | 2017-10-17 14:48:54 +0200 | [diff] [blame] | 97 | FakeAudioCaptureModule::Create(), |
| 98 | webrtc::CreateBuiltinAudioEncoderFactory(), |
| 99 | webrtc::CreateBuiltinAudioDecoderFactory(), nullptr, nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 100 | |
| 101 | ASSERT_TRUE(factory_.get() != NULL); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 102 | port_allocator_.reset( |
| 103 | new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
| 104 | raw_port_allocator_ = port_allocator_.get(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | protected: |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 108 | void VerifyStunServers(cricket::ServerAddresses stun_servers) { |
| 109 | EXPECT_EQ(stun_servers, raw_port_allocator_->stun_servers()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 112 | void VerifyTurnServers(std::vector<cricket::RelayServerConfig> turn_servers) { |
| 113 | EXPECT_EQ(turn_servers.size(), raw_port_allocator_->turn_servers().size()); |
| 114 | for (size_t i = 0; i < turn_servers.size(); ++i) { |
| 115 | ASSERT_EQ(1u, turn_servers[i].ports.size()); |
| 116 | EXPECT_EQ(1u, raw_port_allocator_->turn_servers()[i].ports.size()); |
| 117 | EXPECT_EQ( |
| 118 | turn_servers[i].ports[0].address.ToString(), |
| 119 | raw_port_allocator_->turn_servers()[i].ports[0].address.ToString()); |
| 120 | EXPECT_EQ(turn_servers[i].ports[0].proto, |
| 121 | raw_port_allocator_->turn_servers()[i].ports[0].proto); |
| 122 | EXPECT_EQ(turn_servers[i].credentials.username, |
| 123 | raw_port_allocator_->turn_servers()[i].credentials.username); |
| 124 | EXPECT_EQ(turn_servers[i].credentials.password, |
| 125 | raw_port_allocator_->turn_servers()[i].credentials.password); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 129 | rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 130 | NullPeerConnectionObserver observer_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 131 | std::unique_ptr<cricket::FakePortAllocator> port_allocator_; |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 132 | // Since the PC owns the port allocator after it's been initialized, |
| 133 | // this should only be used when known to be safe. |
| 134 | cricket::FakePortAllocator* raw_port_allocator_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | // Verify creation of PeerConnection using internal ADM, video factory and |
| 138 | // internal libjingle threads. |
henrika | 919dc2e | 2017-10-12 14:24:55 +0200 | [diff] [blame] | 139 | // TODO(henrika): disabling this test since relying on real audio can result in |
| 140 | // flaky tests and focus on details that are out of scope for you might expect |
| 141 | // for a PeerConnectionFactory unit test. |
| 142 | // See https://bugs.chromium.org/p/webrtc/issues/detail?id=7806 for details. |
| 143 | TEST(PeerConnectionFactoryTestInternal, DISABLED_CreatePCUsingInternalModules) { |
phoglund | 37ebcf0 | 2016-01-08 05:04:57 -0800 | [diff] [blame] | 144 | #ifdef WEBRTC_ANDROID |
| 145 | webrtc::InitializeAndroidObjects(); |
| 146 | #endif |
| 147 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 148 | rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
Karl Wiberg | 1b0eae3 | 2017-10-17 14:48:54 +0200 | [diff] [blame] | 149 | webrtc::CreatePeerConnectionFactory( |
| 150 | webrtc::CreateBuiltinAudioEncoderFactory(), |
| 151 | webrtc::CreateBuiltinAudioDecoderFactory())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 152 | |
| 153 | NullPeerConnectionObserver observer; |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 154 | webrtc::PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 155 | |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 156 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 157 | new FakeRTCCertificateGenerator()); |
| 158 | rtc::scoped_refptr<PeerConnectionInterface> pc(factory->CreatePeerConnection( |
| 159 | config, nullptr, nullptr, std::move(cert_generator), &observer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 160 | |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 161 | EXPECT_TRUE(pc.get() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | // This test verifies creation of PeerConnection with valid STUN and TURN |
| 165 | // configuration. Also verifies the URL's parsed correctly as expected. |
| 166 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServers) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 167 | PeerConnectionInterface::RTCConfiguration config; |
| 168 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 169 | ice_server.uri = kStunIceServer; |
| 170 | config.servers.push_back(ice_server); |
| 171 | ice_server.uri = kTurnIceServer; |
| 172 | ice_server.password = kTurnPassword; |
| 173 | config.servers.push_back(ice_server); |
| 174 | ice_server.uri = kTurnIceServerWithTransport; |
| 175 | ice_server.password = kTurnPassword; |
| 176 | config.servers.push_back(ice_server); |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 177 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 178 | new FakeRTCCertificateGenerator()); |
| 179 | rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
| 180 | config, nullptr, std::move(port_allocator_), std::move(cert_generator), |
| 181 | &observer_)); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 182 | ASSERT_TRUE(pc.get() != NULL); |
| 183 | cricket::ServerAddresses stun_servers; |
| 184 | rtc::SocketAddress stun1("stun.l.google.com", 19302); |
| 185 | stun_servers.insert(stun1); |
| 186 | VerifyStunServers(stun_servers); |
| 187 | std::vector<cricket::RelayServerConfig> turn_servers; |
| 188 | cricket::RelayServerConfig turn1("test.com", 1234, "test@hello.com", |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 189 | kTurnPassword, cricket::PROTO_UDP); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 190 | turn_servers.push_back(turn1); |
| 191 | cricket::RelayServerConfig turn2("hello.com", kDefaultStunPort, "test", |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 192 | kTurnPassword, cricket::PROTO_TCP); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 193 | turn_servers.push_back(turn2); |
| 194 | VerifyTurnServers(turn_servers); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | // This test verifies creation of PeerConnection with valid STUN and TURN |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 198 | // configuration. Also verifies the list of URL's parsed correctly as expected. |
| 199 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersUrls) { |
| 200 | PeerConnectionInterface::RTCConfiguration config; |
| 201 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 202 | ice_server.urls.push_back(kStunIceServer); |
| 203 | ice_server.urls.push_back(kTurnIceServer); |
| 204 | ice_server.urls.push_back(kTurnIceServerWithTransport); |
| 205 | ice_server.password = kTurnPassword; |
| 206 | config.servers.push_back(ice_server); |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 207 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 208 | new FakeRTCCertificateGenerator()); |
| 209 | rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
| 210 | config, nullptr, std::move(port_allocator_), std::move(cert_generator), |
| 211 | &observer_)); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 212 | ASSERT_TRUE(pc.get() != NULL); |
| 213 | cricket::ServerAddresses stun_servers; |
| 214 | rtc::SocketAddress stun1("stun.l.google.com", 19302); |
| 215 | stun_servers.insert(stun1); |
| 216 | VerifyStunServers(stun_servers); |
| 217 | std::vector<cricket::RelayServerConfig> turn_servers; |
| 218 | cricket::RelayServerConfig turn1("test.com", 1234, "test@hello.com", |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 219 | kTurnPassword, cricket::PROTO_UDP); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 220 | turn_servers.push_back(turn1); |
| 221 | cricket::RelayServerConfig turn2("hello.com", kDefaultStunPort, "test", |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 222 | kTurnPassword, cricket::PROTO_TCP); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 223 | turn_servers.push_back(turn2); |
| 224 | VerifyTurnServers(turn_servers); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 228 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 229 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 230 | ice_server.uri = kStunIceServer; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 231 | config.servers.push_back(ice_server); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 232 | ice_server.uri = kTurnIceServerWithNoUsernameInUri; |
| 233 | ice_server.username = kTurnUsername; |
| 234 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 235 | config.servers.push_back(ice_server); |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 236 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 237 | new FakeRTCCertificateGenerator()); |
| 238 | rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
| 239 | config, nullptr, std::move(port_allocator_), std::move(cert_generator), |
| 240 | &observer_)); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 241 | ASSERT_TRUE(pc.get() != NULL); |
| 242 | std::vector<cricket::RelayServerConfig> turn_servers; |
| 243 | cricket::RelayServerConfig turn("test.com", 1234, kTurnUsername, |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 244 | kTurnPassword, cricket::PROTO_UDP); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 245 | turn_servers.push_back(turn); |
| 246 | VerifyTurnServers(turn_servers); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | // This test verifies the PeerConnection created properly with TURN url which |
| 250 | // has transport parameter in it. |
| 251 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingTurnUrlWithTransportParam) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 252 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 253 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 254 | ice_server.uri = kTurnIceServerWithTransport; |
| 255 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 256 | config.servers.push_back(ice_server); |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 257 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 258 | new FakeRTCCertificateGenerator()); |
| 259 | rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
| 260 | config, nullptr, std::move(port_allocator_), std::move(cert_generator), |
| 261 | &observer_)); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 262 | ASSERT_TRUE(pc.get() != NULL); |
| 263 | std::vector<cricket::RelayServerConfig> turn_servers; |
| 264 | cricket::RelayServerConfig turn("hello.com", kDefaultStunPort, "test", |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 265 | kTurnPassword, cricket::PROTO_TCP); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 266 | turn_servers.push_back(turn); |
| 267 | VerifyTurnServers(turn_servers); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 268 | } |
| 269 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 270 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 271 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 272 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 273 | ice_server.uri = kSecureTurnIceServer; |
| 274 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 275 | config.servers.push_back(ice_server); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 276 | ice_server.uri = kSecureTurnIceServerWithoutTransportParam; |
| 277 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 278 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 279 | ice_server.uri = kSecureTurnIceServerWithoutTransportAndPortParam; |
| 280 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 281 | config.servers.push_back(ice_server); |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 282 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 283 | new FakeRTCCertificateGenerator()); |
| 284 | rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
| 285 | config, nullptr, std::move(port_allocator_), std::move(cert_generator), |
| 286 | &observer_)); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 287 | ASSERT_TRUE(pc.get() != NULL); |
| 288 | std::vector<cricket::RelayServerConfig> turn_servers; |
| 289 | cricket::RelayServerConfig turn1("hello.com", kDefaultStunTlsPort, "test", |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 290 | kTurnPassword, cricket::PROTO_TLS); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 291 | turn_servers.push_back(turn1); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 292 | // TURNS with transport param should be default to tcp. |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 293 | cricket::RelayServerConfig turn2("hello.com", 443, "test_no_transport", |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 294 | kTurnPassword, cricket::PROTO_TLS); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 295 | turn_servers.push_back(turn2); |
| 296 | cricket::RelayServerConfig turn3("hello.com", kDefaultStunTlsPort, |
| 297 | "test_no_transport", kTurnPassword, |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 298 | cricket::PROTO_TLS); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 299 | turn_servers.push_back(turn3); |
| 300 | VerifyTurnServers(turn_servers); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 301 | } |
| 302 | |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 303 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 304 | PeerConnectionInterface::RTCConfiguration config; |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 305 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 306 | ice_server.uri = kStunIceServerWithIPv4Address; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 307 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 308 | ice_server.uri = kStunIceServerWithIPv4AddressWithoutPort; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 309 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 310 | ice_server.uri = kStunIceServerWithIPv6Address; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 311 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 312 | ice_server.uri = kStunIceServerWithIPv6AddressWithoutPort; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 313 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 314 | ice_server.uri = kTurnIceServerWithIPv6Address; |
| 315 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 316 | config.servers.push_back(ice_server); |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 317 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 318 | new FakeRTCCertificateGenerator()); |
| 319 | rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
| 320 | config, nullptr, std::move(port_allocator_), std::move(cert_generator), |
| 321 | &observer_)); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 322 | ASSERT_TRUE(pc.get() != NULL); |
| 323 | cricket::ServerAddresses stun_servers; |
| 324 | rtc::SocketAddress stun1("1.2.3.4", 1234); |
| 325 | stun_servers.insert(stun1); |
| 326 | rtc::SocketAddress stun2("1.2.3.4", 3478); |
| 327 | stun_servers.insert(stun2); // Default port |
| 328 | rtc::SocketAddress stun3("2401:fa00:4::", 1234); |
| 329 | stun_servers.insert(stun3); |
| 330 | rtc::SocketAddress stun4("2401:fa00:4::", 3478); |
| 331 | stun_servers.insert(stun4); // Default port |
| 332 | VerifyStunServers(stun_servers); |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 333 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 334 | std::vector<cricket::RelayServerConfig> turn_servers; |
| 335 | cricket::RelayServerConfig turn1("2401:fa00:4::", 1234, "test", kTurnPassword, |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 336 | cricket::PROTO_UDP); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 337 | turn_servers.push_back(turn1); |
| 338 | VerifyTurnServers(turn_servers); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 339 | } |
| 340 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 341 | // This test verifies the captured stream is rendered locally using a |
| 342 | // local video track. |
| 343 | TEST_F(PeerConnectionFactoryTest, LocalRendering) { |
| 344 | cricket::FakeVideoCapturer* capturer = new cricket::FakeVideoCapturer(); |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 345 | // The source takes ownership of |capturer|, but we keep a raw pointer to |
| 346 | // inject fake frames. |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 347 | rtc::scoped_refptr<VideoTrackSourceInterface> source( |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 348 | factory_->CreateVideoSource( |
| 349 | std::unique_ptr<cricket::VideoCapturer>(capturer), NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 350 | ASSERT_TRUE(source.get() != NULL); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 351 | rtc::scoped_refptr<VideoTrackInterface> track( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 352 | factory_->CreateVideoTrack("testlabel", source)); |
| 353 | ASSERT_TRUE(track.get() != NULL); |
| 354 | FakeVideoTrackRenderer local_renderer(track); |
| 355 | |
| 356 | EXPECT_EQ(0, local_renderer.num_rendered_frames()); |
| 357 | EXPECT_TRUE(capturer->CaptureFrame()); |
| 358 | EXPECT_EQ(1, local_renderer.num_rendered_frames()); |
nisse | 81354f5 | 2016-01-19 00:23:24 -0800 | [diff] [blame] | 359 | EXPECT_FALSE(local_renderer.black_frame()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 360 | |
| 361 | track->set_enabled(false); |
| 362 | EXPECT_TRUE(capturer->CaptureFrame()); |
nisse | 81354f5 | 2016-01-19 00:23:24 -0800 | [diff] [blame] | 363 | EXPECT_EQ(2, local_renderer.num_rendered_frames()); |
| 364 | EXPECT_TRUE(local_renderer.black_frame()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 365 | |
| 366 | track->set_enabled(true); |
| 367 | EXPECT_TRUE(capturer->CaptureFrame()); |
nisse | 81354f5 | 2016-01-19 00:23:24 -0800 | [diff] [blame] | 368 | EXPECT_EQ(3, local_renderer.num_rendered_frames()); |
| 369 | EXPECT_FALSE(local_renderer.black_frame()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 370 | } |