Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: webrtc/api/peerconnection_unittest.cc

Issue 2141863003: Adding an end-to-end connection time test. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Removing unnecessary "webrtc::" prefixes Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/base/fakenetwork.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 12 matching lines...) Expand all
23 #include "webrtc/api/mediastreaminterface.h" 23 #include "webrtc/api/mediastreaminterface.h"
24 #include "webrtc/api/peerconnection.h" 24 #include "webrtc/api/peerconnection.h"
25 #include "webrtc/api/peerconnectionfactory.h" 25 #include "webrtc/api/peerconnectionfactory.h"
26 #include "webrtc/api/peerconnectioninterface.h" 26 #include "webrtc/api/peerconnectioninterface.h"
27 #include "webrtc/api/test/fakeaudiocapturemodule.h" 27 #include "webrtc/api/test/fakeaudiocapturemodule.h"
28 #include "webrtc/api/test/fakeconstraints.h" 28 #include "webrtc/api/test/fakeconstraints.h"
29 #include "webrtc/api/test/fakeperiodicvideocapturer.h" 29 #include "webrtc/api/test/fakeperiodicvideocapturer.h"
30 #include "webrtc/api/test/fakertccertificategenerator.h" 30 #include "webrtc/api/test/fakertccertificategenerator.h"
31 #include "webrtc/api/test/fakevideotrackrenderer.h" 31 #include "webrtc/api/test/fakevideotrackrenderer.h"
32 #include "webrtc/api/test/mockpeerconnectionobservers.h" 32 #include "webrtc/api/test/mockpeerconnectionobservers.h"
33 #include "webrtc/base/fakenetwork.h"
33 #include "webrtc/base/gunit.h" 34 #include "webrtc/base/gunit.h"
34 #include "webrtc/base/physicalsocketserver.h" 35 #include "webrtc/base/physicalsocketserver.h"
35 #include "webrtc/base/ssladapter.h" 36 #include "webrtc/base/ssladapter.h"
36 #include "webrtc/base/sslstreamadapter.h" 37 #include "webrtc/base/sslstreamadapter.h"
37 #include "webrtc/base/thread.h" 38 #include "webrtc/base/thread.h"
38 #include "webrtc/base/virtualsocketserver.h" 39 #include "webrtc/base/virtualsocketserver.h"
39 #include "webrtc/media/engine/fakewebrtcvideoengine.h" 40 #include "webrtc/media/engine/fakewebrtcvideoengine.h"
40 #include "webrtc/p2p/base/fakeportallocator.h"
41 #include "webrtc/p2p/base/p2pconstants.h" 41 #include "webrtc/p2p/base/p2pconstants.h"
42 #include "webrtc/p2p/base/sessiondescription.h" 42 #include "webrtc/p2p/base/sessiondescription.h"
43 #include "webrtc/p2p/base/testturnserver.h"
44 #include "webrtc/p2p/client/basicportallocator.h"
43 #include "webrtc/pc/mediasession.h" 45 #include "webrtc/pc/mediasession.h"
44 46
45 #define MAYBE_SKIP_TEST(feature) \ 47 #define MAYBE_SKIP_TEST(feature) \
46 if (!(feature())) { \ 48 if (!(feature())) { \
47 LOG(LS_INFO) << "Feature disabled... skipping"; \ 49 LOG(LS_INFO) << "Feature disabled... skipping"; \
48 return; \ 50 return; \
49 } 51 }
50 52
51 using cricket::ContentInfo; 53 using cricket::ContentInfo;
52 using cricket::FakeWebRtcVideoDecoder; 54 using cricket::FakeWebRtcVideoDecoder;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // Disable for TSan v2, see 98 // Disable for TSan v2, see
97 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. 99 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
98 // This declaration is also #ifdef'd as it causes unused-variable errors. 100 // This declaration is also #ifdef'd as it causes unused-variable errors.
99 #if !defined(THREAD_SANITIZER) 101 #if !defined(THREAD_SANITIZER)
100 // SRTP cipher name negotiated by the tests. This must be updated if the 102 // SRTP cipher name negotiated by the tests. This must be updated if the
101 // default changes. 103 // default changes.
102 static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32; 104 static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32;
103 static const int kDefaultSrtpCryptoSuiteGcm = rtc::SRTP_AEAD_AES_256_GCM; 105 static const int kDefaultSrtpCryptoSuiteGcm = rtc::SRTP_AEAD_AES_256_GCM;
104 #endif 106 #endif
105 107
108 // Used to simulate signaling ICE/SDP between two PeerConnections.
109 enum Message { MSG_SDP_MESSAGE, MSG_ICE_MESSAGE };
110
111 struct SdpMessage {
112 std::string type;
113 std::string msg;
114 };
115
116 struct IceMessage {
117 std::string sdp_mid;
118 int sdp_mline_index;
119 std::string msg;
120 };
121
106 static void RemoveLinesFromSdp(const std::string& line_start, 122 static void RemoveLinesFromSdp(const std::string& line_start,
107 std::string* sdp) { 123 std::string* sdp) {
108 const char kSdpLineEnd[] = "\r\n"; 124 const char kSdpLineEnd[] = "\r\n";
109 size_t ssrc_pos = 0; 125 size_t ssrc_pos = 0;
110 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) != 126 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) !=
111 std::string::npos) { 127 std::string::npos) {
112 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos); 128 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos);
113 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd)); 129 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd));
114 } 130 }
115 } 131 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 177
162 virtual ~MockRtpReceiverObserver() {} 178 virtual ~MockRtpReceiverObserver() {}
163 179
164 private: 180 private:
165 bool first_packet_received_ = false; 181 bool first_packet_received_ = false;
166 cricket::MediaType expected_media_type_; 182 cricket::MediaType expected_media_type_;
167 }; 183 };
168 184
169 class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, 185 class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
170 public SignalingMessageReceiver, 186 public SignalingMessageReceiver,
171 public ObserverInterface { 187 public ObserverInterface,
188 public rtc::MessageHandler {
172 public: 189 public:
190 // If |config| is not provided, uses a default constructed RTCConfiguration.
173 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore( 191 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore(
174 const std::string& id, 192 const std::string& id,
175 const MediaConstraintsInterface* constraints, 193 const MediaConstraintsInterface* constraints,
176 const PeerConnectionFactory::Options* options, 194 const PeerConnectionFactory::Options* options,
177 const PeerConnectionInterface::RTCConfiguration& config, 195 const PeerConnectionInterface::RTCConfiguration* config,
178 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, 196 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
179 bool prefer_constraint_apis, 197 bool prefer_constraint_apis,
180 rtc::Thread* network_thread, 198 rtc::Thread* network_thread,
181 rtc::Thread* worker_thread) { 199 rtc::Thread* worker_thread) {
182 PeerConnectionTestClient* client(new PeerConnectionTestClient(id)); 200 PeerConnectionTestClient* client(new PeerConnectionTestClient(id));
183 if (!client->Init(constraints, options, config, std::move(cert_generator), 201 if (!client->Init(constraints, options, config, std::move(cert_generator),
184 prefer_constraint_apis, network_thread, worker_thread)) { 202 prefer_constraint_apis, network_thread, worker_thread)) {
185 delete client; 203 delete client;
186 return nullptr; 204 return nullptr;
187 } 205 }
188 return client; 206 return client;
189 } 207 }
190 208
191 static PeerConnectionTestClient* CreateClient( 209 static PeerConnectionTestClient* CreateClient(
192 const std::string& id, 210 const std::string& id,
193 const MediaConstraintsInterface* constraints, 211 const MediaConstraintsInterface* constraints,
194 const PeerConnectionFactory::Options* options, 212 const PeerConnectionFactory::Options* options,
195 const PeerConnectionInterface::RTCConfiguration& config, 213 const PeerConnectionInterface::RTCConfiguration* config,
196 rtc::Thread* network_thread, 214 rtc::Thread* network_thread,
197 rtc::Thread* worker_thread) { 215 rtc::Thread* worker_thread) {
198 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( 216 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
199 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? 217 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
200 new FakeRTCCertificateGenerator() : nullptr); 218 new FakeRTCCertificateGenerator() : nullptr);
201 219
202 return CreateClientWithDtlsIdentityStore(id, constraints, options, config, 220 return CreateClientWithDtlsIdentityStore(id, constraints, options, config,
203 std::move(cert_generator), true, 221 std::move(cert_generator), true,
204 network_thread, worker_thread); 222 network_thread, worker_thread);
205 } 223 }
206 224
207 static PeerConnectionTestClient* CreateClientPreferNoConstraints( 225 static PeerConnectionTestClient* CreateClientPreferNoConstraints(
208 const std::string& id, 226 const std::string& id,
209 const PeerConnectionFactory::Options* options, 227 const PeerConnectionFactory::Options* options,
210 const PeerConnectionInterface::RTCConfiguration& config,
211 rtc::Thread* network_thread, 228 rtc::Thread* network_thread,
212 rtc::Thread* worker_thread) { 229 rtc::Thread* worker_thread) {
213 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( 230 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
214 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? 231 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
215 new FakeRTCCertificateGenerator() : nullptr); 232 new FakeRTCCertificateGenerator() : nullptr);
216 233
217 return CreateClientWithDtlsIdentityStore(id, nullptr, options, config, 234 return CreateClientWithDtlsIdentityStore(id, nullptr, options, nullptr,
218 std::move(cert_generator), false, 235 std::move(cert_generator), false,
219 network_thread, worker_thread); 236 network_thread, worker_thread);
220 } 237 }
221 238
222 ~PeerConnectionTestClient() { 239 ~PeerConnectionTestClient() {
223 } 240 }
224 241
225 void Negotiate() { Negotiate(true, true); } 242 void Negotiate() { Negotiate(true, true); }
226 243
227 void Negotiate(bool audio, bool video) { 244 void Negotiate(bool audio, bool video) {
228 std::unique_ptr<SessionDescriptionInterface> offer; 245 std::unique_ptr<SessionDescriptionInterface> offer;
229 ASSERT_TRUE(DoCreateOffer(&offer)); 246 ASSERT_TRUE(DoCreateOffer(&offer));
230 247
231 if (offer->description()->GetContentByName("audio")) { 248 if (offer->description()->GetContentByName("audio")) {
232 offer->description()->GetContentByName("audio")->rejected = !audio; 249 offer->description()->GetContentByName("audio")->rejected = !audio;
233 } 250 }
234 if (offer->description()->GetContentByName("video")) { 251 if (offer->description()->GetContentByName("video")) {
235 offer->description()->GetContentByName("video")->rejected = !video; 252 offer->description()->GetContentByName("video")->rejected = !video;
236 } 253 }
237 254
238 std::string sdp; 255 std::string sdp;
239 EXPECT_TRUE(offer->ToString(&sdp)); 256 EXPECT_TRUE(offer->ToString(&sdp));
240 EXPECT_TRUE(DoSetLocalDescription(offer.release())); 257 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
241 signaling_message_receiver_->ReceiveSdpMessage( 258 SendSdpMessage(webrtc::SessionDescriptionInterface::kOffer, sdp);
242 webrtc::SessionDescriptionInterface::kOffer, sdp); 259 }
260
261 void SendSdpMessage(const std::string& type, std::string& msg) {
262 if (signaling_delay_ms_ == 0) {
263 if (signaling_message_receiver_) {
264 signaling_message_receiver_->ReceiveSdpMessage(type, msg);
skvlad 2016/09/06 18:02:09 Is it important to send the message synchronously
Taylor Brandstetter 2016/09/07 00:15:40 Some tests want to ensure that some state changes
265 }
266 } else {
267 rtc::Thread::Current()->PostDelayed(
268 RTC_FROM_HERE, signaling_delay_ms_, this, MSG_SDP_MESSAGE,
269 new rtc::TypedMessageData<SdpMessage>({type, msg}));
270 }
271 }
272
273 void SendIceMessage(const std::string& sdp_mid,
274 int sdp_mline_index,
275 const std::string& msg) {
276 if (signaling_delay_ms_ == 0) {
277 if (signaling_message_receiver_) {
278 signaling_message_receiver_->ReceiveIceMessage(sdp_mid, sdp_mline_index,
279 msg);
280 }
281 } else {
282 rtc::Thread::Current()->PostDelayed(RTC_FROM_HERE, signaling_delay_ms_,
283 this, MSG_ICE_MESSAGE,
284 new rtc::TypedMessageData<IceMessage>(
285 {sdp_mid, sdp_mline_index, msg}));
286 }
287 }
288
289 // MessageHandler callback.
290 void OnMessage(rtc::Message* msg) override {
291 switch (msg->message_id) {
292 case MSG_SDP_MESSAGE: {
293 auto sdp_message =
294 static_cast<rtc::TypedMessageData<SdpMessage>*>(msg->pdata);
295 if (signaling_message_receiver_) {
296 signaling_message_receiver_->ReceiveSdpMessage(
297 sdp_message->data().type, sdp_message->data().msg);
298 }
299 delete sdp_message;
300 break;
301 }
302 case MSG_ICE_MESSAGE: {
303 auto ice_message =
304 static_cast<rtc::TypedMessageData<IceMessage>*>(msg->pdata);
305 if (signaling_message_receiver_) {
306 signaling_message_receiver_->ReceiveIceMessage(
307 ice_message->data().sdp_mid, ice_message->data().sdp_mline_index,
308 ice_message->data().msg);
309 }
310 delete ice_message;
311 break;
312 }
313 default:
314 RTC_CHECK(false);
315 }
243 } 316 }
244 317
245 // SignalingMessageReceiver callback. 318 // SignalingMessageReceiver callback.
246 void ReceiveSdpMessage(const std::string& type, std::string& msg) override { 319 void ReceiveSdpMessage(const std::string& type, std::string& msg) override {
247 FilterIncomingSdpMessage(&msg); 320 FilterIncomingSdpMessage(&msg);
248 if (type == webrtc::SessionDescriptionInterface::kOffer) { 321 if (type == webrtc::SessionDescriptionInterface::kOffer) {
249 HandleIncomingOffer(msg); 322 HandleIncomingOffer(msg);
250 } else { 323 } else {
251 HandleIncomingAnswer(msg); 324 HandleIncomingAnswer(msg);
252 } 325 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 364 }
292 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { 365 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
293 LOG(INFO) << id_ << "OnIceCandidate"; 366 LOG(INFO) << id_ << "OnIceCandidate";
294 367
295 std::string ice_sdp; 368 std::string ice_sdp;
296 EXPECT_TRUE(candidate->ToString(&ice_sdp)); 369 EXPECT_TRUE(candidate->ToString(&ice_sdp));
297 if (signaling_message_receiver_ == nullptr) { 370 if (signaling_message_receiver_ == nullptr) {
298 // Remote party may be deleted. 371 // Remote party may be deleted.
299 return; 372 return;
300 } 373 }
301 signaling_message_receiver_->ReceiveIceMessage( 374 SendIceMessage(candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp);
302 candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp);
303 } 375 }
304 376
305 // MediaStreamInterface callback 377 // MediaStreamInterface callback
306 void OnChanged() override { 378 void OnChanged() override {
307 // Track added or removed from MediaStream, so update our renderers. 379 // Track added or removed from MediaStream, so update our renderers.
308 rtc::scoped_refptr<StreamCollectionInterface> remote_streams = 380 rtc::scoped_refptr<StreamCollectionInterface> remote_streams =
309 pc()->remote_streams(); 381 pc()->remote_streams();
310 // Remove renderers for tracks that were removed. 382 // Remove renderers for tracks that were removed.
311 for (auto it = fake_video_renderers_.begin(); 383 for (auto it = fake_video_renderers_.begin();
312 it != fake_video_renderers_.end();) { 384 it != fake_video_renderers_.end();) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 // Defaults to true. 439 // Defaults to true.
368 void set_auto_add_stream(bool auto_add_stream) { 440 void set_auto_add_stream(bool auto_add_stream) {
369 auto_add_stream_ = auto_add_stream; 441 auto_add_stream_ = auto_add_stream;
370 } 442 }
371 443
372 void set_signaling_message_receiver( 444 void set_signaling_message_receiver(
373 SignalingMessageReceiver* signaling_message_receiver) { 445 SignalingMessageReceiver* signaling_message_receiver) {
374 signaling_message_receiver_ = signaling_message_receiver; 446 signaling_message_receiver_ = signaling_message_receiver;
375 } 447 }
376 448
449 void set_signaling_delay_ms(int delay_ms) { signaling_delay_ms_ = delay_ms; }
450
377 void EnableVideoDecoderFactory() { 451 void EnableVideoDecoderFactory() {
378 video_decoder_factory_enabled_ = true; 452 video_decoder_factory_enabled_ = true;
379 fake_video_decoder_factory_->AddSupportedVideoCodecType( 453 fake_video_decoder_factory_->AddSupportedVideoCodecType(
380 webrtc::kVideoCodecVP8); 454 webrtc::kVideoCodecVP8);
381 } 455 }
382 456
383 void IceRestart() { 457 void IceRestart() {
384 offer_answer_constraints_.SetMandatoryIceRestart(true); 458 offer_answer_constraints_.SetMandatoryIceRestart(true);
385 offer_answer_options_.ice_restart = true; 459 offer_answer_options_.ice_restart = true;
386 SetExpectIceRestart(true); 460 SetExpectIceRestart(true);
387 } 461 }
388 462
389 void SetExpectIceRestart(bool expect_restart) { 463 void SetExpectIceRestart(bool expect_restart) {
390 expect_ice_restart_ = expect_restart; 464 expect_ice_restart_ = expect_restart;
391 } 465 }
392 466
393 bool ExpectIceRestart() const { return expect_ice_restart_; } 467 bool ExpectIceRestart() const { return expect_ice_restart_; }
394 468
469 // Below 3 methods assume streams will be offered.
470 // Thus they'll only set the "offer to receive" flag to true if it's
471 // currently false, not if it's just unset.
395 void SetReceiveAudioVideo(bool audio, bool video) { 472 void SetReceiveAudioVideo(bool audio, bool video) {
396 SetReceiveAudio(audio); 473 SetReceiveAudio(audio);
397 SetReceiveVideo(video); 474 SetReceiveVideo(video);
398 ASSERT_EQ(audio, can_receive_audio()); 475 ASSERT_EQ(audio, can_receive_audio());
399 ASSERT_EQ(video, can_receive_video()); 476 ASSERT_EQ(video, can_receive_video());
400 } 477 }
401 478
402 void SetReceiveAudio(bool audio) { 479 void SetReceiveAudio(bool audio) {
403 if (audio && can_receive_audio()) 480 if (audio && can_receive_audio()) {
404 return; 481 return;
482 }
405 offer_answer_constraints_.SetMandatoryReceiveAudio(audio); 483 offer_answer_constraints_.SetMandatoryReceiveAudio(audio);
406 offer_answer_options_.offer_to_receive_audio = audio ? 1 : 0; 484 offer_answer_options_.offer_to_receive_audio = audio ? 1 : 0;
407 } 485 }
408 486
409 void SetReceiveVideo(bool video) { 487 void SetReceiveVideo(bool video) {
410 if (video && can_receive_video()) 488 if (video && can_receive_video()) {
411 return; 489 return;
490 }
412 offer_answer_constraints_.SetMandatoryReceiveVideo(video); 491 offer_answer_constraints_.SetMandatoryReceiveVideo(video);
413 offer_answer_options_.offer_to_receive_video = video ? 1 : 0; 492 offer_answer_options_.offer_to_receive_video = video ? 1 : 0;
414 } 493 }
494
495 void SetOfferToReceiveAudioVideo(bool audio, bool video) {
496 offer_answer_constraints_.SetMandatoryReceiveAudio(audio);
497 offer_answer_options_.offer_to_receive_audio = audio ? 1 : 0;
498 offer_answer_constraints_.SetMandatoryReceiveVideo(video);
499 offer_answer_options_.offer_to_receive_video = video ? 1 : 0;
500 }
415 501
416 void RemoveMsidFromReceivedSdp(bool remove) { remove_msid_ = remove; } 502 void RemoveMsidFromReceivedSdp(bool remove) { remove_msid_ = remove; }
417 503
418 void RemoveSdesCryptoFromReceivedSdp(bool remove) { remove_sdes_ = remove; } 504 void RemoveSdesCryptoFromReceivedSdp(bool remove) { remove_sdes_ = remove; }
419 505
420 void RemoveBundleFromReceivedSdp(bool remove) { remove_bundle_ = remove; } 506 void RemoveBundleFromReceivedSdp(bool remove) { remove_bundle_ = remove; }
421 507
422 void RemoveCvoFromReceivedSdp(bool remove) { remove_cvo_ = remove; } 508 void RemoveCvoFromReceivedSdp(bool remove) { remove_cvo_ = remove; }
423 509
424 bool can_receive_audio() { 510 bool can_receive_audio() {
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 private: 929 private:
844 bool completed_; 930 bool completed_;
845 std::vector<std::string> tones_; 931 std::vector<std::string> tones_;
846 }; 932 };
847 933
848 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} 934 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {}
849 935
850 bool Init( 936 bool Init(
851 const MediaConstraintsInterface* constraints, 937 const MediaConstraintsInterface* constraints,
852 const PeerConnectionFactory::Options* options, 938 const PeerConnectionFactory::Options* options,
853 const PeerConnectionInterface::RTCConfiguration& config, 939 const PeerConnectionInterface::RTCConfiguration* config,
854 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, 940 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
855 bool prefer_constraint_apis, 941 bool prefer_constraint_apis,
856 rtc::Thread* network_thread, 942 rtc::Thread* network_thread,
857 rtc::Thread* worker_thread) { 943 rtc::Thread* worker_thread) {
858 EXPECT_TRUE(!peer_connection_); 944 EXPECT_TRUE(!peer_connection_);
859 EXPECT_TRUE(!peer_connection_factory_); 945 EXPECT_TRUE(!peer_connection_factory_);
860 if (!prefer_constraint_apis) { 946 if (!prefer_constraint_apis) {
861 EXPECT_TRUE(!constraints); 947 EXPECT_TRUE(!constraints);
862 } 948 }
863 prefer_constraint_apis_ = prefer_constraint_apis; 949 prefer_constraint_apis_ = prefer_constraint_apis;
864 950
951 fake_network_manager_.reset(new rtc::FakeNetworkManager());
952 fake_network_manager_->AddInterface(rtc::SocketAddress("192.168.1.1", 0));
953
865 std::unique_ptr<cricket::PortAllocator> port_allocator( 954 std::unique_ptr<cricket::PortAllocator> port_allocator(
866 new cricket::FakePortAllocator(network_thread, nullptr)); 955 new cricket::BasicPortAllocator(fake_network_manager_.get()));
867 fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); 956 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
868 957
869 if (fake_audio_capture_module_ == nullptr) { 958 if (fake_audio_capture_module_ == nullptr) {
870 return false; 959 return false;
871 } 960 }
872 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory(); 961 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory();
873 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory(); 962 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory();
874 rtc::Thread* const signaling_thread = rtc::Thread::Current(); 963 rtc::Thread* const signaling_thread = rtc::Thread::Current();
875 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( 964 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
876 network_thread, worker_thread, signaling_thread, 965 network_thread, worker_thread, signaling_thread,
877 fake_audio_capture_module_, fake_video_encoder_factory_, 966 fake_audio_capture_module_, fake_video_encoder_factory_,
878 fake_video_decoder_factory_); 967 fake_video_decoder_factory_);
879 if (!peer_connection_factory_) { 968 if (!peer_connection_factory_) {
880 return false; 969 return false;
881 } 970 }
882 if (options) { 971 if (options) {
883 peer_connection_factory_->SetOptions(*options); 972 peer_connection_factory_->SetOptions(*options);
884 } 973 }
885 peer_connection_ = 974 peer_connection_ =
886 CreatePeerConnection(std::move(port_allocator), constraints, config, 975 CreatePeerConnection(std::move(port_allocator), constraints, config,
887 std::move(cert_generator)); 976 std::move(cert_generator));
888
889 return peer_connection_.get() != nullptr; 977 return peer_connection_.get() != nullptr;
890 } 978 }
891 979
892 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( 980 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(
893 std::unique_ptr<cricket::PortAllocator> port_allocator, 981 std::unique_ptr<cricket::PortAllocator> port_allocator,
894 const MediaConstraintsInterface* constraints, 982 const MediaConstraintsInterface* constraints,
895 const PeerConnectionInterface::RTCConfiguration& config, 983 const PeerConnectionInterface::RTCConfiguration* config,
896 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) { 984 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
985 // CreatePeerConnection with RTCConfiguration.
986 PeerConnectionInterface::RTCConfiguration default_config;
987
988 if (!config) {
989 config = &default_config;
990 }
991
897 return peer_connection_factory_->CreatePeerConnection( 992 return peer_connection_factory_->CreatePeerConnection(
898 config, constraints, std::move(port_allocator), 993 *config, constraints, std::move(port_allocator),
899 std::move(cert_generator), this); 994 std::move(cert_generator), this);
900 } 995 }
901 996
902 void HandleIncomingOffer(const std::string& msg) { 997 void HandleIncomingOffer(const std::string& msg) {
903 LOG(INFO) << id_ << "HandleIncomingOffer "; 998 LOG(INFO) << id_ << "HandleIncomingOffer ";
904 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) { 999 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) {
905 // If we are not sending any streams ourselves it is time to add some. 1000 // If we are not sending any streams ourselves it is time to add some.
906 AddMediaStream(true, true); 1001 AddMediaStream(true, true);
907 } 1002 }
908 std::unique_ptr<SessionDescriptionInterface> desc( 1003 std::unique_ptr<SessionDescriptionInterface> desc(
909 webrtc::CreateSessionDescription("offer", msg, nullptr)); 1004 webrtc::CreateSessionDescription("offer", msg, nullptr));
910 EXPECT_TRUE(DoSetRemoteDescription(desc.release())); 1005 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
911 // Set the RtpReceiverObserver after receivers are created. 1006 // Set the RtpReceiverObserver after receivers are created.
912 SetRtpReceiverObservers(); 1007 SetRtpReceiverObservers();
913 std::unique_ptr<SessionDescriptionInterface> answer; 1008 std::unique_ptr<SessionDescriptionInterface> answer;
914 EXPECT_TRUE(DoCreateAnswer(&answer)); 1009 EXPECT_TRUE(DoCreateAnswer(&answer));
915 std::string sdp; 1010 std::string sdp;
916 EXPECT_TRUE(answer->ToString(&sdp)); 1011 EXPECT_TRUE(answer->ToString(&sdp));
917 EXPECT_TRUE(DoSetLocalDescription(answer.release())); 1012 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
918 if (signaling_message_receiver_) { 1013 SendSdpMessage(webrtc::SessionDescriptionInterface::kAnswer, sdp);
919 signaling_message_receiver_->ReceiveSdpMessage(
920 webrtc::SessionDescriptionInterface::kAnswer, sdp);
921 }
922 } 1014 }
923 1015
924 void HandleIncomingAnswer(const std::string& msg) { 1016 void HandleIncomingAnswer(const std::string& msg) {
925 LOG(INFO) << id_ << "HandleIncomingAnswer"; 1017 LOG(INFO) << id_ << "HandleIncomingAnswer";
926 std::unique_ptr<SessionDescriptionInterface> desc( 1018 std::unique_ptr<SessionDescriptionInterface> desc(
927 webrtc::CreateSessionDescription("answer", msg, nullptr)); 1019 webrtc::CreateSessionDescription("answer", msg, nullptr));
928 EXPECT_TRUE(DoSetRemoteDescription(desc.release())); 1020 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
929 // Set the RtpReceiverObserver after receivers are created. 1021 // Set the RtpReceiverObserver after receivers are created.
930 SetRtpReceiverObservers(); 1022 SetRtpReceiverObservers();
931 } 1023 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp); 1104 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp);
1013 } 1105 }
1014 if (remove_cvo_) { 1106 if (remove_cvo_) {
1015 const char kSdpCvoExtenstion[] = "urn:3gpp:video-orientation"; 1107 const char kSdpCvoExtenstion[] = "urn:3gpp:video-orientation";
1016 RemoveLinesFromSdp(kSdpCvoExtenstion, sdp); 1108 RemoveLinesFromSdp(kSdpCvoExtenstion, sdp);
1017 } 1109 }
1018 } 1110 }
1019 1111
1020 std::string id_; 1112 std::string id_;
1021 1113
1114 std::unique_ptr<rtc::FakeNetworkManager> fake_network_manager_;
1115
1022 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; 1116 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
1023 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> 1117 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
1024 peer_connection_factory_; 1118 peer_connection_factory_;
1025 1119
1026 bool prefer_constraint_apis_ = true; 1120 bool prefer_constraint_apis_ = true;
1027 bool auto_add_stream_ = true; 1121 bool auto_add_stream_ = true;
1028 1122
1029 typedef std::pair<std::string, std::string> IceUfragPwdPair; 1123 typedef std::pair<std::string, std::string> IceUfragPwdPair;
1030 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_; 1124 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_;
1031 bool expect_ice_restart_ = false; 1125 bool expect_ice_restart_ = false;
1032 1126
1033 // Needed to keep track of number of frames sent. 1127 // Needed to keep track of number of frames sent.
1034 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; 1128 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
1035 // Needed to keep track of number of frames received. 1129 // Needed to keep track of number of frames received.
1036 std::map<std::string, std::unique_ptr<webrtc::FakeVideoTrackRenderer>> 1130 std::map<std::string, std::unique_ptr<webrtc::FakeVideoTrackRenderer>>
1037 fake_video_renderers_; 1131 fake_video_renderers_;
1038 // Needed to ensure frames aren't received for removed tracks. 1132 // Needed to ensure frames aren't received for removed tracks.
1039 std::vector<std::unique_ptr<webrtc::FakeVideoTrackRenderer>> 1133 std::vector<std::unique_ptr<webrtc::FakeVideoTrackRenderer>>
1040 removed_fake_video_renderers_; 1134 removed_fake_video_renderers_;
1041 // Needed to keep track of number of frames received when external decoder 1135 // Needed to keep track of number of frames received when external decoder
1042 // used. 1136 // used.
1043 FakeWebRtcVideoDecoderFactory* fake_video_decoder_factory_ = nullptr; 1137 FakeWebRtcVideoDecoderFactory* fake_video_decoder_factory_ = nullptr;
1044 FakeWebRtcVideoEncoderFactory* fake_video_encoder_factory_ = nullptr; 1138 FakeWebRtcVideoEncoderFactory* fake_video_encoder_factory_ = nullptr;
1045 bool video_decoder_factory_enabled_ = false; 1139 bool video_decoder_factory_enabled_ = false;
1046 webrtc::FakeConstraints video_constraints_; 1140 webrtc::FakeConstraints video_constraints_;
1047 1141
1048 // For remote peer communication. 1142 // For remote peer communication.
1049 SignalingMessageReceiver* signaling_message_receiver_ = nullptr; 1143 SignalingMessageReceiver* signaling_message_receiver_ = nullptr;
1144 int signaling_delay_ms_ = 0;
1050 1145
1051 // Store references to the video capturers we've created, so that we can stop 1146 // Store references to the video capturers we've created, so that we can stop
1052 // them, if required. 1147 // them, if required.
1053 std::vector<cricket::FakeVideoCapturer*> video_capturers_; 1148 std::vector<cricket::FakeVideoCapturer*> video_capturers_;
1054 webrtc::VideoRotation capture_rotation_ = webrtc::kVideoRotation_0; 1149 webrtc::VideoRotation capture_rotation_ = webrtc::kVideoRotation_0;
1055 // |local_video_renderer_| attached to the first created local video track. 1150 // |local_video_renderer_| attached to the first created local video track.
1056 std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_; 1151 std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_;
1057 1152
1058 webrtc::FakeConstraints offer_answer_constraints_; 1153 webrtc::FakeConstraints offer_answer_constraints_;
1059 PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_; 1154 PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_;
(...skipping 14 matching lines...) Expand all
1074 1169
1075 class P2PTestConductor : public testing::Test { 1170 class P2PTestConductor : public testing::Test {
1076 public: 1171 public:
1077 P2PTestConductor() 1172 P2PTestConductor()
1078 : pss_(new rtc::PhysicalSocketServer), 1173 : pss_(new rtc::PhysicalSocketServer),
1079 ss_(new rtc::VirtualSocketServer(pss_.get())), 1174 ss_(new rtc::VirtualSocketServer(pss_.get())),
1080 network_thread_(new rtc::Thread(ss_.get())), 1175 network_thread_(new rtc::Thread(ss_.get())),
1081 worker_thread_(rtc::Thread::Create()) { 1176 worker_thread_(rtc::Thread::Create()) {
1082 RTC_CHECK(network_thread_->Start()); 1177 RTC_CHECK(network_thread_->Start());
1083 RTC_CHECK(worker_thread_->Start()); 1178 RTC_CHECK(worker_thread_->Start());
1084 webrtc::PeerConnectionInterface::IceServer ice_server;
1085 ice_server.uri = "stun:stun.l.google.com:19302";
1086 config_.servers.push_back(ice_server);
1087 } 1179 }
1088 1180
1089 bool SessionActive() { 1181 bool SessionActive() {
1090 return initiating_client_->SessionActive() && 1182 return initiating_client_->SessionActive() &&
1091 receiving_client_->SessionActive(); 1183 receiving_client_->SessionActive();
1092 } 1184 }
1093 1185
1094 // Return true if the number of frames provided have been received 1186 // Return true if the number of frames provided have been received
1095 // on the video and audio tracks provided. 1187 // on the video and audio tracks provided.
1096 bool FramesHaveArrived(int audio_frames_to_receive, 1188 bool FramesHaveArrived(int audio_frames_to_receive,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 } 1271 }
1180 if (receiving_client_) { 1272 if (receiving_client_) {
1181 receiving_client_->set_signaling_message_receiver(nullptr); 1273 receiving_client_->set_signaling_message_receiver(nullptr);
1182 } 1274 }
1183 } 1275 }
1184 1276
1185 bool CreateTestClients() { return CreateTestClients(nullptr, nullptr); } 1277 bool CreateTestClients() { return CreateTestClients(nullptr, nullptr); }
1186 1278
1187 bool CreateTestClients(MediaConstraintsInterface* init_constraints, 1279 bool CreateTestClients(MediaConstraintsInterface* init_constraints,
1188 MediaConstraintsInterface* recv_constraints) { 1280 MediaConstraintsInterface* recv_constraints) {
1189 return CreateTestClients(init_constraints, nullptr, recv_constraints, 1281 return CreateTestClients(init_constraints, nullptr, nullptr,
1190 nullptr); 1282 recv_constraints, nullptr, nullptr);
1191 } 1283 }
1192 1284
1193 bool CreateTestClientsThatPreferNoConstraints() { 1285 bool CreateTestClientsThatPreferNoConstraints() {
1194 initiating_client_.reset( 1286 initiating_client_.reset(
1195 PeerConnectionTestClient::CreateClientPreferNoConstraints( 1287 PeerConnectionTestClient::CreateClientPreferNoConstraints(
1196 "Caller: ", nullptr, config_, network_thread_.get(), 1288 "Caller: ", nullptr, network_thread_.get(), worker_thread_.get()));
1197 worker_thread_.get()));
1198 receiving_client_.reset( 1289 receiving_client_.reset(
1199 PeerConnectionTestClient::CreateClientPreferNoConstraints( 1290 PeerConnectionTestClient::CreateClientPreferNoConstraints(
1200 "Callee: ", nullptr, config_, network_thread_.get(), 1291 "Callee: ", nullptr, network_thread_.get(), worker_thread_.get()));
1201 worker_thread_.get()));
1202 if (!initiating_client_ || !receiving_client_) { 1292 if (!initiating_client_ || !receiving_client_) {
1203 return false; 1293 return false;
1204 } 1294 }
1205 // Remember the choice for possible later resets of the clients. 1295 // Remember the choice for possible later resets of the clients.
1206 prefer_constraint_apis_ = false; 1296 prefer_constraint_apis_ = false;
1207 SetSignalingReceivers(); 1297 SetSignalingReceivers();
1208 return true; 1298 return true;
1209 } 1299 }
1210 1300
1211 void SetSignalingReceivers() { 1301 void SetSignalingReceivers() {
1212 initiating_client_->set_signaling_message_receiver(receiving_client_.get()); 1302 initiating_client_->set_signaling_message_receiver(receiving_client_.get());
1213 receiving_client_->set_signaling_message_receiver(initiating_client_.get()); 1303 receiving_client_->set_signaling_message_receiver(initiating_client_.get());
1214 } 1304 }
1215 1305
1216 bool CreateTestClients(MediaConstraintsInterface* init_constraints, 1306 void SetSignalingDelayMs(int delay_ms) {
1217 PeerConnectionFactory::Options* init_options, 1307 initiating_client_->set_signaling_delay_ms(delay_ms);
1218 MediaConstraintsInterface* recv_constraints, 1308 receiving_client_->set_signaling_delay_ms(delay_ms);
1219 PeerConnectionFactory::Options* recv_options) { 1309 }
1310
1311 bool CreateTestClients(
1312 MediaConstraintsInterface* init_constraints,
1313 PeerConnectionFactory::Options* init_options,
1314 const PeerConnectionInterface::RTCConfiguration* init_config,
1315 MediaConstraintsInterface* recv_constraints,
1316 PeerConnectionFactory::Options* recv_options,
1317 const PeerConnectionInterface::RTCConfiguration* recv_config) {
1220 initiating_client_.reset(PeerConnectionTestClient::CreateClient( 1318 initiating_client_.reset(PeerConnectionTestClient::CreateClient(
1221 "Caller: ", init_constraints, init_options, config_, 1319 "Caller: ", init_constraints, init_options, init_config,
1222 network_thread_.get(), worker_thread_.get())); 1320 network_thread_.get(), worker_thread_.get()));
1223 receiving_client_.reset(PeerConnectionTestClient::CreateClient( 1321 receiving_client_.reset(PeerConnectionTestClient::CreateClient(
1224 "Callee: ", recv_constraints, recv_options, config_, 1322 "Callee: ", recv_constraints, recv_options, recv_config,
1225 network_thread_.get(), worker_thread_.get())); 1323 network_thread_.get(), worker_thread_.get()));
1226 if (!initiating_client_ || !receiving_client_) { 1324 if (!initiating_client_ || !receiving_client_) {
1227 return false; 1325 return false;
1228 } 1326 }
1229 SetSignalingReceivers(); 1327 SetSignalingReceivers();
1230 return true; 1328 return true;
1231 } 1329 }
1232 1330
1233 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints, 1331 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints,
1234 const webrtc::FakeConstraints& recv_constraints) { 1332 const webrtc::FakeConstraints& recv_constraints) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, 1413 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1316 true); 1414 true);
1317 1415
1318 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( 1416 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
1319 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? 1417 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
1320 new FakeRTCCertificateGenerator() : nullptr); 1418 new FakeRTCCertificateGenerator() : nullptr);
1321 cert_generator->use_alternate_key(); 1419 cert_generator->use_alternate_key();
1322 1420
1323 // Make sure the new client is using a different certificate. 1421 // Make sure the new client is using a different certificate.
1324 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore( 1422 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore(
1325 "New Peer: ", &setup_constraints, nullptr, config_, 1423 "New Peer: ", &setup_constraints, nullptr, nullptr,
1326 std::move(cert_generator), prefer_constraint_apis_, 1424 std::move(cert_generator), prefer_constraint_apis_,
1327 network_thread_.get(), worker_thread_.get()); 1425 network_thread_.get(), worker_thread_.get());
1328 } 1426 }
1329 1427
1330 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { 1428 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) {
1331 // Messages may get lost on the unreliable DataChannel, so we send multiple 1429 // Messages may get lost on the unreliable DataChannel, so we send multiple
1332 // times to avoid test flakiness. 1430 // times to avoid test flakiness.
1333 static const size_t kSendAttempts = 5; 1431 static const size_t kSendAttempts = 5;
1334 1432
1335 for (size_t i = 0; i < kSendAttempts; ++i) { 1433 for (size_t i = 0; i < kSendAttempts; ++i) {
1336 dc->Send(DataBuffer(data)); 1434 dc->Send(DataBuffer(data));
1337 } 1435 }
1338 } 1436 }
1339 1437
1438 rtc::Thread* network_thread() { return network_thread_.get(); }
1439
1440 rtc::VirtualSocketServer* virtual_socket_server() { return ss_.get(); }
1441
1340 PeerConnectionTestClient* initializing_client() { 1442 PeerConnectionTestClient* initializing_client() {
1341 return initiating_client_.get(); 1443 return initiating_client_.get();
1342 } 1444 }
1343 1445
1344 // Set the |initiating_client_| to the |client| passed in and return the 1446 // Set the |initiating_client_| to the |client| passed in and return the
1345 // original |initiating_client_|. 1447 // original |initiating_client_|.
1346 PeerConnectionTestClient* set_initializing_client( 1448 PeerConnectionTestClient* set_initializing_client(
1347 PeerConnectionTestClient* client) { 1449 PeerConnectionTestClient* client) {
1348 PeerConnectionTestClient* old = initiating_client_.release(); 1450 PeerConnectionTestClient* old = initiating_client_.release();
1349 initiating_client_.reset(client); 1451 initiating_client_.reset(client);
1350 return old; 1452 return old;
1351 } 1453 }
1352 1454
1353 PeerConnectionTestClient* receiving_client() { 1455 PeerConnectionTestClient* receiving_client() {
1354 return receiving_client_.get(); 1456 return receiving_client_.get();
1355 } 1457 }
1356 1458
1357 // Set the |receiving_client_| to the |client| passed in and return the 1459 // Set the |receiving_client_| to the |client| passed in and return the
1358 // original |receiving_client_|. 1460 // original |receiving_client_|.
1359 PeerConnectionTestClient* set_receiving_client( 1461 PeerConnectionTestClient* set_receiving_client(
1360 PeerConnectionTestClient* client) { 1462 PeerConnectionTestClient* client) {
1361 PeerConnectionTestClient* old = receiving_client_.release(); 1463 PeerConnectionTestClient* old = receiving_client_.release();
1362 receiving_client_.reset(client); 1464 receiving_client_.reset(client);
1363 return old; 1465 return old;
1364 } 1466 }
1365 webrtc::PeerConnectionInterface::RTCConfiguration* config() {
1366 return &config_;
1367 }
1368 1467
1369 bool AllObserversReceived( 1468 bool AllObserversReceived(
1370 const std::vector<std::unique_ptr<MockRtpReceiverObserver>>& observers) { 1469 const std::vector<std::unique_ptr<MockRtpReceiverObserver>>& observers) {
1371 for (auto& observer : observers) { 1470 for (auto& observer : observers) {
1372 if (!observer->first_packet_received()) { 1471 if (!observer->first_packet_received()) {
1373 return false; 1472 return false;
1374 } 1473 }
1375 } 1474 }
1376 return true; 1475 return true;
1377 } 1476 }
1378 1477
1379 void TestGcmNegotiation(bool local_gcm_enabled, bool remote_gcm_enabled, 1478 void TestGcmNegotiation(bool local_gcm_enabled, bool remote_gcm_enabled,
1380 int expected_cipher_suite) { 1479 int expected_cipher_suite) {
1381 PeerConnectionFactory::Options init_options; 1480 PeerConnectionFactory::Options init_options;
1382 init_options.crypto_options.enable_gcm_crypto_suites = local_gcm_enabled; 1481 init_options.crypto_options.enable_gcm_crypto_suites = local_gcm_enabled;
1383 PeerConnectionFactory::Options recv_options; 1482 PeerConnectionFactory::Options recv_options;
1384 recv_options.crypto_options.enable_gcm_crypto_suites = remote_gcm_enabled; 1483 recv_options.crypto_options.enable_gcm_crypto_suites = remote_gcm_enabled;
1385 ASSERT_TRUE( 1484 ASSERT_TRUE(CreateTestClients(nullptr, &init_options, nullptr, nullptr,
1386 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); 1485 &recv_options, nullptr));
1387 rtc::scoped_refptr<webrtc::FakeMetricsObserver> 1486 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1388 init_observer = 1487 init_observer =
1389 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); 1488 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1390 initializing_client()->pc()->RegisterUMAObserver(init_observer); 1489 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1391 LocalP2PTest(); 1490 LocalP2PTest();
1392 1491
1393 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite), 1492 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite),
1394 initializing_client()->GetSrtpCipherStats(), 1493 initializing_client()->GetSrtpCipherStats(),
1395 kMaxWaitMs); 1494 kMaxWaitMs);
1396 EXPECT_EQ(1, 1495 EXPECT_EQ(1,
1397 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, 1496 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1398 expected_cipher_suite)); 1497 expected_cipher_suite));
1399 } 1498 }
1400 1499
1401 private: 1500 private:
1402 // |ss_| is used by |network_thread_| so it must be destroyed later. 1501 // |ss_| is used by |network_thread_| so it must be destroyed later.
1403 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 1502 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1404 std::unique_ptr<rtc::VirtualSocketServer> ss_; 1503 std::unique_ptr<rtc::VirtualSocketServer> ss_;
1405 // |network_thread_| and |worker_thread_| are used by both 1504 // |network_thread_| and |worker_thread_| are used by both
1406 // |initiating_client_| and |receiving_client_| so they must be destroyed 1505 // |initiating_client_| and |receiving_client_| so they must be destroyed
1407 // later. 1506 // later.
1408 std::unique_ptr<rtc::Thread> network_thread_; 1507 std::unique_ptr<rtc::Thread> network_thread_;
1409 std::unique_ptr<rtc::Thread> worker_thread_; 1508 std::unique_ptr<rtc::Thread> worker_thread_;
1410 std::unique_ptr<PeerConnectionTestClient> initiating_client_; 1509 std::unique_ptr<PeerConnectionTestClient> initiating_client_;
1411 std::unique_ptr<PeerConnectionTestClient> receiving_client_; 1510 std::unique_ptr<PeerConnectionTestClient> receiving_client_;
1412 bool prefer_constraint_apis_ = true; 1511 bool prefer_constraint_apis_ = true;
1413 webrtc::PeerConnectionInterface::RTCConfiguration config_;
1414 }; 1512 };
1415 1513
1416 // Disable for TSan v2, see 1514 // Disable for TSan v2, see
1417 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. 1515 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
1418 #if !defined(THREAD_SANITIZER) 1516 #if !defined(THREAD_SANITIZER)
1419 1517
1420 TEST_F(P2PTestConductor, TestRtpReceiverObserverCallbackFunction) { 1518 TEST_F(P2PTestConductor, TestRtpReceiverObserverCallbackFunction) {
1421 ASSERT_TRUE(CreateTestClients()); 1519 ASSERT_TRUE(CreateTestClients());
1422 LocalP2PTest(); 1520 LocalP2PTest();
1423 EXPECT_TRUE_WAIT( 1521 EXPECT_TRUE_WAIT(
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 initializing_client()->GetBytesSentStats(local_video_track) > 0, 1844 initializing_client()->GetBytesSentStats(local_video_track) > 0,
1747 kMaxWaitForStatsMs); 1845 kMaxWaitForStatsMs);
1748 } 1846 }
1749 1847
1750 // Test that DTLS 1.0 is used if both sides only support DTLS 1.0. 1848 // Test that DTLS 1.0 is used if both sides only support DTLS 1.0.
1751 TEST_F(P2PTestConductor, GetDtls12None) { 1849 TEST_F(P2PTestConductor, GetDtls12None) {
1752 PeerConnectionFactory::Options init_options; 1850 PeerConnectionFactory::Options init_options;
1753 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; 1851 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1754 PeerConnectionFactory::Options recv_options; 1852 PeerConnectionFactory::Options recv_options;
1755 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; 1853 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1756 ASSERT_TRUE( 1854 ASSERT_TRUE(CreateTestClients(nullptr, &init_options, nullptr, nullptr,
1757 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); 1855 &recv_options, nullptr));
1758 rtc::scoped_refptr<webrtc::FakeMetricsObserver> 1856 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1759 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); 1857 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1760 initializing_client()->pc()->RegisterUMAObserver(init_observer); 1858 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1761 LocalP2PTest(); 1859 LocalP2PTest();
1762 1860
1763 EXPECT_TRUE_WAIT( 1861 EXPECT_TRUE_WAIT(
1764 rtc::SSLStreamAdapter::IsAcceptableCipher( 1862 rtc::SSLStreamAdapter::IsAcceptableCipher(
1765 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), 1863 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1766 kMaxWaitForStatsMs); 1864 kMaxWaitForStatsMs);
1767 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), 1865 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
1768 initializing_client()->GetSrtpCipherStats(), 1866 initializing_client()->GetSrtpCipherStats(),
1769 kMaxWaitForStatsMs); 1867 kMaxWaitForStatsMs);
1770 EXPECT_EQ(1, 1868 EXPECT_EQ(1,
1771 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, 1869 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1772 kDefaultSrtpCryptoSuite)); 1870 kDefaultSrtpCryptoSuite));
1773 } 1871 }
1774 1872
1775 // Test that DTLS 1.2 is used if both ends support it. 1873 // Test that DTLS 1.2 is used if both ends support it.
1776 TEST_F(P2PTestConductor, GetDtls12Both) { 1874 TEST_F(P2PTestConductor, GetDtls12Both) {
1777 PeerConnectionFactory::Options init_options; 1875 PeerConnectionFactory::Options init_options;
1778 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; 1876 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1779 PeerConnectionFactory::Options recv_options; 1877 PeerConnectionFactory::Options recv_options;
1780 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; 1878 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1781 ASSERT_TRUE( 1879 ASSERT_TRUE(CreateTestClients(nullptr, &init_options, nullptr, nullptr,
1782 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); 1880 &recv_options, nullptr));
1783 rtc::scoped_refptr<webrtc::FakeMetricsObserver> 1881 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1784 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); 1882 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1785 initializing_client()->pc()->RegisterUMAObserver(init_observer); 1883 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1786 LocalP2PTest(); 1884 LocalP2PTest();
1787 1885
1788 EXPECT_TRUE_WAIT( 1886 EXPECT_TRUE_WAIT(
1789 rtc::SSLStreamAdapter::IsAcceptableCipher( 1887 rtc::SSLStreamAdapter::IsAcceptableCipher(
1790 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), 1888 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1791 kMaxWaitForStatsMs); 1889 kMaxWaitForStatsMs);
1792 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), 1890 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
1793 initializing_client()->GetSrtpCipherStats(), 1891 initializing_client()->GetSrtpCipherStats(),
1794 kMaxWaitForStatsMs); 1892 kMaxWaitForStatsMs);
1795 EXPECT_EQ(1, 1893 EXPECT_EQ(1,
1796 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, 1894 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1797 kDefaultSrtpCryptoSuite)); 1895 kDefaultSrtpCryptoSuite));
1798 } 1896 }
1799 1897
1800 // Test that DTLS 1.0 is used if the initator supports DTLS 1.2 and the 1898 // Test that DTLS 1.0 is used if the initator supports DTLS 1.2 and the
1801 // received supports 1.0. 1899 // received supports 1.0.
1802 TEST_F(P2PTestConductor, GetDtls12Init) { 1900 TEST_F(P2PTestConductor, GetDtls12Init) {
1803 PeerConnectionFactory::Options init_options; 1901 PeerConnectionFactory::Options init_options;
1804 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; 1902 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1805 PeerConnectionFactory::Options recv_options; 1903 PeerConnectionFactory::Options recv_options;
1806 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; 1904 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1807 ASSERT_TRUE( 1905 ASSERT_TRUE(CreateTestClients(nullptr, &init_options, nullptr, nullptr,
1808 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); 1906 &recv_options, nullptr));
1809 rtc::scoped_refptr<webrtc::FakeMetricsObserver> 1907 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1810 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); 1908 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1811 initializing_client()->pc()->RegisterUMAObserver(init_observer); 1909 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1812 LocalP2PTest(); 1910 LocalP2PTest();
1813 1911
1814 EXPECT_TRUE_WAIT( 1912 EXPECT_TRUE_WAIT(
1815 rtc::SSLStreamAdapter::IsAcceptableCipher( 1913 rtc::SSLStreamAdapter::IsAcceptableCipher(
1816 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), 1914 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1817 kMaxWaitForStatsMs); 1915 kMaxWaitForStatsMs);
1818 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), 1916 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
1819 initializing_client()->GetSrtpCipherStats(), 1917 initializing_client()->GetSrtpCipherStats(),
1820 kMaxWaitForStatsMs); 1918 kMaxWaitForStatsMs);
1821 EXPECT_EQ(1, 1919 EXPECT_EQ(1,
1822 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, 1920 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1823 kDefaultSrtpCryptoSuite)); 1921 kDefaultSrtpCryptoSuite));
1824 } 1922 }
1825 1923
1826 // Test that DTLS 1.0 is used if the initator supports DTLS 1.0 and the 1924 // Test that DTLS 1.0 is used if the initator supports DTLS 1.0 and the
1827 // received supports 1.2. 1925 // received supports 1.2.
1828 TEST_F(P2PTestConductor, GetDtls12Recv) { 1926 TEST_F(P2PTestConductor, GetDtls12Recv) {
1829 PeerConnectionFactory::Options init_options; 1927 PeerConnectionFactory::Options init_options;
1830 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; 1928 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1831 PeerConnectionFactory::Options recv_options; 1929 PeerConnectionFactory::Options recv_options;
1832 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; 1930 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1833 ASSERT_TRUE( 1931 ASSERT_TRUE(CreateTestClients(nullptr, &init_options, nullptr, nullptr,
1834 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); 1932 &recv_options, nullptr));
1835 rtc::scoped_refptr<webrtc::FakeMetricsObserver> 1933 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1836 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); 1934 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1837 initializing_client()->pc()->RegisterUMAObserver(init_observer); 1935 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1838 LocalP2PTest(); 1936 LocalP2PTest();
1839 1937
1840 EXPECT_TRUE_WAIT( 1938 EXPECT_TRUE_WAIT(
1841 rtc::SSLStreamAdapter::IsAcceptableCipher( 1939 rtc::SSLStreamAdapter::IsAcceptableCipher(
1842 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), 1940 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1843 kMaxWaitForStatsMs); 1941 kMaxWaitForStatsMs);
1844 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), 1942 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
2125 EXPECT_TRUE( 2223 EXPECT_TRUE(
2126 video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack(""))); 2224 video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack("")));
2127 EXPECT_TRUE_WAIT(FramesHaveArrived(kEndAudioFrameCount, kEndVideoFrameCount), 2225 EXPECT_TRUE_WAIT(FramesHaveArrived(kEndAudioFrameCount, kEndVideoFrameCount),
2128 kMaxWaitForFramesMs); 2226 kMaxWaitForFramesMs);
2129 } 2227 }
2130 2228
2131 #ifdef HAVE_QUIC 2229 #ifdef HAVE_QUIC
2132 // This test sets up a call between two parties using QUIC instead of DTLS for 2230 // This test sets up a call between two parties using QUIC instead of DTLS for
2133 // audio and video, and a QUIC data channel. 2231 // audio and video, and a QUIC data channel.
2134 TEST_F(P2PTestConductor, LocalP2PTestQuicDataChannel) { 2232 TEST_F(P2PTestConductor, LocalP2PTestQuicDataChannel) {
2135 config()->enable_quic = true; 2233 PeerConnectionInterface::RTCConfiguration quic_config;
2234 quic_config.enable_quic = true;
2235 ASSERT_TRUE(CreateTestClients(nullptr, nullptr, &quic_config, nullptr,
2236 nullptr, &quic_config));
2136 ASSERT_TRUE(CreateTestClients()); 2237 ASSERT_TRUE(CreateTestClients());
2137 webrtc::DataChannelInit init; 2238 webrtc::DataChannelInit init;
2138 init.ordered = false; 2239 init.ordered = false;
2139 init.reliable = true; 2240 init.reliable = true;
2140 init.id = 1; 2241 init.id = 1;
2141 initializing_client()->CreateDataChannel(&init); 2242 initializing_client()->CreateDataChannel(&init);
2142 receiving_client()->CreateDataChannel(&init); 2243 receiving_client()->CreateDataChannel(&init);
2143 LocalP2PTest(); 2244 LocalP2PTest();
2144 ASSERT_NE(nullptr, initializing_client()->data_channel()); 2245 ASSERT_NE(nullptr, initializing_client()->data_channel());
2145 ASSERT_NE(nullptr, receiving_client()->data_channel()); 2246 ASSERT_NE(nullptr, receiving_client()->data_channel());
2146 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), 2247 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
2147 kMaxWaitMs); 2248 kMaxWaitMs);
2148 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), kMaxWaitMs); 2249 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), kMaxWaitMs);
2149 2250
2150 std::string data = "hello world"; 2251 std::string data = "hello world";
2151 2252
2152 initializing_client()->data_channel()->Send(DataBuffer(data)); 2253 initializing_client()->data_channel()->Send(DataBuffer(data));
2153 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(), 2254 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(),
2154 kMaxWaitMs); 2255 kMaxWaitMs);
2155 2256
2156 receiving_client()->data_channel()->Send(DataBuffer(data)); 2257 receiving_client()->data_channel()->Send(DataBuffer(data));
2157 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(), 2258 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(),
2158 kMaxWaitMs); 2259 kMaxWaitMs);
2159 } 2260 }
2160 2261
2161 // Tests that negotiation of QUIC data channels is completed without error. 2262 // Tests that negotiation of QUIC data channels is completed without error.
2162 TEST_F(P2PTestConductor, NegotiateQuicDataChannel) { 2263 TEST_F(P2PTestConductor, NegotiateQuicDataChannel) {
2163 config()->enable_quic = true; 2264 PeerConnectionInterface::RTCConfiguration quic_config;
2265 quic_config.enable_quic = true;
2266 ASSERT_TRUE(CreateTestClients(nullptr, &quic_config, nullptr, nullptr,
2267 &quic_config, nullptr));
2164 FakeConstraints constraints; 2268 FakeConstraints constraints;
2165 constraints.SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true); 2269 constraints.SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true);
2166 ASSERT_TRUE(CreateTestClients(&constraints, &constraints)); 2270 ASSERT_TRUE(CreateTestClients(&constraints, &constraints));
2167 webrtc::DataChannelInit init; 2271 webrtc::DataChannelInit init;
2168 init.ordered = false; 2272 init.ordered = false;
2169 init.reliable = true; 2273 init.reliable = true;
2170 init.id = 1; 2274 init.id = 1;
2171 initializing_client()->CreateDataChannel(&init); 2275 initializing_client()->CreateDataChannel(&init);
2172 initializing_client()->Negotiate(false, false); 2276 initializing_client()->Negotiate(false, false);
2173 } 2277 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2225 // Echo the stream back. 2329 // Echo the stream back.
2226 receiving_client()->pc()->AddStream( 2330 receiving_client()->pc()->AddStream(
2227 receiving_client()->remote_streams()->at(0)); 2331 receiving_client()->remote_streams()->at(0));
2228 receiving_client()->Negotiate(); 2332 receiving_client()->Negotiate();
2229 2333
2230 EXPECT_TRUE_WAIT( 2334 EXPECT_TRUE_WAIT(
2231 initializing_client()->VideoFramesReceivedCheck(kEndVideoFrameCount), 2335 initializing_client()->VideoFramesReceivedCheck(kEndVideoFrameCount),
2232 kMaxWaitForFramesMs); 2336 kMaxWaitForFramesMs);
2233 } 2337 }
2234 2338
2339 // Test that we achieve the expected end-to-end connection time, using a
2340 // fake clock and simulated latency on the media and signaling paths.
2341 // We use a TURN<->TURN connection because this is usually the quickest to
2342 // set up initially, especially when we're confident the connection will work
2343 // and can start sending media before we get a STUN response.
2344 //
2345 // With various optimizations enabled, here are the network delays we expect to
2346 // be on the critical path:
2347 // 1. 2 signaling trips: Signaling offer and offerer's TURN candidate, then
2348 // signaling answer (with DTLS fingerprint).
2349 // 2. 9 media hops: Rest of the DTLS handshake. 3 hops in each direction when
2350 // using TURN<->TURN pair, and DTLS exchange is 4 packets,
2351 // the first of which should have arrived before the answer.
2352 TEST_F(P2PTestConductor, EndToEndConnectionTimeWithTurnTurnPair) {
2353 rtc::ScopedFakeClock fake_clock;
2354 // Some things use a time of "0" as a special value, so we need to start out
2355 // the fake clock at a nonzero time.
2356 // TODO(deadbeef): Fix this.
2357 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
2358
2359 static constexpr int media_hop_delay_ms = 50;
2360 static constexpr int signaling_trip_delay_ms = 500;
2361 // For explanation of these values, see comment above.
2362 static constexpr int required_media_hops = 9;
2363 static constexpr int required_signaling_trips = 2;
2364 // For internal delays (such as posting an event asychronously).
2365 static constexpr int allowed_internal_delay_ms = 20;
skvlad 2016/09/06 18:02:09 Is this actually needed with a fake clock? Looks l
Taylor Brandstetter 2016/09/07 00:15:40 The thing is, handling a message can post another
2366 static constexpr int total_connection_time_ms =
2367 media_hop_delay_ms * required_media_hops +
2368 signaling_trip_delay_ms * required_signaling_trips +
2369 allowed_internal_delay_ms;
2370
2371 static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0",
2372 3478};
2373 static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1",
2374 0};
2375 static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0",
2376 3478};
2377 static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1",
2378 0};
2379 cricket::TestTurnServer turn_server_1(network_thread(),
2380 turn_server_1_internal_address,
2381 turn_server_1_external_address);
2382 cricket::TestTurnServer turn_server_2(network_thread(),
2383 turn_server_2_internal_address,
2384 turn_server_2_external_address);
2385 // Bypass permission check on received packets so media can be sent before
2386 // the candidate is signaled.
2387 turn_server_1.set_enable_permission_checks(false);
2388 turn_server_2.set_enable_permission_checks(false);
2389
2390 PeerConnectionInterface::RTCConfiguration client_1_config;
2391 webrtc::PeerConnectionInterface::IceServer ice_server_1;
2392 ice_server_1.urls.push_back("turn:88.88.88.0:3478");
2393 ice_server_1.username = "test";
2394 ice_server_1.password = "test";
2395 client_1_config.servers.push_back(ice_server_1);
2396 client_1_config.type = webrtc::PeerConnectionInterface::kRelay;
2397 client_1_config.presume_writable_when_fully_relayed = true;
2398
2399 PeerConnectionInterface::RTCConfiguration client_2_config;
2400 webrtc::PeerConnectionInterface::IceServer ice_server_2;
2401 ice_server_2.urls.push_back("turn:99.99.99.0:3478");
2402 ice_server_2.username = "test";
2403 ice_server_2.password = "test";
2404 client_2_config.servers.push_back(ice_server_2);
2405 client_2_config.type = webrtc::PeerConnectionInterface::kRelay;
2406 client_2_config.presume_writable_when_fully_relayed = true;
2407
2408 ASSERT_TRUE(CreateTestClients(nullptr, nullptr, &client_1_config, nullptr,
2409 nullptr, &client_2_config));
2410 // Set up the simulated delays.
2411 SetSignalingDelayMs(signaling_trip_delay_ms);
2412 virtual_socket_server()->set_delay_mean(media_hop_delay_ms);
2413 virtual_socket_server()->UpdateDelayDistribution();
2414
2415 initializing_client()->SetOfferToReceiveAudioVideo(true, true);
2416 initializing_client()->Negotiate();
2417 // TODO(deadbeef): kIceConnectionConnected currently means both ICE and DTLS
2418 // are connected. This is an important distinction. Once we have separate ICE
2419 // and DTLS state, this check needs to use the DTLS state.
2420 EXPECT_TRUE_SIMULATED_WAIT(
2421 (receiving_client()->ice_connection_state() ==
2422 webrtc::PeerConnectionInterface::kIceConnectionConnected ||
2423 receiving_client()->ice_connection_state() ==
2424 webrtc::PeerConnectionInterface::kIceConnectionCompleted) &&
2425 (initializing_client()->ice_connection_state() ==
2426 webrtc::PeerConnectionInterface::kIceConnectionConnected ||
2427 initializing_client()->ice_connection_state() ==
2428 webrtc::PeerConnectionInterface::kIceConnectionCompleted),
2429 total_connection_time_ms, fake_clock);
2430 // Need to free the clients here since they're using things we created on
2431 // the stack.
2432 delete set_initializing_client(nullptr);
2433 delete set_receiving_client(nullptr);
2434 }
2435
2235 class IceServerParsingTest : public testing::Test { 2436 class IceServerParsingTest : public testing::Test {
2236 public: 2437 public:
2237 // Convenience for parsing a single URL. 2438 // Convenience for parsing a single URL.
2238 bool ParseUrl(const std::string& url) { 2439 bool ParseUrl(const std::string& url) {
2239 return ParseUrl(url, std::string(), std::string()); 2440 return ParseUrl(url, std::string(), std::string());
2240 } 2441 }
2241 2442
2242 bool ParseUrl(const std::string& url, 2443 bool ParseUrl(const std::string& url,
2243 const std::string& username, 2444 const std::string& username,
2244 const std::string& password) { 2445 const std::string& password) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2417 server.urls.push_back("turn:hostname2"); 2618 server.urls.push_back("turn:hostname2");
2418 servers.push_back(server); 2619 servers.push_back(server);
2419 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); 2620 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
2420 EXPECT_EQ(2U, turn_servers_.size()); 2621 EXPECT_EQ(2U, turn_servers_.size());
2421 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); 2622 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority);
2422 } 2623 }
2423 2624
2424 #endif // if !defined(THREAD_SANITIZER) 2625 #endif // if !defined(THREAD_SANITIZER)
2425 2626
2426 } // namespace 2627 } // namespace
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/fakenetwork.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698