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