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

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: Merge with master. Created 4 years, 3 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/helpers.h" 35 #include "webrtc/base/helpers.h"
35 #include "webrtc/base/physicalsocketserver.h" 36 #include "webrtc/base/physicalsocketserver.h"
36 #include "webrtc/base/ssladapter.h" 37 #include "webrtc/base/ssladapter.h"
37 #include "webrtc/base/sslstreamadapter.h" 38 #include "webrtc/base/sslstreamadapter.h"
38 #include "webrtc/base/thread.h" 39 #include "webrtc/base/thread.h"
39 #include "webrtc/base/virtualsocketserver.h" 40 #include "webrtc/base/virtualsocketserver.h"
40 #include "webrtc/media/engine/fakewebrtcvideoengine.h" 41 #include "webrtc/media/engine/fakewebrtcvideoengine.h"
41 #include "webrtc/p2p/base/fakeportallocator.h"
42 #include "webrtc/p2p/base/p2pconstants.h" 42 #include "webrtc/p2p/base/p2pconstants.h"
43 #include "webrtc/p2p/base/sessiondescription.h" 43 #include "webrtc/p2p/base/sessiondescription.h"
44 #include "webrtc/p2p/base/testturnserver.h"
45 #include "webrtc/p2p/client/basicportallocator.h"
44 #include "webrtc/pc/mediasession.h" 46 #include "webrtc/pc/mediasession.h"
45 47
46 #define MAYBE_SKIP_TEST(feature) \ 48 #define MAYBE_SKIP_TEST(feature) \
47 if (!(feature())) { \ 49 if (!(feature())) { \
48 LOG(LS_INFO) << "Feature disabled... skipping"; \ 50 LOG(LS_INFO) << "Feature disabled... skipping"; \
49 return; \ 51 return; \
50 } 52 }
51 53
52 using cricket::ContentInfo; 54 using cricket::ContentInfo;
53 using cricket::FakeWebRtcVideoDecoder; 55 using cricket::FakeWebRtcVideoDecoder;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // Disable for TSan v2, see 99 // Disable for TSan v2, see
98 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. 100 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
99 // This declaration is also #ifdef'd as it causes unused-variable errors. 101 // This declaration is also #ifdef'd as it causes unused-variable errors.
100 #if !defined(THREAD_SANITIZER) 102 #if !defined(THREAD_SANITIZER)
101 // SRTP cipher name negotiated by the tests. This must be updated if the 103 // SRTP cipher name negotiated by the tests. This must be updated if the
102 // default changes. 104 // default changes.
103 static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32; 105 static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32;
104 static const int kDefaultSrtpCryptoSuiteGcm = rtc::SRTP_AEAD_AES_256_GCM; 106 static const int kDefaultSrtpCryptoSuiteGcm = rtc::SRTP_AEAD_AES_256_GCM;
105 #endif 107 #endif
106 108
109 // Used to simulate signaling ICE/SDP between two PeerConnections.
110 enum Message { MSG_SDP_MESSAGE, MSG_ICE_MESSAGE };
111
112 struct SdpMessage {
113 std::string type;
114 std::string msg;
115 };
116
117 struct IceMessage {
118 std::string sdp_mid;
119 int sdp_mline_index;
120 std::string msg;
121 };
122
107 static void RemoveLinesFromSdp(const std::string& line_start, 123 static void RemoveLinesFromSdp(const std::string& line_start,
108 std::string* sdp) { 124 std::string* sdp) {
109 const char kSdpLineEnd[] = "\r\n"; 125 const char kSdpLineEnd[] = "\r\n";
110 size_t ssrc_pos = 0; 126 size_t ssrc_pos = 0;
111 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) != 127 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) !=
112 std::string::npos) { 128 std::string::npos) {
113 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos); 129 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos);
114 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd)); 130 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd));
115 } 131 }
116 } 132 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 178
163 virtual ~MockRtpReceiverObserver() {} 179 virtual ~MockRtpReceiverObserver() {}
164 180
165 private: 181 private:
166 bool first_packet_received_ = false; 182 bool first_packet_received_ = false;
167 cricket::MediaType expected_media_type_; 183 cricket::MediaType expected_media_type_;
168 }; 184 };
169 185
170 class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, 186 class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
171 public SignalingMessageReceiver, 187 public SignalingMessageReceiver,
172 public ObserverInterface { 188 public ObserverInterface,
189 public rtc::MessageHandler {
173 public: 190 public:
191 // If |config| is not provided, uses a default constructed RTCConfiguration.
174 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore( 192 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore(
175 const std::string& id, 193 const std::string& id,
176 const MediaConstraintsInterface* constraints, 194 const MediaConstraintsInterface* constraints,
177 const PeerConnectionFactory::Options* options, 195 const PeerConnectionFactory::Options* options,
178 const PeerConnectionInterface::RTCConfiguration& config, 196 const PeerConnectionInterface::RTCConfiguration* config,
179 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, 197 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
180 bool prefer_constraint_apis, 198 bool prefer_constraint_apis,
181 rtc::Thread* network_thread, 199 rtc::Thread* network_thread,
182 rtc::Thread* worker_thread) { 200 rtc::Thread* worker_thread) {
183 PeerConnectionTestClient* client(new PeerConnectionTestClient(id)); 201 PeerConnectionTestClient* client(new PeerConnectionTestClient(id));
184 if (!client->Init(constraints, options, config, std::move(cert_generator), 202 if (!client->Init(constraints, options, config, std::move(cert_generator),
185 prefer_constraint_apis, network_thread, worker_thread)) { 203 prefer_constraint_apis, network_thread, worker_thread)) {
186 delete client; 204 delete client;
187 return nullptr; 205 return nullptr;
188 } 206 }
189 return client; 207 return client;
190 } 208 }
191 209
192 static PeerConnectionTestClient* CreateClient( 210 static PeerConnectionTestClient* CreateClient(
193 const std::string& id, 211 const std::string& id,
194 const MediaConstraintsInterface* constraints, 212 const MediaConstraintsInterface* constraints,
195 const PeerConnectionFactory::Options* options, 213 const PeerConnectionFactory::Options* options,
196 const PeerConnectionInterface::RTCConfiguration& config, 214 const PeerConnectionInterface::RTCConfiguration* config,
197 rtc::Thread* network_thread, 215 rtc::Thread* network_thread,
198 rtc::Thread* worker_thread) { 216 rtc::Thread* worker_thread) {
199 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( 217 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
200 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? 218 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
201 new FakeRTCCertificateGenerator() : nullptr); 219 new FakeRTCCertificateGenerator() : nullptr);
202 220
203 return CreateClientWithDtlsIdentityStore(id, constraints, options, config, 221 return CreateClientWithDtlsIdentityStore(id, constraints, options, config,
204 std::move(cert_generator), true, 222 std::move(cert_generator), true,
205 network_thread, worker_thread); 223 network_thread, worker_thread);
206 } 224 }
207 225
208 static PeerConnectionTestClient* CreateClientPreferNoConstraints( 226 static PeerConnectionTestClient* CreateClientPreferNoConstraints(
209 const std::string& id, 227 const std::string& id,
210 const PeerConnectionFactory::Options* options, 228 const PeerConnectionFactory::Options* options,
211 const PeerConnectionInterface::RTCConfiguration& config,
212 rtc::Thread* network_thread, 229 rtc::Thread* network_thread,
213 rtc::Thread* worker_thread) { 230 rtc::Thread* worker_thread) {
214 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( 231 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
215 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? 232 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
216 new FakeRTCCertificateGenerator() : nullptr); 233 new FakeRTCCertificateGenerator() : nullptr);
217 234
218 return CreateClientWithDtlsIdentityStore(id, nullptr, options, config, 235 return CreateClientWithDtlsIdentityStore(id, nullptr, options, nullptr,
219 std::move(cert_generator), false, 236 std::move(cert_generator), false,
220 network_thread, worker_thread); 237 network_thread, worker_thread);
221 } 238 }
222 239
223 ~PeerConnectionTestClient() { 240 ~PeerConnectionTestClient() {
224 } 241 }
225 242
226 void Negotiate() { Negotiate(true, true); } 243 void Negotiate() { Negotiate(true, true); }
227 244
228 void Negotiate(bool audio, bool video) { 245 void Negotiate(bool audio, bool video) {
229 std::unique_ptr<SessionDescriptionInterface> offer; 246 std::unique_ptr<SessionDescriptionInterface> offer;
230 ASSERT_TRUE(DoCreateOffer(&offer)); 247 ASSERT_TRUE(DoCreateOffer(&offer));
231 248
232 if (offer->description()->GetContentByName("audio")) { 249 if (offer->description()->GetContentByName("audio")) {
233 offer->description()->GetContentByName("audio")->rejected = !audio; 250 offer->description()->GetContentByName("audio")->rejected = !audio;
234 } 251 }
235 if (offer->description()->GetContentByName("video")) { 252 if (offer->description()->GetContentByName("video")) {
236 offer->description()->GetContentByName("video")->rejected = !video; 253 offer->description()->GetContentByName("video")->rejected = !video;
237 } 254 }
238 255
239 std::string sdp; 256 std::string sdp;
240 EXPECT_TRUE(offer->ToString(&sdp)); 257 EXPECT_TRUE(offer->ToString(&sdp));
241 EXPECT_TRUE(DoSetLocalDescription(offer.release())); 258 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
242 signaling_message_receiver_->ReceiveSdpMessage( 259 SendSdpMessage(webrtc::SessionDescriptionInterface::kOffer, sdp);
243 webrtc::SessionDescriptionInterface::kOffer, sdp); 260 }
261
262 void SendSdpMessage(const std::string& type, std::string& msg) {
263 if (signaling_delay_ms_ == 0) {
264 if (signaling_message_receiver_) {
265 signaling_message_receiver_->ReceiveSdpMessage(type, msg);
266 }
267 } else {
268 rtc::Thread::Current()->PostDelayed(
269 RTC_FROM_HERE, signaling_delay_ms_, this, MSG_SDP_MESSAGE,
270 new rtc::TypedMessageData<SdpMessage>({type, msg}));
271 }
272 }
273
274 void SendIceMessage(const std::string& sdp_mid,
275 int sdp_mline_index,
276 const std::string& msg) {
277 if (signaling_delay_ms_ == 0) {
278 if (signaling_message_receiver_) {
279 signaling_message_receiver_->ReceiveIceMessage(sdp_mid, sdp_mline_index,
280 msg);
281 }
282 } else {
283 rtc::Thread::Current()->PostDelayed(RTC_FROM_HERE, signaling_delay_ms_,
284 this, MSG_ICE_MESSAGE,
285 new rtc::TypedMessageData<IceMessage>(
286 {sdp_mid, sdp_mline_index, msg}));
287 }
288 }
289
290 // MessageHandler callback.
291 void OnMessage(rtc::Message* msg) override {
292 switch (msg->message_id) {
293 case MSG_SDP_MESSAGE: {
294 auto sdp_message =
295 static_cast<rtc::TypedMessageData<SdpMessage>*>(msg->pdata);
296 if (signaling_message_receiver_) {
297 signaling_message_receiver_->ReceiveSdpMessage(
298 sdp_message->data().type, sdp_message->data().msg);
299 }
300 delete sdp_message;
301 break;
302 }
303 case MSG_ICE_MESSAGE: {
304 auto ice_message =
305 static_cast<rtc::TypedMessageData<IceMessage>*>(msg->pdata);
306 if (signaling_message_receiver_) {
307 signaling_message_receiver_->ReceiveIceMessage(
308 ice_message->data().sdp_mid, ice_message->data().sdp_mline_index,
309 ice_message->data().msg);
310 }
311 delete ice_message;
312 break;
313 }
314 default:
315 RTC_CHECK(false);
316 }
244 } 317 }
245 318
246 // SignalingMessageReceiver callback. 319 // SignalingMessageReceiver callback.
247 void ReceiveSdpMessage(const std::string& type, std::string& msg) override { 320 void ReceiveSdpMessage(const std::string& type, std::string& msg) override {
248 FilterIncomingSdpMessage(&msg); 321 FilterIncomingSdpMessage(&msg);
249 if (type == webrtc::SessionDescriptionInterface::kOffer) { 322 if (type == webrtc::SessionDescriptionInterface::kOffer) {
250 HandleIncomingOffer(msg); 323 HandleIncomingOffer(msg);
251 } else { 324 } else {
252 HandleIncomingAnswer(msg); 325 HandleIncomingAnswer(msg);
253 } 326 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } 365 }
293 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { 366 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
294 LOG(INFO) << id_ << "OnIceCandidate"; 367 LOG(INFO) << id_ << "OnIceCandidate";
295 368
296 std::string ice_sdp; 369 std::string ice_sdp;
297 EXPECT_TRUE(candidate->ToString(&ice_sdp)); 370 EXPECT_TRUE(candidate->ToString(&ice_sdp));
298 if (signaling_message_receiver_ == nullptr) { 371 if (signaling_message_receiver_ == nullptr) {
299 // Remote party may be deleted. 372 // Remote party may be deleted.
300 return; 373 return;
301 } 374 }
302 signaling_message_receiver_->ReceiveIceMessage( 375 SendIceMessage(candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp);
303 candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp);
304 } 376 }
305 377
306 // MediaStreamInterface callback 378 // MediaStreamInterface callback
307 void OnChanged() override { 379 void OnChanged() override {
308 // Track added or removed from MediaStream, so update our renderers. 380 // Track added or removed from MediaStream, so update our renderers.
309 rtc::scoped_refptr<StreamCollectionInterface> remote_streams = 381 rtc::scoped_refptr<StreamCollectionInterface> remote_streams =
310 pc()->remote_streams(); 382 pc()->remote_streams();
311 // Remove renderers for tracks that were removed. 383 // Remove renderers for tracks that were removed.
312 for (auto it = fake_video_renderers_.begin(); 384 for (auto it = fake_video_renderers_.begin();
313 it != fake_video_renderers_.end();) { 385 it != fake_video_renderers_.end();) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 // Defaults to true. 440 // Defaults to true.
369 void set_auto_add_stream(bool auto_add_stream) { 441 void set_auto_add_stream(bool auto_add_stream) {
370 auto_add_stream_ = auto_add_stream; 442 auto_add_stream_ = auto_add_stream;
371 } 443 }
372 444
373 void set_signaling_message_receiver( 445 void set_signaling_message_receiver(
374 SignalingMessageReceiver* signaling_message_receiver) { 446 SignalingMessageReceiver* signaling_message_receiver) {
375 signaling_message_receiver_ = signaling_message_receiver; 447 signaling_message_receiver_ = signaling_message_receiver;
376 } 448 }
377 449
450 void set_signaling_delay_ms(int delay_ms) { signaling_delay_ms_ = delay_ms; }
451
378 void EnableVideoDecoderFactory() { 452 void EnableVideoDecoderFactory() {
379 video_decoder_factory_enabled_ = true; 453 video_decoder_factory_enabled_ = true;
380 fake_video_decoder_factory_->AddSupportedVideoCodecType( 454 fake_video_decoder_factory_->AddSupportedVideoCodecType(
381 webrtc::kVideoCodecVP8); 455 webrtc::kVideoCodecVP8);
382 } 456 }
383 457
384 void IceRestart() { 458 void IceRestart() {
385 offer_answer_constraints_.SetMandatoryIceRestart(true); 459 offer_answer_constraints_.SetMandatoryIceRestart(true);
386 offer_answer_options_.ice_restart = true; 460 offer_answer_options_.ice_restart = true;
387 SetExpectIceRestart(true); 461 SetExpectIceRestart(true);
388 } 462 }
389 463
390 void SetExpectIceRestart(bool expect_restart) { 464 void SetExpectIceRestart(bool expect_restart) {
391 expect_ice_restart_ = expect_restart; 465 expect_ice_restart_ = expect_restart;
392 } 466 }
393 467
394 bool ExpectIceRestart() const { return expect_ice_restart_; } 468 bool ExpectIceRestart() const { return expect_ice_restart_; }
395 469
396 void SetExpectIceRenomination(bool expect_renomination) { 470 void SetExpectIceRenomination(bool expect_renomination) {
397 expect_ice_renomination_ = expect_renomination; 471 expect_ice_renomination_ = expect_renomination;
398 } 472 }
399 void SetExpectRemoteIceRenomination(bool expect_renomination) { 473 void SetExpectRemoteIceRenomination(bool expect_renomination) {
400 expect_remote_ice_renomination_ = expect_renomination; 474 expect_remote_ice_renomination_ = expect_renomination;
401 } 475 }
402 bool ExpectIceRenomination() { return expect_ice_renomination_; } 476 bool ExpectIceRenomination() { return expect_ice_renomination_; }
403 bool ExpectRemoteIceRenomination() { return expect_remote_ice_renomination_; } 477 bool ExpectRemoteIceRenomination() { return expect_remote_ice_renomination_; }
404 478
479 // The below 3 methods assume streams will be offered.
480 // Thus they'll only set the "offer to receive" flag to true if it's
481 // currently false, not if it's just unset.
405 void SetReceiveAudioVideo(bool audio, bool video) { 482 void SetReceiveAudioVideo(bool audio, bool video) {
406 SetReceiveAudio(audio); 483 SetReceiveAudio(audio);
407 SetReceiveVideo(video); 484 SetReceiveVideo(video);
408 ASSERT_EQ(audio, can_receive_audio()); 485 ASSERT_EQ(audio, can_receive_audio());
409 ASSERT_EQ(video, can_receive_video()); 486 ASSERT_EQ(video, can_receive_video());
410 } 487 }
411 488
412 void SetReceiveAudio(bool audio) { 489 void SetReceiveAudio(bool audio) {
413 if (audio && can_receive_audio()) 490 if (audio && can_receive_audio()) {
414 return; 491 return;
492 }
415 offer_answer_constraints_.SetMandatoryReceiveAudio(audio); 493 offer_answer_constraints_.SetMandatoryReceiveAudio(audio);
416 offer_answer_options_.offer_to_receive_audio = audio ? 1 : 0; 494 offer_answer_options_.offer_to_receive_audio = audio ? 1 : 0;
417 } 495 }
418 496
419 void SetReceiveVideo(bool video) { 497 void SetReceiveVideo(bool video) {
420 if (video && can_receive_video()) 498 if (video && can_receive_video()) {
421 return; 499 return;
500 }
422 offer_answer_constraints_.SetMandatoryReceiveVideo(video); 501 offer_answer_constraints_.SetMandatoryReceiveVideo(video);
423 offer_answer_options_.offer_to_receive_video = video ? 1 : 0; 502 offer_answer_options_.offer_to_receive_video = video ? 1 : 0;
424 } 503 }
504
505 void SetOfferToReceiveAudioVideo(bool audio, bool video) {
506 offer_answer_constraints_.SetMandatoryReceiveAudio(audio);
507 offer_answer_options_.offer_to_receive_audio = audio ? 1 : 0;
508 offer_answer_constraints_.SetMandatoryReceiveVideo(video);
509 offer_answer_options_.offer_to_receive_video = video ? 1 : 0;
510 }
425 511
426 void RemoveMsidFromReceivedSdp(bool remove) { remove_msid_ = remove; } 512 void RemoveMsidFromReceivedSdp(bool remove) { remove_msid_ = remove; }
427 513
428 void RemoveSdesCryptoFromReceivedSdp(bool remove) { remove_sdes_ = remove; } 514 void RemoveSdesCryptoFromReceivedSdp(bool remove) { remove_sdes_ = remove; }
429 515
430 void RemoveBundleFromReceivedSdp(bool remove) { remove_bundle_ = remove; } 516 void RemoveBundleFromReceivedSdp(bool remove) { remove_bundle_ = remove; }
431 517
432 void RemoveCvoFromReceivedSdp(bool remove) { remove_cvo_ = remove; } 518 void RemoveCvoFromReceivedSdp(bool remove) { remove_cvo_ = remove; }
433 519
434 bool can_receive_audio() { 520 bool can_receive_audio() {
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 private: 975 private:
890 bool completed_; 976 bool completed_;
891 std::vector<std::string> tones_; 977 std::vector<std::string> tones_;
892 }; 978 };
893 979
894 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} 980 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {}
895 981
896 bool Init( 982 bool Init(
897 const MediaConstraintsInterface* constraints, 983 const MediaConstraintsInterface* constraints,
898 const PeerConnectionFactory::Options* options, 984 const PeerConnectionFactory::Options* options,
899 const PeerConnectionInterface::RTCConfiguration& config, 985 const PeerConnectionInterface::RTCConfiguration* config,
900 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, 986 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
901 bool prefer_constraint_apis, 987 bool prefer_constraint_apis,
902 rtc::Thread* network_thread, 988 rtc::Thread* network_thread,
903 rtc::Thread* worker_thread) { 989 rtc::Thread* worker_thread) {
904 EXPECT_TRUE(!peer_connection_); 990 EXPECT_TRUE(!peer_connection_);
905 EXPECT_TRUE(!peer_connection_factory_); 991 EXPECT_TRUE(!peer_connection_factory_);
906 if (!prefer_constraint_apis) { 992 if (!prefer_constraint_apis) {
907 EXPECT_TRUE(!constraints); 993 EXPECT_TRUE(!constraints);
908 } 994 }
909 prefer_constraint_apis_ = prefer_constraint_apis; 995 prefer_constraint_apis_ = prefer_constraint_apis;
910 996
997 fake_network_manager_.reset(new rtc::FakeNetworkManager());
998 fake_network_manager_->AddInterface(rtc::SocketAddress("192.168.1.1", 0));
999
911 std::unique_ptr<cricket::PortAllocator> port_allocator( 1000 std::unique_ptr<cricket::PortAllocator> port_allocator(
912 new cricket::FakePortAllocator(network_thread, nullptr)); 1001 new cricket::BasicPortAllocator(fake_network_manager_.get()));
913 fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); 1002 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
914 1003
915 if (fake_audio_capture_module_ == nullptr) { 1004 if (fake_audio_capture_module_ == nullptr) {
916 return false; 1005 return false;
917 } 1006 }
918 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory(); 1007 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory();
919 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory(); 1008 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory();
920 rtc::Thread* const signaling_thread = rtc::Thread::Current(); 1009 rtc::Thread* const signaling_thread = rtc::Thread::Current();
921 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( 1010 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
922 network_thread, worker_thread, signaling_thread, 1011 network_thread, worker_thread, signaling_thread,
923 fake_audio_capture_module_, fake_video_encoder_factory_, 1012 fake_audio_capture_module_, fake_video_encoder_factory_,
924 fake_video_decoder_factory_); 1013 fake_video_decoder_factory_);
925 if (!peer_connection_factory_) { 1014 if (!peer_connection_factory_) {
926 return false; 1015 return false;
927 } 1016 }
928 if (options) { 1017 if (options) {
929 peer_connection_factory_->SetOptions(*options); 1018 peer_connection_factory_->SetOptions(*options);
930 } 1019 }
931 peer_connection_ = 1020 peer_connection_ =
932 CreatePeerConnection(std::move(port_allocator), constraints, config, 1021 CreatePeerConnection(std::move(port_allocator), constraints, config,
933 std::move(cert_generator)); 1022 std::move(cert_generator));
934
935 return peer_connection_.get() != nullptr; 1023 return peer_connection_.get() != nullptr;
936 } 1024 }
937 1025
938 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( 1026 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(
939 std::unique_ptr<cricket::PortAllocator> port_allocator, 1027 std::unique_ptr<cricket::PortAllocator> port_allocator,
940 const MediaConstraintsInterface* constraints, 1028 const MediaConstraintsInterface* constraints,
941 const PeerConnectionInterface::RTCConfiguration& config, 1029 const PeerConnectionInterface::RTCConfiguration* config,
942 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) { 1030 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
1031 // CreatePeerConnection with RTCConfiguration.
1032 PeerConnectionInterface::RTCConfiguration default_config;
1033
1034 if (!config) {
1035 config = &default_config;
1036 }
1037
943 return peer_connection_factory_->CreatePeerConnection( 1038 return peer_connection_factory_->CreatePeerConnection(
944 config, constraints, std::move(port_allocator), 1039 *config, constraints, std::move(port_allocator),
945 std::move(cert_generator), this); 1040 std::move(cert_generator), this);
946 } 1041 }
947 1042
948 void HandleIncomingOffer(const std::string& msg) { 1043 void HandleIncomingOffer(const std::string& msg) {
949 LOG(INFO) << id_ << "HandleIncomingOffer "; 1044 LOG(INFO) << id_ << "HandleIncomingOffer ";
950 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) { 1045 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) {
951 // If we are not sending any streams ourselves it is time to add some. 1046 // If we are not sending any streams ourselves it is time to add some.
952 AddMediaStream(true, true); 1047 AddMediaStream(true, true);
953 } 1048 }
954 std::unique_ptr<SessionDescriptionInterface> desc( 1049 std::unique_ptr<SessionDescriptionInterface> desc(
955 webrtc::CreateSessionDescription("offer", msg, nullptr)); 1050 webrtc::CreateSessionDescription("offer", msg, nullptr));
956 EXPECT_TRUE(DoSetRemoteDescription(desc.release())); 1051 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
957 // Set the RtpReceiverObserver after receivers are created. 1052 // Set the RtpReceiverObserver after receivers are created.
958 SetRtpReceiverObservers(); 1053 SetRtpReceiverObservers();
959 std::unique_ptr<SessionDescriptionInterface> answer; 1054 std::unique_ptr<SessionDescriptionInterface> answer;
960 EXPECT_TRUE(DoCreateAnswer(&answer)); 1055 EXPECT_TRUE(DoCreateAnswer(&answer));
961 std::string sdp; 1056 std::string sdp;
962 EXPECT_TRUE(answer->ToString(&sdp)); 1057 EXPECT_TRUE(answer->ToString(&sdp));
963 EXPECT_TRUE(DoSetLocalDescription(answer.release())); 1058 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
964 if (signaling_message_receiver_) { 1059 SendSdpMessage(webrtc::SessionDescriptionInterface::kAnswer, sdp);
965 signaling_message_receiver_->ReceiveSdpMessage(
966 webrtc::SessionDescriptionInterface::kAnswer, sdp);
967 }
968 } 1060 }
969 1061
970 void HandleIncomingAnswer(const std::string& msg) { 1062 void HandleIncomingAnswer(const std::string& msg) {
971 LOG(INFO) << id_ << "HandleIncomingAnswer"; 1063 LOG(INFO) << id_ << "HandleIncomingAnswer";
972 std::unique_ptr<SessionDescriptionInterface> desc( 1064 std::unique_ptr<SessionDescriptionInterface> desc(
973 webrtc::CreateSessionDescription("answer", msg, nullptr)); 1065 webrtc::CreateSessionDescription("answer", msg, nullptr));
974 EXPECT_TRUE(DoSetRemoteDescription(desc.release())); 1066 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
975 // Set the RtpReceiverObserver after receivers are created. 1067 // Set the RtpReceiverObserver after receivers are created.
976 SetRtpReceiverObservers(); 1068 SetRtpReceiverObservers();
977 } 1069 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp); 1150 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp);
1059 } 1151 }
1060 if (remove_cvo_) { 1152 if (remove_cvo_) {
1061 const char kSdpCvoExtenstion[] = "urn:3gpp:video-orientation"; 1153 const char kSdpCvoExtenstion[] = "urn:3gpp:video-orientation";
1062 RemoveLinesFromSdp(kSdpCvoExtenstion, sdp); 1154 RemoveLinesFromSdp(kSdpCvoExtenstion, sdp);
1063 } 1155 }
1064 } 1156 }
1065 1157
1066 std::string id_; 1158 std::string id_;
1067 1159
1160 std::unique_ptr<rtc::FakeNetworkManager> fake_network_manager_;
1161
1068 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; 1162 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
1069 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> 1163 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
1070 peer_connection_factory_; 1164 peer_connection_factory_;
1071 1165
1072 bool prefer_constraint_apis_ = true; 1166 bool prefer_constraint_apis_ = true;
1073 bool auto_add_stream_ = true; 1167 bool auto_add_stream_ = true;
1074 1168
1075 typedef std::pair<std::string, std::string> IceUfragPwdPair; 1169 typedef std::pair<std::string, std::string> IceUfragPwdPair;
1076 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_; 1170 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_;
1077 bool expect_ice_restart_ = false; 1171 bool expect_ice_restart_ = false;
(...skipping 10 matching lines...) Expand all
1088 removed_fake_video_renderers_; 1182 removed_fake_video_renderers_;
1089 // Needed to keep track of number of frames received when external decoder 1183 // Needed to keep track of number of frames received when external decoder
1090 // used. 1184 // used.
1091 FakeWebRtcVideoDecoderFactory* fake_video_decoder_factory_ = nullptr; 1185 FakeWebRtcVideoDecoderFactory* fake_video_decoder_factory_ = nullptr;
1092 FakeWebRtcVideoEncoderFactory* fake_video_encoder_factory_ = nullptr; 1186 FakeWebRtcVideoEncoderFactory* fake_video_encoder_factory_ = nullptr;
1093 bool video_decoder_factory_enabled_ = false; 1187 bool video_decoder_factory_enabled_ = false;
1094 webrtc::FakeConstraints video_constraints_; 1188 webrtc::FakeConstraints video_constraints_;
1095 1189
1096 // For remote peer communication. 1190 // For remote peer communication.
1097 SignalingMessageReceiver* signaling_message_receiver_ = nullptr; 1191 SignalingMessageReceiver* signaling_message_receiver_ = nullptr;
1192 int signaling_delay_ms_ = 0;
1098 1193
1099 // Store references to the video capturers we've created, so that we can stop 1194 // Store references to the video capturers we've created, so that we can stop
1100 // them, if required. 1195 // them, if required.
1101 std::vector<cricket::FakeVideoCapturer*> video_capturers_; 1196 std::vector<cricket::FakeVideoCapturer*> video_capturers_;
1102 webrtc::VideoRotation capture_rotation_ = webrtc::kVideoRotation_0; 1197 webrtc::VideoRotation capture_rotation_ = webrtc::kVideoRotation_0;
1103 // |local_video_renderer_| attached to the first created local video track. 1198 // |local_video_renderer_| attached to the first created local video track.
1104 std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_; 1199 std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_;
1105 1200
1106 webrtc::FakeConstraints offer_answer_constraints_; 1201 webrtc::FakeConstraints offer_answer_constraints_;
1107 PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_; 1202 PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_;
(...skipping 14 matching lines...) Expand all
1122 1217
1123 class P2PTestConductor : public testing::Test { 1218 class P2PTestConductor : public testing::Test {
1124 public: 1219 public:
1125 P2PTestConductor() 1220 P2PTestConductor()
1126 : pss_(new rtc::PhysicalSocketServer), 1221 : pss_(new rtc::PhysicalSocketServer),
1127 ss_(new rtc::VirtualSocketServer(pss_.get())), 1222 ss_(new rtc::VirtualSocketServer(pss_.get())),
1128 network_thread_(new rtc::Thread(ss_.get())), 1223 network_thread_(new rtc::Thread(ss_.get())),
1129 worker_thread_(rtc::Thread::Create()) { 1224 worker_thread_(rtc::Thread::Create()) {
1130 RTC_CHECK(network_thread_->Start()); 1225 RTC_CHECK(network_thread_->Start());
1131 RTC_CHECK(worker_thread_->Start()); 1226 RTC_CHECK(worker_thread_->Start());
1132 webrtc::PeerConnectionInterface::IceServer ice_server;
1133 ice_server.uri = "stun:stun.l.google.com:19302";
1134 config_.servers.push_back(ice_server);
1135 } 1227 }
1136 1228
1137 bool SessionActive() { 1229 bool SessionActive() {
1138 return initiating_client_->SessionActive() && 1230 return initiating_client_->SessionActive() &&
1139 receiving_client_->SessionActive(); 1231 receiving_client_->SessionActive();
1140 } 1232 }
1141 1233
1142 // Return true if the number of frames provided have been received 1234 // Return true if the number of frames provided have been received
1143 // on the video and audio tracks provided. 1235 // on the video and audio tracks provided.
1144 bool FramesHaveArrived(int audio_frames_to_receive, 1236 bool FramesHaveArrived(int audio_frames_to_receive,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 } 1319 }
1228 if (receiving_client_) { 1320 if (receiving_client_) {
1229 receiving_client_->set_signaling_message_receiver(nullptr); 1321 receiving_client_->set_signaling_message_receiver(nullptr);
1230 } 1322 }
1231 } 1323 }
1232 1324
1233 bool CreateTestClients() { return CreateTestClients(nullptr, nullptr); } 1325 bool CreateTestClients() { return CreateTestClients(nullptr, nullptr); }
1234 1326
1235 bool CreateTestClients(MediaConstraintsInterface* init_constraints, 1327 bool CreateTestClients(MediaConstraintsInterface* init_constraints,
1236 MediaConstraintsInterface* recv_constraints) { 1328 MediaConstraintsInterface* recv_constraints) {
1237 return CreateTestClients(init_constraints, nullptr, recv_constraints, 1329 return CreateTestClients(init_constraints, nullptr, nullptr,
1238 nullptr); 1330 recv_constraints, nullptr, nullptr);
1331 }
1332
1333 bool CreateTestClients(
1334 const PeerConnectionInterface::RTCConfiguration& init_config,
1335 const PeerConnectionInterface::RTCConfiguration& recv_config) {
1336 return CreateTestClients(nullptr, nullptr, &init_config, nullptr, nullptr,
1337 &recv_config);
1239 } 1338 }
1240 1339
1241 bool CreateTestClientsThatPreferNoConstraints() { 1340 bool CreateTestClientsThatPreferNoConstraints() {
1242 initiating_client_.reset( 1341 initiating_client_.reset(
1243 PeerConnectionTestClient::CreateClientPreferNoConstraints( 1342 PeerConnectionTestClient::CreateClientPreferNoConstraints(
1244 "Caller: ", nullptr, config_, network_thread_.get(), 1343 "Caller: ", nullptr, network_thread_.get(), worker_thread_.get()));
1245 worker_thread_.get()));
1246 receiving_client_.reset( 1344 receiving_client_.reset(
1247 PeerConnectionTestClient::CreateClientPreferNoConstraints( 1345 PeerConnectionTestClient::CreateClientPreferNoConstraints(
1248 "Callee: ", nullptr, config_, network_thread_.get(), 1346 "Callee: ", nullptr, network_thread_.get(), worker_thread_.get()));
1249 worker_thread_.get()));
1250 if (!initiating_client_ || !receiving_client_) { 1347 if (!initiating_client_ || !receiving_client_) {
1251 return false; 1348 return false;
1252 } 1349 }
1253 // Remember the choice for possible later resets of the clients. 1350 // Remember the choice for possible later resets of the clients.
1254 prefer_constraint_apis_ = false; 1351 prefer_constraint_apis_ = false;
1255 SetSignalingReceivers(); 1352 SetSignalingReceivers();
1256 return true; 1353 return true;
1257 } 1354 }
1258 1355
1259 void SetSignalingReceivers() { 1356 bool CreateTestClients(
1260 initiating_client_->set_signaling_message_receiver(receiving_client_.get()); 1357 MediaConstraintsInterface* init_constraints,
1261 receiving_client_->set_signaling_message_receiver(initiating_client_.get()); 1358 PeerConnectionFactory::Options* init_options,
1262 } 1359 const PeerConnectionInterface::RTCConfiguration* init_config,
1263 1360 MediaConstraintsInterface* recv_constraints,
1264 bool CreateTestClients(MediaConstraintsInterface* init_constraints, 1361 PeerConnectionFactory::Options* recv_options,
1265 PeerConnectionFactory::Options* init_options, 1362 const PeerConnectionInterface::RTCConfiguration* recv_config) {
1266 MediaConstraintsInterface* recv_constraints,
1267 PeerConnectionFactory::Options* recv_options) {
1268 initiating_client_.reset(PeerConnectionTestClient::CreateClient( 1363 initiating_client_.reset(PeerConnectionTestClient::CreateClient(
1269 "Caller: ", init_constraints, init_options, config_, 1364 "Caller: ", init_constraints, init_options, init_config,
1270 network_thread_.get(), worker_thread_.get())); 1365 network_thread_.get(), worker_thread_.get()));
1271 receiving_client_.reset(PeerConnectionTestClient::CreateClient( 1366 receiving_client_.reset(PeerConnectionTestClient::CreateClient(
1272 "Callee: ", recv_constraints, recv_options, config_, 1367 "Callee: ", recv_constraints, recv_options, recv_config,
1273 network_thread_.get(), worker_thread_.get())); 1368 network_thread_.get(), worker_thread_.get()));
1274 if (!initiating_client_ || !receiving_client_) { 1369 if (!initiating_client_ || !receiving_client_) {
1275 return false; 1370 return false;
1276 } 1371 }
1277 SetSignalingReceivers(); 1372 SetSignalingReceivers();
1278 return true; 1373 return true;
1279 } 1374 }
1280 1375
1376 void SetSignalingReceivers() {
1377 initiating_client_->set_signaling_message_receiver(receiving_client_.get());
1378 receiving_client_->set_signaling_message_receiver(initiating_client_.get());
1379 }
1380
1381 void SetSignalingDelayMs(int delay_ms) {
1382 initiating_client_->set_signaling_delay_ms(delay_ms);
1383 receiving_client_->set_signaling_delay_ms(delay_ms);
1384 }
1385
1281 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints, 1386 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints,
1282 const webrtc::FakeConstraints& recv_constraints) { 1387 const webrtc::FakeConstraints& recv_constraints) {
1283 initiating_client_->SetVideoConstraints(init_constraints); 1388 initiating_client_->SetVideoConstraints(init_constraints);
1284 receiving_client_->SetVideoConstraints(recv_constraints); 1389 receiving_client_->SetVideoConstraints(recv_constraints);
1285 } 1390 }
1286 1391
1287 void SetCaptureRotation(webrtc::VideoRotation rotation) { 1392 void SetCaptureRotation(webrtc::VideoRotation rotation) {
1288 initiating_client_->SetCaptureRotation(rotation); 1393 initiating_client_->SetCaptureRotation(rotation);
1289 receiving_client_->SetCaptureRotation(rotation); 1394 receiving_client_->SetCaptureRotation(rotation);
1290 } 1395 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1363 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, 1468 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1364 true); 1469 true);
1365 1470
1366 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( 1471 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
1367 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? 1472 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
1368 new FakeRTCCertificateGenerator() : nullptr); 1473 new FakeRTCCertificateGenerator() : nullptr);
1369 cert_generator->use_alternate_key(); 1474 cert_generator->use_alternate_key();
1370 1475
1371 // Make sure the new client is using a different certificate. 1476 // Make sure the new client is using a different certificate.
1372 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore( 1477 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore(
1373 "New Peer: ", &setup_constraints, nullptr, config_, 1478 "New Peer: ", &setup_constraints, nullptr, nullptr,
1374 std::move(cert_generator), prefer_constraint_apis_, 1479 std::move(cert_generator), prefer_constraint_apis_,
1375 network_thread_.get(), worker_thread_.get()); 1480 network_thread_.get(), worker_thread_.get());
1376 } 1481 }
1377 1482
1378 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { 1483 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) {
1379 // Messages may get lost on the unreliable DataChannel, so we send multiple 1484 // Messages may get lost on the unreliable DataChannel, so we send multiple
1380 // times to avoid test flakiness. 1485 // times to avoid test flakiness.
1381 static const size_t kSendAttempts = 5; 1486 static const size_t kSendAttempts = 5;
1382 1487
1383 for (size_t i = 0; i < kSendAttempts; ++i) { 1488 for (size_t i = 0; i < kSendAttempts; ++i) {
1384 dc->Send(DataBuffer(data)); 1489 dc->Send(DataBuffer(data));
1385 } 1490 }
1386 } 1491 }
1387 1492
1493 rtc::Thread* network_thread() { return network_thread_.get(); }
1494
1388 rtc::VirtualSocketServer* virtual_socket_server() { return ss_.get(); } 1495 rtc::VirtualSocketServer* virtual_socket_server() { return ss_.get(); }
1389 1496
1390 PeerConnectionTestClient* initializing_client() { 1497 PeerConnectionTestClient* initializing_client() {
1391 return initiating_client_.get(); 1498 return initiating_client_.get();
1392 } 1499 }
1393 1500
1394 // Set the |initiating_client_| to the |client| passed in and return the 1501 // Set the |initiating_client_| to the |client| passed in and return the
1395 // original |initiating_client_|. 1502 // original |initiating_client_|.
1396 PeerConnectionTestClient* set_initializing_client( 1503 PeerConnectionTestClient* set_initializing_client(
1397 PeerConnectionTestClient* client) { 1504 PeerConnectionTestClient* client) {
1398 PeerConnectionTestClient* old = initiating_client_.release(); 1505 PeerConnectionTestClient* old = initiating_client_.release();
1399 initiating_client_.reset(client); 1506 initiating_client_.reset(client);
1400 return old; 1507 return old;
1401 } 1508 }
1402 1509
1403 PeerConnectionTestClient* receiving_client() { 1510 PeerConnectionTestClient* receiving_client() {
1404 return receiving_client_.get(); 1511 return receiving_client_.get();
1405 } 1512 }
1406 1513
1407 // Set the |receiving_client_| to the |client| passed in and return the 1514 // Set the |receiving_client_| to the |client| passed in and return the
1408 // original |receiving_client_|. 1515 // original |receiving_client_|.
1409 PeerConnectionTestClient* set_receiving_client( 1516 PeerConnectionTestClient* set_receiving_client(
1410 PeerConnectionTestClient* client) { 1517 PeerConnectionTestClient* client) {
1411 PeerConnectionTestClient* old = receiving_client_.release(); 1518 PeerConnectionTestClient* old = receiving_client_.release();
1412 receiving_client_.reset(client); 1519 receiving_client_.reset(client);
1413 return old; 1520 return old;
1414 } 1521 }
1415 webrtc::PeerConnectionInterface::RTCConfiguration* config() {
1416 return &config_;
1417 }
1418 1522
1419 bool AllObserversReceived( 1523 bool AllObserversReceived(
1420 const std::vector<std::unique_ptr<MockRtpReceiverObserver>>& observers) { 1524 const std::vector<std::unique_ptr<MockRtpReceiverObserver>>& observers) {
1421 for (auto& observer : observers) { 1525 for (auto& observer : observers) {
1422 if (!observer->first_packet_received()) { 1526 if (!observer->first_packet_received()) {
1423 return false; 1527 return false;
1424 } 1528 }
1425 } 1529 }
1426 return true; 1530 return true;
1427 } 1531 }
1428 1532
1429 void TestGcmNegotiation(bool local_gcm_enabled, bool remote_gcm_enabled, 1533 void TestGcmNegotiation(bool local_gcm_enabled, bool remote_gcm_enabled,
1430 int expected_cipher_suite) { 1534 int expected_cipher_suite) {
1431 PeerConnectionFactory::Options init_options; 1535 PeerConnectionFactory::Options init_options;
1432 init_options.crypto_options.enable_gcm_crypto_suites = local_gcm_enabled; 1536 init_options.crypto_options.enable_gcm_crypto_suites = local_gcm_enabled;
1433 PeerConnectionFactory::Options recv_options; 1537 PeerConnectionFactory::Options recv_options;
1434 recv_options.crypto_options.enable_gcm_crypto_suites = remote_gcm_enabled; 1538 recv_options.crypto_options.enable_gcm_crypto_suites = remote_gcm_enabled;
1435 ASSERT_TRUE( 1539 ASSERT_TRUE(CreateTestClients(nullptr, &init_options, nullptr, nullptr,
1436 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); 1540 &recv_options, nullptr));
1437 rtc::scoped_refptr<webrtc::FakeMetricsObserver> 1541 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1438 init_observer = 1542 init_observer =
1439 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); 1543 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1440 initializing_client()->pc()->RegisterUMAObserver(init_observer); 1544 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1441 LocalP2PTest(); 1545 LocalP2PTest();
1442 1546
1443 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite), 1547 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite),
1444 initializing_client()->GetSrtpCipherStats(), 1548 initializing_client()->GetSrtpCipherStats(),
1445 kMaxWaitMs); 1549 kMaxWaitMs);
1446 EXPECT_EQ(1, 1550 EXPECT_EQ(1,
1447 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, 1551 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1448 expected_cipher_suite)); 1552 expected_cipher_suite));
1449 } 1553 }
1450 1554
1451 private: 1555 private:
1452 // |ss_| is used by |network_thread_| so it must be destroyed later. 1556 // |ss_| is used by |network_thread_| so it must be destroyed later.
1453 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 1557 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1454 std::unique_ptr<rtc::VirtualSocketServer> ss_; 1558 std::unique_ptr<rtc::VirtualSocketServer> ss_;
1455 // |network_thread_| and |worker_thread_| are used by both 1559 // |network_thread_| and |worker_thread_| are used by both
1456 // |initiating_client_| and |receiving_client_| so they must be destroyed 1560 // |initiating_client_| and |receiving_client_| so they must be destroyed
1457 // later. 1561 // later.
1458 std::unique_ptr<rtc::Thread> network_thread_; 1562 std::unique_ptr<rtc::Thread> network_thread_;
1459 std::unique_ptr<rtc::Thread> worker_thread_; 1563 std::unique_ptr<rtc::Thread> worker_thread_;
1460 std::unique_ptr<PeerConnectionTestClient> initiating_client_; 1564 std::unique_ptr<PeerConnectionTestClient> initiating_client_;
1461 std::unique_ptr<PeerConnectionTestClient> receiving_client_; 1565 std::unique_ptr<PeerConnectionTestClient> receiving_client_;
1462 bool prefer_constraint_apis_ = true; 1566 bool prefer_constraint_apis_ = true;
1463 webrtc::PeerConnectionInterface::RTCConfiguration config_;
1464 }; 1567 };
1465 1568
1466 // Disable for TSan v2, see 1569 // Disable for TSan v2, see
1467 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. 1570 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
1468 #if !defined(THREAD_SANITIZER) 1571 #if !defined(THREAD_SANITIZER)
1469 1572
1470 TEST_F(P2PTestConductor, TestRtpReceiverObserverCallbackFunction) { 1573 TEST_F(P2PTestConductor, TestRtpReceiverObserverCallbackFunction) {
1471 ASSERT_TRUE(CreateTestClients()); 1574 ASSERT_TRUE(CreateTestClients());
1472 LocalP2PTest(); 1575 LocalP2PTest();
1473 EXPECT_TRUE_WAIT( 1576 EXPECT_TRUE_WAIT(
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1796 initializing_client()->GetBytesSentStats(local_video_track) > 0, 1899 initializing_client()->GetBytesSentStats(local_video_track) > 0,
1797 kMaxWaitForStatsMs); 1900 kMaxWaitForStatsMs);
1798 } 1901 }
1799 1902
1800 // Test that DTLS 1.0 is used if both sides only support DTLS 1.0. 1903 // Test that DTLS 1.0 is used if both sides only support DTLS 1.0.
1801 TEST_F(P2PTestConductor, GetDtls12None) { 1904 TEST_F(P2PTestConductor, GetDtls12None) {
1802 PeerConnectionFactory::Options init_options; 1905 PeerConnectionFactory::Options init_options;
1803 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; 1906 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1804 PeerConnectionFactory::Options recv_options; 1907 PeerConnectionFactory::Options recv_options;
1805 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; 1908 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1806 ASSERT_TRUE( 1909 ASSERT_TRUE(CreateTestClients(nullptr, &init_options, nullptr, nullptr,
1807 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); 1910 &recv_options, nullptr));
1808 rtc::scoped_refptr<webrtc::FakeMetricsObserver> 1911 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1809 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); 1912 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1810 initializing_client()->pc()->RegisterUMAObserver(init_observer); 1913 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1811 LocalP2PTest(); 1914 LocalP2PTest();
1812 1915
1813 EXPECT_TRUE_WAIT( 1916 EXPECT_TRUE_WAIT(
1814 rtc::SSLStreamAdapter::IsAcceptableCipher( 1917 rtc::SSLStreamAdapter::IsAcceptableCipher(
1815 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), 1918 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1816 kMaxWaitForStatsMs); 1919 kMaxWaitForStatsMs);
1817 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), 1920 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
1818 initializing_client()->GetSrtpCipherStats(), 1921 initializing_client()->GetSrtpCipherStats(),
1819 kMaxWaitForStatsMs); 1922 kMaxWaitForStatsMs);
1820 EXPECT_EQ(1, 1923 EXPECT_EQ(1,
1821 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, 1924 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1822 kDefaultSrtpCryptoSuite)); 1925 kDefaultSrtpCryptoSuite));
1823 } 1926 }
1824 1927
1825 // Test that DTLS 1.2 is used if both ends support it. 1928 // Test that DTLS 1.2 is used if both ends support it.
1826 TEST_F(P2PTestConductor, GetDtls12Both) { 1929 TEST_F(P2PTestConductor, GetDtls12Both) {
1827 PeerConnectionFactory::Options init_options; 1930 PeerConnectionFactory::Options init_options;
1828 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; 1931 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1829 PeerConnectionFactory::Options recv_options; 1932 PeerConnectionFactory::Options recv_options;
1830 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; 1933 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1831 ASSERT_TRUE( 1934 ASSERT_TRUE(CreateTestClients(nullptr, &init_options, nullptr, nullptr,
1832 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); 1935 &recv_options, nullptr));
1833 rtc::scoped_refptr<webrtc::FakeMetricsObserver> 1936 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1834 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); 1937 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1835 initializing_client()->pc()->RegisterUMAObserver(init_observer); 1938 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1836 LocalP2PTest(); 1939 LocalP2PTest();
1837 1940
1838 EXPECT_TRUE_WAIT( 1941 EXPECT_TRUE_WAIT(
1839 rtc::SSLStreamAdapter::IsAcceptableCipher( 1942 rtc::SSLStreamAdapter::IsAcceptableCipher(
1840 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), 1943 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1841 kMaxWaitForStatsMs); 1944 kMaxWaitForStatsMs);
1842 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), 1945 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
1843 initializing_client()->GetSrtpCipherStats(), 1946 initializing_client()->GetSrtpCipherStats(),
1844 kMaxWaitForStatsMs); 1947 kMaxWaitForStatsMs);
1845 EXPECT_EQ(1, 1948 EXPECT_EQ(1,
1846 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, 1949 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1847 kDefaultSrtpCryptoSuite)); 1950 kDefaultSrtpCryptoSuite));
1848 } 1951 }
1849 1952
1850 // Test that DTLS 1.0 is used if the initator supports DTLS 1.2 and the 1953 // Test that DTLS 1.0 is used if the initator supports DTLS 1.2 and the
1851 // received supports 1.0. 1954 // received supports 1.0.
1852 TEST_F(P2PTestConductor, GetDtls12Init) { 1955 TEST_F(P2PTestConductor, GetDtls12Init) {
1853 PeerConnectionFactory::Options init_options; 1956 PeerConnectionFactory::Options init_options;
1854 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; 1957 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1855 PeerConnectionFactory::Options recv_options; 1958 PeerConnectionFactory::Options recv_options;
1856 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; 1959 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1857 ASSERT_TRUE( 1960 ASSERT_TRUE(CreateTestClients(nullptr, &init_options, nullptr, nullptr,
1858 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); 1961 &recv_options, nullptr));
1859 rtc::scoped_refptr<webrtc::FakeMetricsObserver> 1962 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1860 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); 1963 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1861 initializing_client()->pc()->RegisterUMAObserver(init_observer); 1964 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1862 LocalP2PTest(); 1965 LocalP2PTest();
1863 1966
1864 EXPECT_TRUE_WAIT( 1967 EXPECT_TRUE_WAIT(
1865 rtc::SSLStreamAdapter::IsAcceptableCipher( 1968 rtc::SSLStreamAdapter::IsAcceptableCipher(
1866 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), 1969 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1867 kMaxWaitForStatsMs); 1970 kMaxWaitForStatsMs);
1868 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), 1971 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
1869 initializing_client()->GetSrtpCipherStats(), 1972 initializing_client()->GetSrtpCipherStats(),
1870 kMaxWaitForStatsMs); 1973 kMaxWaitForStatsMs);
1871 EXPECT_EQ(1, 1974 EXPECT_EQ(1,
1872 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, 1975 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1873 kDefaultSrtpCryptoSuite)); 1976 kDefaultSrtpCryptoSuite));
1874 } 1977 }
1875 1978
1876 // Test that DTLS 1.0 is used if the initator supports DTLS 1.0 and the 1979 // Test that DTLS 1.0 is used if the initator supports DTLS 1.0 and the
1877 // received supports 1.2. 1980 // received supports 1.2.
1878 TEST_F(P2PTestConductor, GetDtls12Recv) { 1981 TEST_F(P2PTestConductor, GetDtls12Recv) {
1879 PeerConnectionFactory::Options init_options; 1982 PeerConnectionFactory::Options init_options;
1880 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; 1983 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1881 PeerConnectionFactory::Options recv_options; 1984 PeerConnectionFactory::Options recv_options;
1882 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; 1985 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1883 ASSERT_TRUE( 1986 ASSERT_TRUE(CreateTestClients(nullptr, &init_options, nullptr, nullptr,
1884 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); 1987 &recv_options, nullptr));
1885 rtc::scoped_refptr<webrtc::FakeMetricsObserver> 1988 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1886 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); 1989 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1887 initializing_client()->pc()->RegisterUMAObserver(init_observer); 1990 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1888 LocalP2PTest(); 1991 LocalP2PTest();
1889 1992
1890 EXPECT_TRUE_WAIT( 1993 EXPECT_TRUE_WAIT(
1891 rtc::SSLStreamAdapter::IsAcceptableCipher( 1994 rtc::SSLStreamAdapter::IsAcceptableCipher(
1892 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), 1995 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1893 kMaxWaitForStatsMs); 1996 kMaxWaitForStatsMs);
1894 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), 1997 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
2169 EXPECT_TRUE(audio_candidates_reciever_restart->at(0)->ToString( 2272 EXPECT_TRUE(audio_candidates_reciever_restart->at(0)->ToString(
2170 &receiver_candidate_restart)); 2273 &receiver_candidate_restart));
2171 2274
2172 // Verify that the first candidates in the local session descriptions has 2275 // Verify that the first candidates in the local session descriptions has
2173 // changed. 2276 // changed.
2174 EXPECT_NE(initiator_candidate, initiator_candidate_restart); 2277 EXPECT_NE(initiator_candidate, initiator_candidate_restart);
2175 EXPECT_NE(receiver_candidate, receiver_candidate_restart); 2278 EXPECT_NE(receiver_candidate, receiver_candidate_restart);
2176 } 2279 }
2177 2280
2178 TEST_F(P2PTestConductor, IceRenominationDisabled) { 2281 TEST_F(P2PTestConductor, IceRenominationDisabled) {
2179 config()->enable_ice_renomination = false; 2282 PeerConnectionInterface::RTCConfiguration config;
2180 ASSERT_TRUE(CreateTestClients()); 2283 config.enable_ice_renomination = false;
2284 ASSERT_TRUE(CreateTestClients(config, config));
2181 LocalP2PTest(); 2285 LocalP2PTest();
2182 2286
2183 initializing_client()->VerifyLocalIceRenomination(); 2287 initializing_client()->VerifyLocalIceRenomination();
2184 receiving_client()->VerifyLocalIceRenomination(); 2288 receiving_client()->VerifyLocalIceRenomination();
2185 initializing_client()->VerifyRemoteIceRenomination(); 2289 initializing_client()->VerifyRemoteIceRenomination();
2186 receiving_client()->VerifyRemoteIceRenomination(); 2290 receiving_client()->VerifyRemoteIceRenomination();
2187 } 2291 }
2188 2292
2189 TEST_F(P2PTestConductor, IceRenominationEnabled) { 2293 TEST_F(P2PTestConductor, IceRenominationEnabled) {
2190 config()->enable_ice_renomination = true; 2294 PeerConnectionInterface::RTCConfiguration config;
2191 ASSERT_TRUE(CreateTestClients()); 2295 config.enable_ice_renomination = true;
2296 ASSERT_TRUE(CreateTestClients(config, config));
2192 initializing_client()->SetExpectIceRenomination(true); 2297 initializing_client()->SetExpectIceRenomination(true);
2193 initializing_client()->SetExpectRemoteIceRenomination(true); 2298 initializing_client()->SetExpectRemoteIceRenomination(true);
2194 receiving_client()->SetExpectIceRenomination(true); 2299 receiving_client()->SetExpectIceRenomination(true);
2195 receiving_client()->SetExpectRemoteIceRenomination(true); 2300 receiving_client()->SetExpectRemoteIceRenomination(true);
2196 LocalP2PTest(); 2301 LocalP2PTest();
2197 2302
2198 initializing_client()->VerifyLocalIceRenomination(); 2303 initializing_client()->VerifyLocalIceRenomination();
2199 receiving_client()->VerifyLocalIceRenomination(); 2304 receiving_client()->VerifyLocalIceRenomination();
2200 initializing_client()->VerifyRemoteIceRenomination(); 2305 initializing_client()->VerifyRemoteIceRenomination();
2201 receiving_client()->VerifyRemoteIceRenomination(); 2306 receiving_client()->VerifyRemoteIceRenomination();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2261 EXPECT_TRUE( 2366 EXPECT_TRUE(
2262 video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack(""))); 2367 video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack("")));
2263 EXPECT_TRUE_WAIT(FramesHaveArrived(kEndAudioFrameCount, kEndVideoFrameCount), 2368 EXPECT_TRUE_WAIT(FramesHaveArrived(kEndAudioFrameCount, kEndVideoFrameCount),
2264 kMaxWaitForFramesMs); 2369 kMaxWaitForFramesMs);
2265 } 2370 }
2266 2371
2267 #ifdef HAVE_QUIC 2372 #ifdef HAVE_QUIC
2268 // This test sets up a call between two parties using QUIC instead of DTLS for 2373 // This test sets up a call between two parties using QUIC instead of DTLS for
2269 // audio and video, and a QUIC data channel. 2374 // audio and video, and a QUIC data channel.
2270 TEST_F(P2PTestConductor, LocalP2PTestQuicDataChannel) { 2375 TEST_F(P2PTestConductor, LocalP2PTestQuicDataChannel) {
2271 config()->enable_quic = true; 2376 PeerConnectionInterface::RTCConfiguration quic_config;
2272 ASSERT_TRUE(CreateTestClients()); 2377 quic_config.enable_quic = true;
2378 ASSERT_TRUE(CreateTestClients(quic_config, quic_config));
2273 webrtc::DataChannelInit init; 2379 webrtc::DataChannelInit init;
2274 init.ordered = false; 2380 init.ordered = false;
2275 init.reliable = true; 2381 init.reliable = true;
2276 init.id = 1; 2382 init.id = 1;
2277 initializing_client()->CreateDataChannel(&init); 2383 initializing_client()->CreateDataChannel(&init);
2278 receiving_client()->CreateDataChannel(&init); 2384 receiving_client()->CreateDataChannel(&init);
2279 LocalP2PTest(); 2385 LocalP2PTest();
2280 ASSERT_NE(nullptr, initializing_client()->data_channel()); 2386 ASSERT_NE(nullptr, initializing_client()->data_channel());
2281 ASSERT_NE(nullptr, receiving_client()->data_channel()); 2387 ASSERT_NE(nullptr, receiving_client()->data_channel());
2282 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), 2388 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
2283 kMaxWaitMs); 2389 kMaxWaitMs);
2284 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), kMaxWaitMs); 2390 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), kMaxWaitMs);
2285 2391
2286 std::string data = "hello world"; 2392 std::string data = "hello world";
2287 2393
2288 initializing_client()->data_channel()->Send(DataBuffer(data)); 2394 initializing_client()->data_channel()->Send(DataBuffer(data));
2289 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(), 2395 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(),
2290 kMaxWaitMs); 2396 kMaxWaitMs);
2291 2397
2292 receiving_client()->data_channel()->Send(DataBuffer(data)); 2398 receiving_client()->data_channel()->Send(DataBuffer(data));
2293 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(), 2399 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(),
2294 kMaxWaitMs); 2400 kMaxWaitMs);
2295 } 2401 }
2296 2402
2297 // Tests that negotiation of QUIC data channels is completed without error. 2403 // Tests that negotiation of QUIC data channels is completed without error.
2298 TEST_F(P2PTestConductor, NegotiateQuicDataChannel) { 2404 TEST_F(P2PTestConductor, NegotiateQuicDataChannel) {
2299 config()->enable_quic = true; 2405 PeerConnectionInterface::RTCConfiguration quic_config;
2406 quic_config.enable_quic = true;
2407 ASSERT_TRUE(CreateTestClients(quic_config, quic_config));
2300 FakeConstraints constraints; 2408 FakeConstraints constraints;
2301 constraints.SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true); 2409 constraints.SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true);
2302 ASSERT_TRUE(CreateTestClients(&constraints, &constraints)); 2410 ASSERT_TRUE(CreateTestClients(&constraints, &constraints));
2303 webrtc::DataChannelInit init; 2411 webrtc::DataChannelInit init;
2304 init.ordered = false; 2412 init.ordered = false;
2305 init.reliable = true; 2413 init.reliable = true;
2306 init.id = 1; 2414 init.id = 1;
2307 initializing_client()->CreateDataChannel(&init); 2415 initializing_client()->CreateDataChannel(&init);
2308 initializing_client()->Negotiate(false, false); 2416 initializing_client()->Negotiate(false, false);
2309 } 2417 }
2310 2418
2311 // This test sets up a JSEP call using QUIC. The callee only receives video. 2419 // This test sets up a JSEP call using QUIC. The callee only receives video.
2312 TEST_F(P2PTestConductor, LocalP2PTestVideoOnlyWithQuic) { 2420 TEST_F(P2PTestConductor, LocalP2PTestVideoOnlyWithQuic) {
2313 config()->enable_quic = true; 2421 PeerConnectionInterface::RTCConfiguration quic_config;
2314 ASSERT_TRUE(CreateTestClients()); 2422 quic_config.enable_quic = true;
2423 ASSERT_TRUE(CreateTestClients(quic_config, quic_config));
2315 receiving_client()->SetReceiveAudioVideo(false, true); 2424 receiving_client()->SetReceiveAudioVideo(false, true);
2316 LocalP2PTest(); 2425 LocalP2PTest();
2317 } 2426 }
2318 2427
2319 // This test sets up a JSEP call using QUIC. The callee only receives audio. 2428 // This test sets up a JSEP call using QUIC. The callee only receives audio.
2320 TEST_F(P2PTestConductor, LocalP2PTestAudioOnlyWithQuic) { 2429 TEST_F(P2PTestConductor, LocalP2PTestAudioOnlyWithQuic) {
2321 config()->enable_quic = true; 2430 PeerConnectionInterface::RTCConfiguration quic_config;
2322 ASSERT_TRUE(CreateTestClients()); 2431 quic_config.enable_quic = true;
2432 ASSERT_TRUE(CreateTestClients(quic_config, quic_config));
2323 receiving_client()->SetReceiveAudioVideo(true, false); 2433 receiving_client()->SetReceiveAudioVideo(true, false);
2324 LocalP2PTest(); 2434 LocalP2PTest();
2325 } 2435 }
2326 2436
2327 // This test sets up a JSEP call using QUIC. The callee rejects both audio and 2437 // This test sets up a JSEP call using QUIC. The callee rejects both audio and
2328 // video. 2438 // video.
2329 TEST_F(P2PTestConductor, LocalP2PTestNoVideoAudioWithQuic) { 2439 TEST_F(P2PTestConductor, LocalP2PTestNoVideoAudioWithQuic) {
2330 config()->enable_quic = true; 2440 PeerConnectionInterface::RTCConfiguration quic_config;
2331 ASSERT_TRUE(CreateTestClients()); 2441 quic_config.enable_quic = true;
2442 ASSERT_TRUE(CreateTestClients(quic_config, quic_config));
2332 receiving_client()->SetReceiveAudioVideo(false, false); 2443 receiving_client()->SetReceiveAudioVideo(false, false);
2333 LocalP2PTest(); 2444 LocalP2PTest();
2334 } 2445 }
2335 2446
2336 #endif // HAVE_QUIC 2447 #endif // HAVE_QUIC
2337 2448
2338 TEST_F(P2PTestConductor, ForwardVideoOnlyStream) { 2449 TEST_F(P2PTestConductor, ForwardVideoOnlyStream) {
2339 ASSERT_TRUE(CreateTestClients()); 2450 ASSERT_TRUE(CreateTestClients());
2340 // One-way stream 2451 // One-way stream
2341 receiving_client()->set_auto_add_stream(false); 2452 receiving_client()->set_auto_add_stream(false);
(...skipping 19 matching lines...) Expand all
2361 // Echo the stream back. 2472 // Echo the stream back.
2362 receiving_client()->pc()->AddStream( 2473 receiving_client()->pc()->AddStream(
2363 receiving_client()->remote_streams()->at(0)); 2474 receiving_client()->remote_streams()->at(0));
2364 receiving_client()->Negotiate(); 2475 receiving_client()->Negotiate();
2365 2476
2366 EXPECT_TRUE_WAIT( 2477 EXPECT_TRUE_WAIT(
2367 initializing_client()->VideoFramesReceivedCheck(kEndVideoFrameCount), 2478 initializing_client()->VideoFramesReceivedCheck(kEndVideoFrameCount),
2368 kMaxWaitForFramesMs); 2479 kMaxWaitForFramesMs);
2369 } 2480 }
2370 2481
2482 // Test that we achieve the expected end-to-end connection time, using a
2483 // fake clock and simulated latency on the media and signaling paths.
2484 // We use a TURN<->TURN connection because this is usually the quickest to
2485 // set up initially, especially when we're confident the connection will work
2486 // and can start sending media before we get a STUN response.
2487 //
2488 // With various optimizations enabled, here are the network delays we expect to
2489 // be on the critical path:
2490 // 1. 2 signaling trips: Signaling offer and offerer's TURN candidate, then
2491 // signaling answer (with DTLS fingerprint).
2492 // 2. 9 media hops: Rest of the DTLS handshake. 3 hops in each direction when
2493 // using TURN<->TURN pair, and DTLS exchange is 4 packets,
2494 // the first of which should have arrived before the answer.
2495 TEST_F(P2PTestConductor, EndToEndConnectionTimeWithTurnTurnPair) {
2496 rtc::ScopedFakeClock fake_clock;
2497 // Some things use a time of "0" as a special value, so we need to start out
2498 // the fake clock at a nonzero time.
2499 // TODO(deadbeef): Fix this.
2500 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
2501
2502 static constexpr int media_hop_delay_ms = 50;
2503 static constexpr int signaling_trip_delay_ms = 500;
2504 // For explanation of these values, see comment above.
2505 static constexpr int required_media_hops = 9;
2506 static constexpr int required_signaling_trips = 2;
2507 // For internal delays (such as posting an event asychronously).
2508 static constexpr int allowed_internal_delay_ms = 20;
2509 static constexpr int total_connection_time_ms =
2510 media_hop_delay_ms * required_media_hops +
2511 signaling_trip_delay_ms * required_signaling_trips +
2512 allowed_internal_delay_ms;
2513
2514 static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0",
2515 3478};
2516 static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1",
2517 0};
2518 static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0",
2519 3478};
2520 static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1",
2521 0};
2522 cricket::TestTurnServer turn_server_1(network_thread(),
2523 turn_server_1_internal_address,
2524 turn_server_1_external_address);
2525 cricket::TestTurnServer turn_server_2(network_thread(),
2526 turn_server_2_internal_address,
2527 turn_server_2_external_address);
2528 // Bypass permission check on received packets so media can be sent before
2529 // the candidate is signaled.
2530 turn_server_1.set_enable_permission_checks(false);
2531 turn_server_2.set_enable_permission_checks(false);
2532
2533 PeerConnectionInterface::RTCConfiguration client_1_config;
2534 webrtc::PeerConnectionInterface::IceServer ice_server_1;
2535 ice_server_1.urls.push_back("turn:88.88.88.0:3478");
2536 ice_server_1.username = "test";
2537 ice_server_1.password = "test";
2538 client_1_config.servers.push_back(ice_server_1);
2539 client_1_config.type = webrtc::PeerConnectionInterface::kRelay;
2540 client_1_config.presume_writable_when_fully_relayed = true;
2541
2542 PeerConnectionInterface::RTCConfiguration client_2_config;
2543 webrtc::PeerConnectionInterface::IceServer ice_server_2;
2544 ice_server_2.urls.push_back("turn:99.99.99.0:3478");
2545 ice_server_2.username = "test";
2546 ice_server_2.password = "test";
2547 client_2_config.servers.push_back(ice_server_2);
2548 client_2_config.type = webrtc::PeerConnectionInterface::kRelay;
2549 client_2_config.presume_writable_when_fully_relayed = true;
2550
2551 ASSERT_TRUE(CreateTestClients(client_1_config, client_2_config));
2552 // Set up the simulated delays.
2553 SetSignalingDelayMs(signaling_trip_delay_ms);
2554 virtual_socket_server()->set_delay_mean(media_hop_delay_ms);
2555 virtual_socket_server()->UpdateDelayDistribution();
2556
2557 initializing_client()->SetOfferToReceiveAudioVideo(true, true);
2558 initializing_client()->Negotiate();
2559 // TODO(deadbeef): kIceConnectionConnected currently means both ICE and DTLS
2560 // are connected. This is an important distinction. Once we have separate ICE
2561 // and DTLS state, this check needs to use the DTLS state.
2562 EXPECT_TRUE_SIMULATED_WAIT(
2563 (receiving_client()->ice_connection_state() ==
2564 webrtc::PeerConnectionInterface::kIceConnectionConnected ||
2565 receiving_client()->ice_connection_state() ==
2566 webrtc::PeerConnectionInterface::kIceConnectionCompleted) &&
2567 (initializing_client()->ice_connection_state() ==
2568 webrtc::PeerConnectionInterface::kIceConnectionConnected ||
2569 initializing_client()->ice_connection_state() ==
2570 webrtc::PeerConnectionInterface::kIceConnectionCompleted),
2571 total_connection_time_ms, fake_clock);
2572 // Need to free the clients here since they're using things we created on
2573 // the stack.
2574 delete set_initializing_client(nullptr);
2575 delete set_receiving_client(nullptr);
2576 }
2577
2371 class IceServerParsingTest : public testing::Test { 2578 class IceServerParsingTest : public testing::Test {
2372 public: 2579 public:
2373 // Convenience for parsing a single URL. 2580 // Convenience for parsing a single URL.
2374 bool ParseUrl(const std::string& url) { 2581 bool ParseUrl(const std::string& url) {
2375 return ParseUrl(url, std::string(), std::string()); 2582 return ParseUrl(url, std::string(), std::string());
2376 } 2583 }
2377 2584
2378 bool ParseUrl(const std::string& url, 2585 bool ParseUrl(const std::string& url,
2379 const std::string& username, 2586 const std::string& username,
2380 const std::string& password) { 2587 const std::string& password) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2553 server.urls.push_back("turn:hostname2"); 2760 server.urls.push_back("turn:hostname2");
2554 servers.push_back(server); 2761 servers.push_back(server);
2555 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); 2762 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
2556 EXPECT_EQ(2U, turn_servers_.size()); 2763 EXPECT_EQ(2U, turn_servers_.size());
2557 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); 2764 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority);
2558 } 2765 }
2559 2766
2560 #endif // if !defined(THREAD_SANITIZER) 2767 #endif // if !defined(THREAD_SANITIZER)
2561 2768
2562 } // namespace 2769 } // 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