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