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 | |
Florent Castelli | 72b751a | 2018-06-28 14:09:33 +0200 | [diff] [blame] | 133 | void VerifyAudioCodecCapability(const webrtc::RtpCodecCapability& codec) { |
| 134 | EXPECT_EQ(codec.kind, cricket::MEDIA_TYPE_AUDIO); |
| 135 | EXPECT_FALSE(codec.name.empty()); |
| 136 | EXPECT_GT(codec.clock_rate, 0); |
| 137 | EXPECT_GT(codec.num_channels, 0); |
| 138 | } |
| 139 | |
| 140 | void VerifyVideoCodecCapability(const webrtc::RtpCodecCapability& codec) { |
| 141 | EXPECT_EQ(codec.kind, cricket::MEDIA_TYPE_VIDEO); |
| 142 | EXPECT_FALSE(codec.name.empty()); |
| 143 | EXPECT_GT(codec.clock_rate, 0); |
| 144 | } |
| 145 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 146 | rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 147 | NullPeerConnectionObserver observer_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 148 | std::unique_ptr<cricket::FakePortAllocator> port_allocator_; |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 149 | // Since the PC owns the port allocator after it's been initialized, |
| 150 | // this should only be used when known to be safe. |
| 151 | cricket::FakePortAllocator* raw_port_allocator_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | // Verify creation of PeerConnection using internal ADM, video factory and |
| 155 | // internal libjingle threads. |
henrika | 919dc2e | 2017-10-12 14:24:55 +0200 | [diff] [blame] | 156 | // TODO(henrika): disabling this test since relying on real audio can result in |
| 157 | // flaky tests and focus on details that are out of scope for you might expect |
| 158 | // for a PeerConnectionFactory unit test. |
| 159 | // See https://bugs.chromium.org/p/webrtc/issues/detail?id=7806 for details. |
| 160 | TEST(PeerConnectionFactoryTestInternal, DISABLED_CreatePCUsingInternalModules) { |
phoglund | 37ebcf0 | 2016-01-08 05:04:57 -0800 | [diff] [blame] | 161 | #ifdef WEBRTC_ANDROID |
| 162 | webrtc::InitializeAndroidObjects(); |
| 163 | #endif |
| 164 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 165 | rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
Karl Wiberg | 1b0eae3 | 2017-10-17 14:48:54 +0200 | [diff] [blame] | 166 | webrtc::CreatePeerConnectionFactory( |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 167 | nullptr /* network_thread */, nullptr /* worker_thread */, |
| 168 | nullptr /* signaling_thread */, nullptr /* default_adm */, |
Karl Wiberg | 1b0eae3 | 2017-10-17 14:48:54 +0200 | [diff] [blame] | 169 | webrtc::CreateBuiltinAudioEncoderFactory(), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 170 | webrtc::CreateBuiltinAudioDecoderFactory(), |
| 171 | webrtc::CreateBuiltinVideoEncoderFactory(), |
| 172 | webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */, |
| 173 | nullptr /* audio_processing */)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 174 | |
| 175 | NullPeerConnectionObserver observer; |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 176 | webrtc::PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 177 | |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 178 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 179 | new FakeRTCCertificateGenerator()); |
| 180 | rtc::scoped_refptr<PeerConnectionInterface> pc(factory->CreatePeerConnection( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame^] | 181 | config, nullptr, std::move(cert_generator), &observer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 182 | |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 183 | EXPECT_TRUE(pc.get() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Florent Castelli | 72b751a | 2018-06-28 14:09:33 +0200 | [diff] [blame] | 186 | TEST_F(PeerConnectionFactoryTest, CheckRtpSenderAudioCapabilities) { |
| 187 | webrtc::RtpCapabilities audio_capabilities = |
| 188 | factory_->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_AUDIO); |
| 189 | EXPECT_FALSE(audio_capabilities.codecs.empty()); |
| 190 | for (const auto& codec : audio_capabilities.codecs) { |
| 191 | VerifyAudioCodecCapability(codec); |
| 192 | } |
| 193 | EXPECT_FALSE(audio_capabilities.header_extensions.empty()); |
| 194 | for (const auto& header_extension : audio_capabilities.header_extensions) { |
| 195 | EXPECT_FALSE(header_extension.uri.empty()); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | TEST_F(PeerConnectionFactoryTest, CheckRtpSenderVideoCapabilities) { |
| 200 | webrtc::RtpCapabilities video_capabilities = |
| 201 | factory_->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_VIDEO); |
| 202 | EXPECT_FALSE(video_capabilities.codecs.empty()); |
| 203 | for (const auto& codec : video_capabilities.codecs) { |
| 204 | VerifyVideoCodecCapability(codec); |
| 205 | } |
| 206 | EXPECT_FALSE(video_capabilities.header_extensions.empty()); |
| 207 | for (const auto& header_extension : video_capabilities.header_extensions) { |
| 208 | EXPECT_FALSE(header_extension.uri.empty()); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | TEST_F(PeerConnectionFactoryTest, CheckRtpSenderDataCapabilities) { |
| 213 | webrtc::RtpCapabilities data_capabilities = |
| 214 | factory_->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_DATA); |
| 215 | EXPECT_TRUE(data_capabilities.codecs.empty()); |
| 216 | EXPECT_TRUE(data_capabilities.header_extensions.empty()); |
| 217 | } |
| 218 | |
| 219 | TEST_F(PeerConnectionFactoryTest, CheckRtpReceiverAudioCapabilities) { |
| 220 | webrtc::RtpCapabilities audio_capabilities = |
| 221 | factory_->GetRtpReceiverCapabilities(cricket::MEDIA_TYPE_AUDIO); |
| 222 | EXPECT_FALSE(audio_capabilities.codecs.empty()); |
| 223 | for (const auto& codec : audio_capabilities.codecs) { |
| 224 | VerifyAudioCodecCapability(codec); |
| 225 | } |
| 226 | EXPECT_FALSE(audio_capabilities.header_extensions.empty()); |
| 227 | for (const auto& header_extension : audio_capabilities.header_extensions) { |
| 228 | EXPECT_FALSE(header_extension.uri.empty()); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | TEST_F(PeerConnectionFactoryTest, CheckRtpReceiverVideoCapabilities) { |
| 233 | webrtc::RtpCapabilities video_capabilities = |
| 234 | factory_->GetRtpReceiverCapabilities(cricket::MEDIA_TYPE_VIDEO); |
| 235 | EXPECT_FALSE(video_capabilities.codecs.empty()); |
| 236 | for (const auto& codec : video_capabilities.codecs) { |
| 237 | VerifyVideoCodecCapability(codec); |
| 238 | } |
| 239 | EXPECT_FALSE(video_capabilities.header_extensions.empty()); |
| 240 | for (const auto& header_extension : video_capabilities.header_extensions) { |
| 241 | EXPECT_FALSE(header_extension.uri.empty()); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | TEST_F(PeerConnectionFactoryTest, CheckRtpReceiverDataCapabilities) { |
| 246 | webrtc::RtpCapabilities data_capabilities = |
| 247 | factory_->GetRtpReceiverCapabilities(cricket::MEDIA_TYPE_DATA); |
| 248 | EXPECT_TRUE(data_capabilities.codecs.empty()); |
| 249 | EXPECT_TRUE(data_capabilities.header_extensions.empty()); |
| 250 | } |
| 251 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 252 | // This test verifies creation of PeerConnection with valid STUN and TURN |
| 253 | // configuration. Also verifies the URL's parsed correctly as expected. |
| 254 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServers) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 255 | PeerConnectionInterface::RTCConfiguration config; |
| 256 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 257 | ice_server.uri = kStunIceServer; |
| 258 | config.servers.push_back(ice_server); |
| 259 | ice_server.uri = kTurnIceServer; |
| 260 | ice_server.password = kTurnPassword; |
| 261 | config.servers.push_back(ice_server); |
| 262 | ice_server.uri = kTurnIceServerWithTransport; |
| 263 | ice_server.password = kTurnPassword; |
| 264 | config.servers.push_back(ice_server); |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 265 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 266 | new FakeRTCCertificateGenerator()); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame^] | 267 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
| 268 | factory_->CreatePeerConnection(config, std::move(port_allocator_), |
| 269 | std::move(cert_generator), &observer_)); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 270 | ASSERT_TRUE(pc.get() != NULL); |
| 271 | cricket::ServerAddresses stun_servers; |
| 272 | rtc::SocketAddress stun1("stun.l.google.com", 19302); |
| 273 | stun_servers.insert(stun1); |
| 274 | VerifyStunServers(stun_servers); |
| 275 | std::vector<cricket::RelayServerConfig> turn_servers; |
| 276 | cricket::RelayServerConfig turn1("test.com", 1234, "test@hello.com", |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 277 | kTurnPassword, cricket::PROTO_UDP); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 278 | turn_servers.push_back(turn1); |
| 279 | cricket::RelayServerConfig turn2("hello.com", kDefaultStunPort, "test", |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 280 | kTurnPassword, cricket::PROTO_TCP); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 281 | turn_servers.push_back(turn2); |
| 282 | VerifyTurnServers(turn_servers); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | // This test verifies creation of PeerConnection with valid STUN and TURN |
Joachim Bauch | 7c4e745 | 2015-05-28 23:06:30 +0200 | [diff] [blame] | 286 | // configuration. Also verifies the list of URL's parsed correctly as expected. |
| 287 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersUrls) { |
| 288 | PeerConnectionInterface::RTCConfiguration config; |
| 289 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 290 | ice_server.urls.push_back(kStunIceServer); |
| 291 | ice_server.urls.push_back(kTurnIceServer); |
| 292 | ice_server.urls.push_back(kTurnIceServerWithTransport); |
| 293 | ice_server.password = kTurnPassword; |
| 294 | config.servers.push_back(ice_server); |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 295 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 296 | new FakeRTCCertificateGenerator()); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame^] | 297 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
| 298 | factory_->CreatePeerConnection(config, std::move(port_allocator_), |
| 299 | std::move(cert_generator), &observer_)); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 300 | ASSERT_TRUE(pc.get() != NULL); |
| 301 | cricket::ServerAddresses stun_servers; |
| 302 | rtc::SocketAddress stun1("stun.l.google.com", 19302); |
| 303 | stun_servers.insert(stun1); |
| 304 | VerifyStunServers(stun_servers); |
| 305 | std::vector<cricket::RelayServerConfig> turn_servers; |
| 306 | cricket::RelayServerConfig turn1("test.com", 1234, "test@hello.com", |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 307 | kTurnPassword, cricket::PROTO_UDP); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 308 | turn_servers.push_back(turn1); |
| 309 | cricket::RelayServerConfig turn2("hello.com", kDefaultStunPort, "test", |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 310 | kTurnPassword, cricket::PROTO_TCP); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 311 | turn_servers.push_back(turn2); |
| 312 | VerifyTurnServers(turn_servers); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 316 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 317 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 318 | ice_server.uri = kStunIceServer; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 319 | config.servers.push_back(ice_server); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 320 | ice_server.uri = kTurnIceServerWithNoUsernameInUri; |
| 321 | ice_server.username = kTurnUsername; |
| 322 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 323 | config.servers.push_back(ice_server); |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 324 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 325 | new FakeRTCCertificateGenerator()); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame^] | 326 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
| 327 | factory_->CreatePeerConnection(config, std::move(port_allocator_), |
| 328 | std::move(cert_generator), &observer_)); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 329 | ASSERT_TRUE(pc.get() != NULL); |
| 330 | std::vector<cricket::RelayServerConfig> turn_servers; |
| 331 | cricket::RelayServerConfig turn("test.com", 1234, kTurnUsername, |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 332 | kTurnPassword, cricket::PROTO_UDP); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 333 | turn_servers.push_back(turn); |
| 334 | VerifyTurnServers(turn_servers); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | // This test verifies the PeerConnection created properly with TURN url which |
| 338 | // has transport parameter in it. |
| 339 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingTurnUrlWithTransportParam) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 340 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 341 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 342 | ice_server.uri = kTurnIceServerWithTransport; |
| 343 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 344 | config.servers.push_back(ice_server); |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 345 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 346 | new FakeRTCCertificateGenerator()); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame^] | 347 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
| 348 | factory_->CreatePeerConnection(config, std::move(port_allocator_), |
| 349 | std::move(cert_generator), &observer_)); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 350 | ASSERT_TRUE(pc.get() != NULL); |
| 351 | std::vector<cricket::RelayServerConfig> turn_servers; |
| 352 | cricket::RelayServerConfig turn("hello.com", kDefaultStunPort, "test", |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 353 | kTurnPassword, cricket::PROTO_TCP); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 354 | turn_servers.push_back(turn); |
| 355 | VerifyTurnServers(turn_servers); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 356 | } |
| 357 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 358 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 359 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 360 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 361 | ice_server.uri = kSecureTurnIceServer; |
| 362 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 363 | config.servers.push_back(ice_server); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 364 | ice_server.uri = kSecureTurnIceServerWithoutTransportParam; |
| 365 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 366 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 367 | ice_server.uri = kSecureTurnIceServerWithoutTransportAndPortParam; |
| 368 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 369 | config.servers.push_back(ice_server); |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 370 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 371 | new FakeRTCCertificateGenerator()); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame^] | 372 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
| 373 | factory_->CreatePeerConnection(config, std::move(port_allocator_), |
| 374 | std::move(cert_generator), &observer_)); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 375 | ASSERT_TRUE(pc.get() != NULL); |
| 376 | std::vector<cricket::RelayServerConfig> turn_servers; |
| 377 | cricket::RelayServerConfig turn1("hello.com", kDefaultStunTlsPort, "test", |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 378 | kTurnPassword, cricket::PROTO_TLS); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 379 | turn_servers.push_back(turn1); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 380 | // TURNS with transport param should be default to tcp. |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 381 | cricket::RelayServerConfig turn2("hello.com", 443, "test_no_transport", |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 382 | kTurnPassword, cricket::PROTO_TLS); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 383 | turn_servers.push_back(turn2); |
| 384 | cricket::RelayServerConfig turn3("hello.com", kDefaultStunTlsPort, |
| 385 | "test_no_transport", kTurnPassword, |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 386 | cricket::PROTO_TLS); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 387 | turn_servers.push_back(turn3); |
| 388 | VerifyTurnServers(turn_servers); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 389 | } |
| 390 | |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 391 | TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 392 | PeerConnectionInterface::RTCConfiguration config; |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 393 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 394 | ice_server.uri = kStunIceServerWithIPv4Address; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 395 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 396 | ice_server.uri = kStunIceServerWithIPv4AddressWithoutPort; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 397 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 398 | ice_server.uri = kStunIceServerWithIPv6Address; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 399 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 400 | ice_server.uri = kStunIceServerWithIPv6AddressWithoutPort; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 401 | config.servers.push_back(ice_server); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 402 | ice_server.uri = kTurnIceServerWithIPv6Address; |
| 403 | ice_server.password = kTurnPassword; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 404 | config.servers.push_back(ice_server); |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 405 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 406 | new FakeRTCCertificateGenerator()); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame^] | 407 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
| 408 | factory_->CreatePeerConnection(config, std::move(port_allocator_), |
| 409 | std::move(cert_generator), &observer_)); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 410 | ASSERT_TRUE(pc.get() != NULL); |
| 411 | cricket::ServerAddresses stun_servers; |
| 412 | rtc::SocketAddress stun1("1.2.3.4", 1234); |
| 413 | stun_servers.insert(stun1); |
| 414 | rtc::SocketAddress stun2("1.2.3.4", 3478); |
| 415 | stun_servers.insert(stun2); // Default port |
| 416 | rtc::SocketAddress stun3("2401:fa00:4::", 1234); |
| 417 | stun_servers.insert(stun3); |
| 418 | rtc::SocketAddress stun4("2401:fa00:4::", 3478); |
| 419 | stun_servers.insert(stun4); // Default port |
| 420 | VerifyStunServers(stun_servers); |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 421 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 422 | std::vector<cricket::RelayServerConfig> turn_servers; |
| 423 | cricket::RelayServerConfig turn1("2401:fa00:4::", 1234, "test", kTurnPassword, |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 424 | cricket::PROTO_UDP); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 425 | turn_servers.push_back(turn1); |
| 426 | VerifyTurnServers(turn_servers); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 427 | } |
| 428 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 429 | // This test verifies the captured stream is rendered locally using a |
| 430 | // local video track. |
| 431 | TEST_F(PeerConnectionFactoryTest, LocalRendering) { |
Tommi | 1829af6 | 2018-02-06 09:29:17 +0100 | [diff] [blame] | 432 | cricket::FakeVideoCapturerWithTaskQueue* capturer = |
| 433 | new cricket::FakeVideoCapturerWithTaskQueue(); |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 434 | // The source takes ownership of |capturer|, but we keep a raw pointer to |
| 435 | // inject fake frames. |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 436 | rtc::scoped_refptr<VideoTrackSourceInterface> source( |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 437 | factory_->CreateVideoSource( |
| 438 | std::unique_ptr<cricket::VideoCapturer>(capturer), NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 439 | ASSERT_TRUE(source.get() != NULL); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 440 | rtc::scoped_refptr<VideoTrackInterface> track( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 441 | factory_->CreateVideoTrack("testlabel", source)); |
| 442 | ASSERT_TRUE(track.get() != NULL); |
| 443 | FakeVideoTrackRenderer local_renderer(track); |
| 444 | |
| 445 | EXPECT_EQ(0, local_renderer.num_rendered_frames()); |
| 446 | EXPECT_TRUE(capturer->CaptureFrame()); |
| 447 | EXPECT_EQ(1, local_renderer.num_rendered_frames()); |
nisse | 81354f5 | 2016-01-19 00:23:24 -0800 | [diff] [blame] | 448 | EXPECT_FALSE(local_renderer.black_frame()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 449 | |
| 450 | track->set_enabled(false); |
| 451 | EXPECT_TRUE(capturer->CaptureFrame()); |
nisse | 81354f5 | 2016-01-19 00:23:24 -0800 | [diff] [blame] | 452 | EXPECT_EQ(2, local_renderer.num_rendered_frames()); |
| 453 | EXPECT_TRUE(local_renderer.black_frame()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 454 | |
| 455 | track->set_enabled(true); |
| 456 | EXPECT_TRUE(capturer->CaptureFrame()); |
nisse | 81354f5 | 2016-01-19 00:23:24 -0800 | [diff] [blame] | 457 | EXPECT_EQ(3, local_renderer.num_rendered_frames()); |
| 458 | EXPECT_FALSE(local_renderer.black_frame()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 459 | } |