| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 * this list of conditions and the following disclaimer in the documentation | 11 * this list of conditions and the following disclaimer in the documentation |
| 12 * and/or other materials provided with the distribution. | 12 * and/or other materials provided with the distribution. |
| 13 * 3. The name of the author may not be used to endorse or promote products | 13 * 3. The name of the author may not be used to endorse or promote products |
| 14 * derived from this software without specific prior written permission. | 14 * derived from this software without specific prior written permission. |
| 15 * | 15 * |
| 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "talk/app/webrtc/audiotrack.h" | 28 #include "talk/app/webrtc/audiotrack.h" |
| 29 #include "talk/app/webrtc/fakemetricsobserver.h" |
| 29 #include "talk/app/webrtc/jsepicecandidate.h" | 30 #include "talk/app/webrtc/jsepicecandidate.h" |
| 30 #include "talk/app/webrtc/jsepsessiondescription.h" | 31 #include "talk/app/webrtc/jsepsessiondescription.h" |
| 31 #include "talk/app/webrtc/mediastreamsignaling.h" | 32 #include "talk/app/webrtc/mediastreamsignaling.h" |
| 32 #include "talk/app/webrtc/streamcollection.h" | 33 #include "talk/app/webrtc/streamcollection.h" |
| 33 #include "talk/app/webrtc/test/fakeconstraints.h" | 34 #include "talk/app/webrtc/test/fakeconstraints.h" |
| 34 #include "talk/app/webrtc/test/fakedtlsidentityservice.h" | 35 #include "talk/app/webrtc/test/fakedtlsidentityservice.h" |
| 35 #include "talk/app/webrtc/test/fakemediastreamsignaling.h" | 36 #include "talk/app/webrtc/test/fakemediastreamsignaling.h" |
| 36 #include "talk/app/webrtc/videotrack.h" | 37 #include "talk/app/webrtc/videotrack.h" |
| 37 #include "talk/app/webrtc/webrtcsession.h" | 38 #include "talk/app/webrtc/webrtcsession.h" |
| 38 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h" | 39 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 using cricket::TransportInfo; | 75 using cricket::TransportInfo; |
| 75 using rtc::SocketAddress; | 76 using rtc::SocketAddress; |
| 76 using rtc::scoped_ptr; | 77 using rtc::scoped_ptr; |
| 77 using rtc::Thread; | 78 using rtc::Thread; |
| 78 using webrtc::CreateSessionDescription; | 79 using webrtc::CreateSessionDescription; |
| 79 using webrtc::CreateSessionDescriptionObserver; | 80 using webrtc::CreateSessionDescriptionObserver; |
| 80 using webrtc::CreateSessionDescriptionRequest; | 81 using webrtc::CreateSessionDescriptionRequest; |
| 81 using webrtc::DTLSIdentityRequestObserver; | 82 using webrtc::DTLSIdentityRequestObserver; |
| 82 using webrtc::DTLSIdentityServiceInterface; | 83 using webrtc::DTLSIdentityServiceInterface; |
| 83 using webrtc::FakeConstraints; | 84 using webrtc::FakeConstraints; |
| 85 using webrtc::FakeMetricsObserver; |
| 84 using webrtc::IceCandidateCollection; | 86 using webrtc::IceCandidateCollection; |
| 85 using webrtc::JsepIceCandidate; | 87 using webrtc::JsepIceCandidate; |
| 86 using webrtc::JsepSessionDescription; | 88 using webrtc::JsepSessionDescription; |
| 87 using webrtc::PeerConnectionFactoryInterface; | 89 using webrtc::PeerConnectionFactoryInterface; |
| 88 using webrtc::PeerConnectionInterface; | 90 using webrtc::PeerConnectionInterface; |
| 89 using webrtc::SessionDescriptionInterface; | 91 using webrtc::SessionDescriptionInterface; |
| 90 using webrtc::StreamCollection; | 92 using webrtc::StreamCollection; |
| 91 using webrtc::WebRtcSession; | 93 using webrtc::WebRtcSession; |
| 92 using webrtc::kBundleWithoutRtcpMux; | 94 using webrtc::kBundleWithoutRtcpMux; |
| 93 using webrtc::kCreateChannelFailed; | 95 using webrtc::kCreateChannelFailed; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 160 |
| 159 // Add some extra |newlines| to the |message| after |line|. | 161 // Add some extra |newlines| to the |message| after |line|. |
| 160 static void InjectAfter(const std::string& line, | 162 static void InjectAfter(const std::string& line, |
| 161 const std::string& newlines, | 163 const std::string& newlines, |
| 162 std::string* message) { | 164 std::string* message) { |
| 163 const std::string tmp = line + newlines; | 165 const std::string tmp = line + newlines; |
| 164 rtc::replace_substrs(line.c_str(), line.length(), | 166 rtc::replace_substrs(line.c_str(), line.length(), |
| 165 tmp.c_str(), tmp.length(), message); | 167 tmp.c_str(), tmp.length(), message); |
| 166 } | 168 } |
| 167 | 169 |
| 168 class FakeMetricsObserver : public webrtc::MetricsObserverInterface { | |
| 169 public: | |
| 170 FakeMetricsObserver() { Reset(); } | |
| 171 void Reset() { | |
| 172 memset(peer_connection_metrics_counters_, 0, | |
| 173 sizeof(peer_connection_metrics_counters_)); | |
| 174 memset(peer_connection_metrics_name_, 0, | |
| 175 sizeof(peer_connection_metrics_name_)); | |
| 176 } | |
| 177 | |
| 178 void IncrementCounter(webrtc::PeerConnectionMetricsCounter type) override { | |
| 179 peer_connection_metrics_counters_[type]++; | |
| 180 } | |
| 181 void AddHistogramSample(webrtc::PeerConnectionMetricsName type, | |
| 182 int value) override { | |
| 183 ASSERT(peer_connection_metrics_name_[type] == 0); | |
| 184 peer_connection_metrics_name_[type] = value; | |
| 185 } | |
| 186 | |
| 187 int peer_connection_metrics_counters_ | |
| 188 [webrtc::kPeerConnectionMetricsCounter_Max]; | |
| 189 int peer_connection_metrics_name_[webrtc::kPeerConnectionMetricsCounter_Max]; | |
| 190 | |
| 191 int AddRef() override { return 1; } | |
| 192 int Release() override { return 1; } | |
| 193 }; | |
| 194 | |
| 195 class MockIceObserver : public webrtc::IceObserver { | 170 class MockIceObserver : public webrtc::IceObserver { |
| 196 public: | 171 public: |
| 197 MockIceObserver() | 172 MockIceObserver() |
| 198 : oncandidatesready_(false), | 173 : oncandidatesready_(false), |
| 199 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), | 174 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), |
| 200 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) { | 175 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) { |
| 201 } | 176 } |
| 202 | 177 |
| 203 virtual void OnIceConnectionChange( | 178 virtual void OnIceConnectionChange( |
| 204 PeerConnectionInterface::IceConnectionState new_state) { | 179 PeerConnectionInterface::IceConnectionState new_state) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 channel_manager_.get(), tdesc_factory_.get())), | 328 channel_manager_.get(), tdesc_factory_.get())), |
| 354 pss_(new rtc::PhysicalSocketServer), | 329 pss_(new rtc::PhysicalSocketServer), |
| 355 vss_(new rtc::VirtualSocketServer(pss_.get())), | 330 vss_(new rtc::VirtualSocketServer(pss_.get())), |
| 356 fss_(new rtc::FirewallSocketServer(vss_.get())), | 331 fss_(new rtc::FirewallSocketServer(vss_.get())), |
| 357 ss_scope_(fss_.get()), | 332 ss_scope_(fss_.get()), |
| 358 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost, | 333 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost, |
| 359 cricket::STUN_SERVER_PORT)), | 334 cricket::STUN_SERVER_PORT)), |
| 360 stun_server_(cricket::TestStunServer::Create(Thread::Current(), | 335 stun_server_(cricket::TestStunServer::Create(Thread::Current(), |
| 361 stun_socket_addr_)), | 336 stun_socket_addr_)), |
| 362 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr), | 337 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr), |
| 363 mediastream_signaling_(channel_manager_.get()) { | 338 mediastream_signaling_(channel_manager_.get()), |
| 339 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) { |
| 364 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID); | 340 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID); |
| 365 | 341 |
| 366 cricket::ServerAddresses stun_servers; | 342 cricket::ServerAddresses stun_servers; |
| 367 stun_servers.insert(stun_socket_addr_); | 343 stun_servers.insert(stun_socket_addr_); |
| 368 allocator_.reset(new cricket::BasicPortAllocator( | 344 allocator_.reset(new cricket::BasicPortAllocator( |
| 369 &network_manager_, | 345 &network_manager_, |
| 370 stun_servers, | 346 stun_servers, |
| 371 SocketAddress(), SocketAddress(), SocketAddress())); | 347 SocketAddress(), SocketAddress(), SocketAddress())); |
| 372 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | | 348 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
| 373 cricket::PORTALLOCATOR_DISABLE_RELAY | | 349 cricket::PORTALLOCATOR_DISABLE_RELAY | |
| (...skipping 17 matching lines...) Expand all Loading... |
| 391 &observer_, | 367 &observer_, |
| 392 &mediastream_signaling_)); | 368 &mediastream_signaling_)); |
| 393 | 369 |
| 394 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, | 370 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 395 observer_.ice_connection_state_); | 371 observer_.ice_connection_state_); |
| 396 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, | 372 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 397 observer_.ice_gathering_state_); | 373 observer_.ice_gathering_state_); |
| 398 | 374 |
| 399 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(), | 375 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(), |
| 400 identity_service, rtc_configuration)); | 376 identity_service, rtc_configuration)); |
| 401 session_->set_metrics_observer(&metrics_observer_); | 377 session_->set_metrics_observer(metrics_observer_); |
| 402 } | 378 } |
| 403 | 379 |
| 404 void Init() { | 380 void Init() { |
| 405 PeerConnectionInterface::RTCConfiguration configuration; | 381 PeerConnectionInterface::RTCConfiguration configuration; |
| 406 Init(NULL, configuration); | 382 Init(NULL, configuration); |
| 407 } | 383 } |
| 408 | 384 |
| 409 void InitWithIceTransport( | 385 void InitWithIceTransport( |
| 410 PeerConnectionInterface::IceTransportsType ice_transport_type) { | 386 PeerConnectionInterface::IceTransportsType ice_transport_type) { |
| 411 PeerConnectionInterface::RTCConfiguration configuration; | 387 PeerConnectionInterface::RTCConfiguration configuration; |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 | 991 |
| 1016 int ipv4_count_; | 992 int ipv4_count_; |
| 1017 int ipv6_count_; | 993 int ipv6_count_; |
| 1018 }; | 994 }; |
| 1019 | 995 |
| 1020 bool test_ipv6_network_; | 996 bool test_ipv6_network_; |
| 1021 bool test_extra_ipv4_network_; | 997 bool test_extra_ipv4_network_; |
| 1022 ExpectedBestConnection best_connection_after_initial_ice_converged_; | 998 ExpectedBestConnection best_connection_after_initial_ice_converged_; |
| 1023 | 999 |
| 1024 void VerifyBestConnectionAfterIceConverge( | 1000 void VerifyBestConnectionAfterIceConverge( |
| 1025 const FakeMetricsObserver& metrics_observer) const { | 1001 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const { |
| 1026 Verify(metrics_observer, best_connection_after_initial_ice_converged_); | 1002 Verify(metrics_observer, best_connection_after_initial_ice_converged_); |
| 1027 } | 1003 } |
| 1028 | 1004 |
| 1029 private: | 1005 private: |
| 1030 void Verify(const FakeMetricsObserver& metrics_observer, | 1006 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer, |
| 1031 const ExpectedBestConnection& expected) const { | 1007 const ExpectedBestConnection& expected) const { |
| 1032 EXPECT_EQ( | 1008 EXPECT_EQ( |
| 1033 metrics_observer | 1009 metrics_observer->GetCounter(webrtc::kBestConnections_IPv4), |
| 1034 .peer_connection_metrics_counters_[webrtc::kBestConnections_IPv4], | |
| 1035 expected.ipv4_count_); | 1010 expected.ipv4_count_); |
| 1036 EXPECT_EQ( | 1011 EXPECT_EQ( |
| 1037 metrics_observer | 1012 metrics_observer->GetCounter(webrtc::kBestConnections_IPv6), |
| 1038 .peer_connection_metrics_counters_[webrtc::kBestConnections_IPv6], | |
| 1039 expected.ipv6_count_); | 1013 expected.ipv6_count_); |
| 1040 } | 1014 } |
| 1041 }; | 1015 }; |
| 1042 | 1016 |
| 1043 class LoopbackNetworkManager { | 1017 class LoopbackNetworkManager { |
| 1044 public: | 1018 public: |
| 1045 LoopbackNetworkManager(WebRtcSessionTest* session, | 1019 LoopbackNetworkManager(WebRtcSessionTest* session, |
| 1046 const LoopbackNetworkConfiguration& config) | 1020 const LoopbackNetworkConfiguration& config) |
| 1047 : config_(config) { | 1021 : config_(config) { |
| 1048 session->AddInterface( | 1022 session->AddInterface( |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 // Adding firewall rule to block ping requests, which should cause | 1102 // Adding firewall rule to block ping requests, which should cause |
| 1129 // transport channel failure. | 1103 // transport channel failure. |
| 1130 | 1104 |
| 1131 loopback_network_manager.ApplyFirewallRules(fss_.get()); | 1105 loopback_network_manager.ApplyFirewallRules(fss_.get()); |
| 1132 | 1106 |
| 1133 LOG(LS_INFO) << "Firewall Rules applied"; | 1107 LOG(LS_INFO) << "Firewall Rules applied"; |
| 1134 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, | 1108 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 1135 observer_.ice_connection_state_, | 1109 observer_.ice_connection_state_, |
| 1136 kIceCandidatesTimeout); | 1110 kIceCandidatesTimeout); |
| 1137 | 1111 |
| 1138 metrics_observer_.Reset(); | 1112 metrics_observer_->Reset(); |
| 1139 | 1113 |
| 1140 // Clearing the rules, session should move back to completed state. | 1114 // Clearing the rules, session should move back to completed state. |
| 1141 loopback_network_manager.ClearRules(fss_.get()); | 1115 loopback_network_manager.ClearRules(fss_.get()); |
| 1142 // Session is automatically calling OnSignalingReady after creation of | 1116 // Session is automatically calling OnSignalingReady after creation of |
| 1143 // new portallocator session which will allocate new set of candidates. | 1117 // new portallocator session which will allocate new set of candidates. |
| 1144 | 1118 |
| 1145 LOG(LS_INFO) << "Firewall Rules cleared"; | 1119 LOG(LS_INFO) << "Firewall Rules cleared"; |
| 1146 | 1120 |
| 1147 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, | 1121 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 1148 observer_.ice_connection_state_, | 1122 observer_.ice_connection_state_, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1273 cricket::TestTurnServer turn_server_; | 1247 cricket::TestTurnServer turn_server_; |
| 1274 rtc::FakeNetworkManager network_manager_; | 1248 rtc::FakeNetworkManager network_manager_; |
| 1275 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_; | 1249 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_; |
| 1276 PeerConnectionFactoryInterface::Options options_; | 1250 PeerConnectionFactoryInterface::Options options_; |
| 1277 rtc::scoped_ptr<FakeConstraints> constraints_; | 1251 rtc::scoped_ptr<FakeConstraints> constraints_; |
| 1278 FakeMediaStreamSignaling mediastream_signaling_; | 1252 FakeMediaStreamSignaling mediastream_signaling_; |
| 1279 rtc::scoped_ptr<WebRtcSessionForTest> session_; | 1253 rtc::scoped_ptr<WebRtcSessionForTest> session_; |
| 1280 MockIceObserver observer_; | 1254 MockIceObserver observer_; |
| 1281 cricket::FakeVideoMediaChannel* video_channel_; | 1255 cricket::FakeVideoMediaChannel* video_channel_; |
| 1282 cricket::FakeVoiceMediaChannel* voice_channel_; | 1256 cricket::FakeVoiceMediaChannel* voice_channel_; |
| 1283 FakeMetricsObserver metrics_observer_; | 1257 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_; |
| 1284 }; | 1258 }; |
| 1285 | 1259 |
| 1286 TEST_F(WebRtcSessionTest, TestInitializeWithDtls) { | 1260 TEST_F(WebRtcSessionTest, TestInitializeWithDtls) { |
| 1287 InitWithDtls(); | 1261 InitWithDtls(); |
| 1288 // SDES is disabled when DTLS is on. | 1262 // SDES is disabled when DTLS is on. |
| 1289 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy()); | 1263 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy()); |
| 1290 } | 1264 } |
| 1291 | 1265 |
| 1292 TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) { | 1266 TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) { |
| 1293 Init(); | 1267 Init(); |
| (...skipping 2580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3874 EXPECT_EQ(4000, option_val); | 3848 EXPECT_EQ(4000, option_val); |
| 3875 | 3849 |
| 3876 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption( | 3850 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption( |
| 3877 rtc::Socket::Option::OPT_RCVBUF, &option_val)); | 3851 rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 3878 EXPECT_EQ(8000, option_val); | 3852 EXPECT_EQ(8000, option_val); |
| 3879 } | 3853 } |
| 3880 | 3854 |
| 3881 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test | 3855 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
| 3882 // currently fails because upon disconnection and reconnection OnIceComplete is | 3856 // currently fails because upon disconnection and reconnection OnIceComplete is |
| 3883 // called more than once without returning to IceGatheringGathering. | 3857 // called more than once without returning to IceGatheringGathering. |
| OLD | NEW |