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

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: Created 4 years, 5 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') | webrtc/base/fakenetwork.h » ('J')
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 97
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 #endif 105 #endif
104 106
107 // Used to simulate signaling ICE/SDP between two PeerConnections.
108 enum { MSG_SDP_MESSAGE, MSG_ICE_MESSAGE };
109
105 static void RemoveLinesFromSdp(const std::string& line_start, 110 static void RemoveLinesFromSdp(const std::string& line_start,
106 std::string* sdp) { 111 std::string* sdp) {
107 const char kSdpLineEnd[] = "\r\n"; 112 const char kSdpLineEnd[] = "\r\n";
108 size_t ssrc_pos = 0; 113 size_t ssrc_pos = 0;
109 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) != 114 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) !=
110 std::string::npos) { 115 std::string::npos) {
111 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos); 116 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos);
112 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd)); 117 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd));
113 } 118 }
114 } 119 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 165
161 virtual ~MockRtpReceiverObserver() {} 166 virtual ~MockRtpReceiverObserver() {}
162 167
163 private: 168 private:
164 bool first_packet_received_ = false; 169 bool first_packet_received_ = false;
165 cricket::MediaType expected_media_type_; 170 cricket::MediaType expected_media_type_;
166 }; 171 };
167 172
168 class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, 173 class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
169 public SignalingMessageReceiver, 174 public SignalingMessageReceiver,
170 public ObserverInterface { 175 public ObserverInterface,
176 public rtc::MessageHandler {
171 public: 177 public:
178 // If |config| is not provided, uses a default constructed RTCConfiguration.
172 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore( 179 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore(
173 const std::string& id, 180 const std::string& id,
174 const MediaConstraintsInterface* constraints, 181 const MediaConstraintsInterface* constraints,
182 const webrtc::PeerConnectionInterface::RTCConfiguration* config,
175 const PeerConnectionFactory::Options* options, 183 const PeerConnectionFactory::Options* options,
176 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, 184 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
177 bool prefer_constraint_apis, 185 bool prefer_constraint_apis,
178 rtc::Thread* network_thread, 186 rtc::Thread* network_thread,
179 rtc::Thread* worker_thread) { 187 rtc::Thread* worker_thread) {
180 PeerConnectionTestClient* client(new PeerConnectionTestClient(id)); 188 PeerConnectionTestClient* client(new PeerConnectionTestClient(id));
181 if (!client->Init(constraints, options, std::move(cert_generator), 189 if (!client->Init(constraints, config, options, std::move(cert_generator),
182 prefer_constraint_apis, network_thread, worker_thread)) { 190 prefer_constraint_apis, network_thread, worker_thread)) {
183 delete client; 191 delete client;
184 return nullptr; 192 return nullptr;
185 } 193 }
186 return client; 194 return client;
187 } 195 }
188 196
189 static PeerConnectionTestClient* CreateClient( 197 static PeerConnectionTestClient* CreateClient(
190 const std::string& id, 198 const std::string& id,
191 const MediaConstraintsInterface* constraints, 199 const MediaConstraintsInterface* constraints,
200 const webrtc::PeerConnectionInterface::RTCConfiguration* config,
192 const PeerConnectionFactory::Options* options, 201 const PeerConnectionFactory::Options* options,
193 rtc::Thread* network_thread, 202 rtc::Thread* network_thread,
194 rtc::Thread* worker_thread) { 203 rtc::Thread* worker_thread) {
195 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( 204 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
196 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? 205 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
197 new FakeRTCCertificateGenerator() : nullptr); 206 new FakeRTCCertificateGenerator() : nullptr);
198 207
199 return CreateClientWithDtlsIdentityStore( 208 return CreateClientWithDtlsIdentityStore(id, constraints, config, options,
200 id, constraints, options, std::move(cert_generator), true, 209 std::move(cert_generator), true,
201 network_thread, worker_thread); 210 network_thread, worker_thread);
202 } 211 }
203 212
204 static PeerConnectionTestClient* CreateClientPreferNoConstraints( 213 static PeerConnectionTestClient* CreateClientPreferNoConstraints(
205 const std::string& id, 214 const std::string& id,
206 const PeerConnectionFactory::Options* options, 215 const PeerConnectionFactory::Options* options,
207 rtc::Thread* network_thread, 216 rtc::Thread* network_thread,
208 rtc::Thread* worker_thread) { 217 rtc::Thread* worker_thread) {
209 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( 218 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
210 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? 219 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
211 new FakeRTCCertificateGenerator() : nullptr); 220 new FakeRTCCertificateGenerator() : nullptr);
212 221
213 return CreateClientWithDtlsIdentityStore( 222 return CreateClientWithDtlsIdentityStore(id, nullptr, nullptr, options,
214 id, nullptr, options, std::move(cert_generator), false, 223 std::move(cert_generator), false,
215 network_thread, worker_thread); 224 network_thread, worker_thread);
216 } 225 }
217 226
218 ~PeerConnectionTestClient() { 227 ~PeerConnectionTestClient() {
219 } 228 }
220 229
221 void Negotiate() { Negotiate(true, true); } 230 void Negotiate() { Negotiate(true, true); }
222 231
223 void Negotiate(bool audio, bool video) { 232 void Negotiate(bool audio, bool video) {
224 std::unique_ptr<SessionDescriptionInterface> offer; 233 std::unique_ptr<SessionDescriptionInterface> offer;
225 ASSERT_TRUE(DoCreateOffer(&offer)); 234 ASSERT_TRUE(DoCreateOffer(&offer));
226 235
227 if (offer->description()->GetContentByName("audio")) { 236 if (offer->description()->GetContentByName("audio")) {
228 offer->description()->GetContentByName("audio")->rejected = !audio; 237 offer->description()->GetContentByName("audio")->rejected = !audio;
229 } 238 }
230 if (offer->description()->GetContentByName("video")) { 239 if (offer->description()->GetContentByName("video")) {
231 offer->description()->GetContentByName("video")->rejected = !video; 240 offer->description()->GetContentByName("video")->rejected = !video;
232 } 241 }
233 242
234 std::string sdp; 243 std::string sdp;
235 EXPECT_TRUE(offer->ToString(&sdp)); 244 EXPECT_TRUE(offer->ToString(&sdp));
236 EXPECT_TRUE(DoSetLocalDescription(offer.release())); 245 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
237 signaling_message_receiver_->ReceiveSdpMessage( 246 SendSdpMessage(webrtc::SessionDescriptionInterface::kOffer, sdp);
238 webrtc::SessionDescriptionInterface::kOffer, sdp); 247 }
248
249 typedef std::pair<std::string, std::string> SdpMessage;
250 void SendSdpMessage(const std::string& type, std::string& msg) {
251 if (signaling_delay_ms_ == 0) {
252 if (signaling_message_receiver_) {
253 signaling_message_receiver_->ReceiveSdpMessage(type, msg);
254 }
255 } else {
256 rtc::Thread::Current()->PostDelayed(
257 RTC_FROM_HERE, signaling_delay_ms_, this, MSG_SDP_MESSAGE,
258 new rtc::TypedMessageData<SdpMessage>(SdpMessage(type, msg)));
259 }
260 }
261
262 typedef std::tuple<std::string, int, std::string> IceMessage;
263 void SendIceMessage(const std::string& sdp_mid,
264 int sdp_mline_index,
265 const std::string& msg) {
266 if (signaling_delay_ms_ == 0) {
267 if (signaling_message_receiver_) {
268 signaling_message_receiver_->ReceiveIceMessage(sdp_mid, sdp_mline_index,
269 msg);
270 }
271 } else {
272 rtc::Thread::Current()->PostDelayed(
273 RTC_FROM_HERE, signaling_delay_ms_, this, MSG_ICE_MESSAGE,
274 new rtc::TypedMessageData<IceMessage>(
275 IceMessage(sdp_mid, sdp_mline_index, msg)));
276 }
277 }
278
279 // MessageHandler callback.
280 void OnMessage(rtc::Message* msg) override {
281 switch (msg->message_id) {
282 case MSG_SDP_MESSAGE: {
283 auto sdp_message =
284 static_cast<rtc::TypedMessageData<SdpMessage>*>(msg->pdata);
285 if (signaling_message_receiver_) {
286 signaling_message_receiver_->ReceiveSdpMessage(
287 std::get<0>(sdp_message->data()),
288 std::get<1>(sdp_message->data()));
289 }
290 delete sdp_message;
291 break;
292 }
293 case MSG_ICE_MESSAGE: {
294 auto ice_message =
295 static_cast<rtc::TypedMessageData<IceMessage>*>(msg->pdata);
296 if (signaling_message_receiver_) {
297 signaling_message_receiver_->ReceiveIceMessage(
298 std::get<0>(ice_message->data()),
299 std::get<1>(ice_message->data()),
300 std::get<2>(ice_message->data()));
301 }
302 delete ice_message;
303 break;
304 }
305 default:
306 RTC_CHECK(false);
307 }
239 } 308 }
240 309
241 // SignalingMessageReceiver callback. 310 // SignalingMessageReceiver callback.
242 void ReceiveSdpMessage(const std::string& type, std::string& msg) override { 311 void ReceiveSdpMessage(const std::string& type, std::string& msg) override {
243 FilterIncomingSdpMessage(&msg); 312 FilterIncomingSdpMessage(&msg);
244 if (type == webrtc::SessionDescriptionInterface::kOffer) { 313 if (type == webrtc::SessionDescriptionInterface::kOffer) {
245 HandleIncomingOffer(msg); 314 HandleIncomingOffer(msg);
246 } else { 315 } else {
247 HandleIncomingAnswer(msg); 316 HandleIncomingAnswer(msg);
248 } 317 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 356 }
288 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { 357 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
289 LOG(INFO) << id_ << "OnIceCandidate"; 358 LOG(INFO) << id_ << "OnIceCandidate";
290 359
291 std::string ice_sdp; 360 std::string ice_sdp;
292 EXPECT_TRUE(candidate->ToString(&ice_sdp)); 361 EXPECT_TRUE(candidate->ToString(&ice_sdp));
293 if (signaling_message_receiver_ == nullptr) { 362 if (signaling_message_receiver_ == nullptr) {
294 // Remote party may be deleted. 363 // Remote party may be deleted.
295 return; 364 return;
296 } 365 }
297 signaling_message_receiver_->ReceiveIceMessage( 366 SendIceMessage(candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp);
298 candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp);
299 } 367 }
300 368
301 // MediaStreamInterface callback 369 // MediaStreamInterface callback
302 void OnChanged() override { 370 void OnChanged() override {
303 // Track added or removed from MediaStream, so update our renderers. 371 // Track added or removed from MediaStream, so update our renderers.
304 rtc::scoped_refptr<StreamCollectionInterface> remote_streams = 372 rtc::scoped_refptr<StreamCollectionInterface> remote_streams =
305 pc()->remote_streams(); 373 pc()->remote_streams();
306 // Remove renderers for tracks that were removed. 374 // Remove renderers for tracks that were removed.
307 for (auto it = fake_video_renderers_.begin(); 375 for (auto it = fake_video_renderers_.begin();
308 it != fake_video_renderers_.end();) { 376 it != fake_video_renderers_.end();) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 // Defaults to true. 431 // Defaults to true.
364 void set_auto_add_stream(bool auto_add_stream) { 432 void set_auto_add_stream(bool auto_add_stream) {
365 auto_add_stream_ = auto_add_stream; 433 auto_add_stream_ = auto_add_stream;
366 } 434 }
367 435
368 void set_signaling_message_receiver( 436 void set_signaling_message_receiver(
369 SignalingMessageReceiver* signaling_message_receiver) { 437 SignalingMessageReceiver* signaling_message_receiver) {
370 signaling_message_receiver_ = signaling_message_receiver; 438 signaling_message_receiver_ = signaling_message_receiver;
371 } 439 }
372 440
441 void set_signaling_delay_ms(int delay_ms) { signaling_delay_ms_ = delay_ms; }
442
373 void EnableVideoDecoderFactory() { 443 void EnableVideoDecoderFactory() {
374 video_decoder_factory_enabled_ = true; 444 video_decoder_factory_enabled_ = true;
375 fake_video_decoder_factory_->AddSupportedVideoCodecType( 445 fake_video_decoder_factory_->AddSupportedVideoCodecType(
376 webrtc::kVideoCodecVP8); 446 webrtc::kVideoCodecVP8);
377 } 447 }
378 448
379 void IceRestart() { 449 void IceRestart() {
380 offer_answer_constraints_.SetMandatoryIceRestart(true); 450 offer_answer_constraints_.SetMandatoryIceRestart(true);
381 offer_answer_options_.ice_restart = true; 451 offer_answer_options_.ice_restart = true;
382 SetExpectIceRestart(true); 452 SetExpectIceRestart(true);
383 } 453 }
384 454
385 void SetExpectIceRestart(bool expect_restart) { 455 void SetExpectIceRestart(bool expect_restart) {
386 expect_ice_restart_ = expect_restart; 456 expect_ice_restart_ = expect_restart;
387 } 457 }
388 458
389 bool ExpectIceRestart() const { return expect_ice_restart_; } 459 bool ExpectIceRestart() const { return expect_ice_restart_; }
390 460
461 // Below 3 methods assume streams will be offered.
462 // Thus they'll only set the "offer to receive" flag to true if it's
463 // currently false, not if it's just unset.
391 void SetReceiveAudioVideo(bool audio, bool video) { 464 void SetReceiveAudioVideo(bool audio, bool video) {
392 SetReceiveAudio(audio); 465 SetReceiveAudio(audio);
393 SetReceiveVideo(video); 466 SetReceiveVideo(video);
394 ASSERT_EQ(audio, can_receive_audio()); 467 ASSERT_EQ(audio, can_receive_audio());
395 ASSERT_EQ(video, can_receive_video()); 468 ASSERT_EQ(video, can_receive_video());
396 } 469 }
397 470
398 void SetReceiveAudio(bool audio) { 471 void SetReceiveAudio(bool audio) {
399 if (audio && can_receive_audio()) 472 if (audio && can_receive_audio()) {
400 return; 473 return;
474 }
401 offer_answer_constraints_.SetMandatoryReceiveAudio(audio); 475 offer_answer_constraints_.SetMandatoryReceiveAudio(audio);
402 offer_answer_options_.offer_to_receive_audio = audio ? 1 : 0; 476 offer_answer_options_.offer_to_receive_audio = audio ? 1 : 0;
403 } 477 }
404 478
405 void SetReceiveVideo(bool video) { 479 void SetReceiveVideo(bool video) {
406 if (video && can_receive_video()) 480 if (video && can_receive_video()) {
407 return; 481 return;
482 }
408 offer_answer_constraints_.SetMandatoryReceiveVideo(video); 483 offer_answer_constraints_.SetMandatoryReceiveVideo(video);
409 offer_answer_options_.offer_to_receive_video = video ? 1 : 0; 484 offer_answer_options_.offer_to_receive_video = video ? 1 : 0;
410 } 485 }
486
487 void SetOfferToReceiveAudioVideo(bool audio, bool video) {
488 offer_answer_constraints_.SetMandatoryReceiveAudio(audio);
489 offer_answer_options_.offer_to_receive_audio = audio ? 1 : 0;
490 offer_answer_constraints_.SetMandatoryReceiveVideo(video);
491 offer_answer_options_.offer_to_receive_video = video ? 1 : 0;
492 }
411 493
412 void RemoveMsidFromReceivedSdp(bool remove) { remove_msid_ = remove; } 494 void RemoveMsidFromReceivedSdp(bool remove) { remove_msid_ = remove; }
413 495
414 void RemoveSdesCryptoFromReceivedSdp(bool remove) { remove_sdes_ = remove; } 496 void RemoveSdesCryptoFromReceivedSdp(bool remove) { remove_sdes_ = remove; }
415 497
416 void RemoveBundleFromReceivedSdp(bool remove) { remove_bundle_ = remove; } 498 void RemoveBundleFromReceivedSdp(bool remove) { remove_bundle_ = remove; }
417 499
418 void RemoveCvoFromReceivedSdp(bool remove) { remove_cvo_ = remove; } 500 void RemoveCvoFromReceivedSdp(bool remove) { remove_cvo_ = remove; }
419 501
420 bool can_receive_audio() { 502 bool can_receive_audio() {
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 918
837 private: 919 private:
838 bool completed_; 920 bool completed_;
839 std::vector<std::string> tones_; 921 std::vector<std::string> tones_;
840 }; 922 };
841 923
842 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} 924 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {}
843 925
844 bool Init( 926 bool Init(
845 const MediaConstraintsInterface* constraints, 927 const MediaConstraintsInterface* constraints,
928 const webrtc::PeerConnectionInterface::RTCConfiguration* config,
846 const PeerConnectionFactory::Options* options, 929 const PeerConnectionFactory::Options* options,
847 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, 930 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
848 bool prefer_constraint_apis, 931 bool prefer_constraint_apis,
849 rtc::Thread* network_thread, 932 rtc::Thread* network_thread,
850 rtc::Thread* worker_thread) { 933 rtc::Thread* worker_thread) {
851 EXPECT_TRUE(!peer_connection_); 934 EXPECT_TRUE(!peer_connection_);
852 EXPECT_TRUE(!peer_connection_factory_); 935 EXPECT_TRUE(!peer_connection_factory_);
853 if (!prefer_constraint_apis) { 936 if (!prefer_constraint_apis) {
854 EXPECT_TRUE(!constraints); 937 EXPECT_TRUE(!constraints);
855 } 938 }
856 prefer_constraint_apis_ = prefer_constraint_apis; 939 prefer_constraint_apis_ = prefer_constraint_apis;
857 940
941 fake_network_manager_.reset(new rtc::FakeNetworkManager());
942 fake_network_manager_->AddInterface(rtc::SocketAddress("192.168.1.1", 0));
943
858 std::unique_ptr<cricket::PortAllocator> port_allocator( 944 std::unique_ptr<cricket::PortAllocator> port_allocator(
859 new cricket::FakePortAllocator(network_thread, nullptr)); 945 new cricket::BasicPortAllocator(fake_network_manager_.get()));
Taylor Brandstetter 2016/07/12 19:33:34 Switched to using a BasicPortAllocator so we can t
860 fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); 946 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
861 947
862 if (fake_audio_capture_module_ == nullptr) { 948 if (fake_audio_capture_module_ == nullptr) {
863 return false; 949 return false;
864 } 950 }
865 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory(); 951 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory();
866 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory(); 952 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory();
867 rtc::Thread* const signaling_thread = rtc::Thread::Current(); 953 rtc::Thread* const signaling_thread = rtc::Thread::Current();
868 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( 954 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
869 network_thread, worker_thread, signaling_thread, 955 network_thread, worker_thread, signaling_thread,
870 fake_audio_capture_module_, fake_video_encoder_factory_, 956 fake_audio_capture_module_, fake_video_encoder_factory_,
871 fake_video_decoder_factory_); 957 fake_video_decoder_factory_);
872 if (!peer_connection_factory_) { 958 if (!peer_connection_factory_) {
873 return false; 959 return false;
874 } 960 }
875 if (options) { 961 if (options) {
876 peer_connection_factory_->SetOptions(*options); 962 peer_connection_factory_->SetOptions(*options);
877 } 963 }
878 peer_connection_ = CreatePeerConnection( 964 peer_connection_ =
879 std::move(port_allocator), constraints, std::move(cert_generator)); 965 CreatePeerConnection(std::move(port_allocator), constraints, config,
966 std::move(cert_generator));
880 return peer_connection_.get() != nullptr; 967 return peer_connection_.get() != nullptr;
881 } 968 }
882 969
883 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( 970 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(
884 std::unique_ptr<cricket::PortAllocator> port_allocator, 971 std::unique_ptr<cricket::PortAllocator> port_allocator,
885 const MediaConstraintsInterface* constraints, 972 const MediaConstraintsInterface* constraints,
973 const webrtc::PeerConnectionInterface::RTCConfiguration* config,
886 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) { 974 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
887 // CreatePeerConnection with RTCConfiguration. 975 // CreatePeerConnection with RTCConfiguration.
888 webrtc::PeerConnectionInterface::RTCConfiguration config; 976 webrtc::PeerConnectionInterface::RTCConfiguration default_config;
889 webrtc::PeerConnectionInterface::IceServer ice_server; 977
890 ice_server.uri = "stun:stun.l.google.com:19302"; 978 if (!config) {
Taylor Brandstetter 2016/07/12 19:33:34 This STUN server wasn't doing anything since the F
891 config.servers.push_back(ice_server); 979 config = &default_config;
980 }
892 981
893 return peer_connection_factory_->CreatePeerConnection( 982 return peer_connection_factory_->CreatePeerConnection(
894 config, constraints, std::move(port_allocator), 983 *config, constraints, std::move(port_allocator),
895 std::move(cert_generator), this); 984 std::move(cert_generator), this);
896 } 985 }
897 986
898 void HandleIncomingOffer(const std::string& msg) { 987 void HandleIncomingOffer(const std::string& msg) {
899 LOG(INFO) << id_ << "HandleIncomingOffer "; 988 LOG(INFO) << id_ << "HandleIncomingOffer ";
900 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) { 989 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) {
901 // If we are not sending any streams ourselves it is time to add some. 990 // If we are not sending any streams ourselves it is time to add some.
902 AddMediaStream(true, true); 991 AddMediaStream(true, true);
903 } 992 }
904 std::unique_ptr<SessionDescriptionInterface> desc( 993 std::unique_ptr<SessionDescriptionInterface> desc(
905 webrtc::CreateSessionDescription("offer", msg, nullptr)); 994 webrtc::CreateSessionDescription("offer", msg, nullptr));
906 EXPECT_TRUE(DoSetRemoteDescription(desc.release())); 995 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
907 // Set the RtpReceiverObserver after receivers are created. 996 // Set the RtpReceiverObserver after receivers are created.
908 SetRtpReceiverObservers(); 997 SetRtpReceiverObservers();
909 std::unique_ptr<SessionDescriptionInterface> answer; 998 std::unique_ptr<SessionDescriptionInterface> answer;
910 EXPECT_TRUE(DoCreateAnswer(&answer)); 999 EXPECT_TRUE(DoCreateAnswer(&answer));
911 std::string sdp; 1000 std::string sdp;
912 EXPECT_TRUE(answer->ToString(&sdp)); 1001 EXPECT_TRUE(answer->ToString(&sdp));
913 EXPECT_TRUE(DoSetLocalDescription(answer.release())); 1002 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
914 if (signaling_message_receiver_) { 1003 SendSdpMessage(webrtc::SessionDescriptionInterface::kAnswer, sdp);
915 signaling_message_receiver_->ReceiveSdpMessage(
916 webrtc::SessionDescriptionInterface::kAnswer, sdp);
917 }
918 } 1004 }
919 1005
920 void HandleIncomingAnswer(const std::string& msg) { 1006 void HandleIncomingAnswer(const std::string& msg) {
921 LOG(INFO) << id_ << "HandleIncomingAnswer"; 1007 LOG(INFO) << id_ << "HandleIncomingAnswer";
922 std::unique_ptr<SessionDescriptionInterface> desc( 1008 std::unique_ptr<SessionDescriptionInterface> desc(
923 webrtc::CreateSessionDescription("answer", msg, nullptr)); 1009 webrtc::CreateSessionDescription("answer", msg, nullptr));
924 EXPECT_TRUE(DoSetRemoteDescription(desc.release())); 1010 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
925 // Set the RtpReceiverObserver after receivers are created. 1011 // Set the RtpReceiverObserver after receivers are created.
926 SetRtpReceiverObservers(); 1012 SetRtpReceiverObservers();
927 } 1013 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp); 1094 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp);
1009 } 1095 }
1010 if (remove_cvo_) { 1096 if (remove_cvo_) {
1011 const char kSdpCvoExtenstion[] = "urn:3gpp:video-orientation"; 1097 const char kSdpCvoExtenstion[] = "urn:3gpp:video-orientation";
1012 RemoveLinesFromSdp(kSdpCvoExtenstion, sdp); 1098 RemoveLinesFromSdp(kSdpCvoExtenstion, sdp);
1013 } 1099 }
1014 } 1100 }
1015 1101
1016 std::string id_; 1102 std::string id_;
1017 1103
1104 std::unique_ptr<rtc::FakeNetworkManager> fake_network_manager_;
1105
1018 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; 1106 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
1019 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> 1107 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
1020 peer_connection_factory_; 1108 peer_connection_factory_;
1021 1109
1022 bool prefer_constraint_apis_ = true; 1110 bool prefer_constraint_apis_ = true;
1023 bool auto_add_stream_ = true; 1111 bool auto_add_stream_ = true;
1024 1112
1025 typedef std::pair<std::string, std::string> IceUfragPwdPair; 1113 typedef std::pair<std::string, std::string> IceUfragPwdPair;
1026 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_; 1114 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_;
1027 bool expect_ice_restart_ = false; 1115 bool expect_ice_restart_ = false;
1028 1116
1029 // Needed to keep track of number of frames sent. 1117 // Needed to keep track of number of frames sent.
1030 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; 1118 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
1031 // Needed to keep track of number of frames received. 1119 // Needed to keep track of number of frames received.
1032 std::map<std::string, std::unique_ptr<webrtc::FakeVideoTrackRenderer>> 1120 std::map<std::string, std::unique_ptr<webrtc::FakeVideoTrackRenderer>>
1033 fake_video_renderers_; 1121 fake_video_renderers_;
1034 // Needed to ensure frames aren't received for removed tracks. 1122 // Needed to ensure frames aren't received for removed tracks.
1035 std::vector<std::unique_ptr<webrtc::FakeVideoTrackRenderer>> 1123 std::vector<std::unique_ptr<webrtc::FakeVideoTrackRenderer>>
1036 removed_fake_video_renderers_; 1124 removed_fake_video_renderers_;
1037 // Needed to keep track of number of frames received when external decoder 1125 // Needed to keep track of number of frames received when external decoder
1038 // used. 1126 // used.
1039 FakeWebRtcVideoDecoderFactory* fake_video_decoder_factory_ = nullptr; 1127 FakeWebRtcVideoDecoderFactory* fake_video_decoder_factory_ = nullptr;
1040 FakeWebRtcVideoEncoderFactory* fake_video_encoder_factory_ = nullptr; 1128 FakeWebRtcVideoEncoderFactory* fake_video_encoder_factory_ = nullptr;
1041 bool video_decoder_factory_enabled_ = false; 1129 bool video_decoder_factory_enabled_ = false;
1042 webrtc::FakeConstraints video_constraints_; 1130 webrtc::FakeConstraints video_constraints_;
1043 1131
1044 // For remote peer communication. 1132 // For remote peer communication.
1045 SignalingMessageReceiver* signaling_message_receiver_ = nullptr; 1133 SignalingMessageReceiver* signaling_message_receiver_ = nullptr;
1134 int signaling_delay_ms_ = 0;
1046 1135
1047 // Store references to the video capturers we've created, so that we can stop 1136 // Store references to the video capturers we've created, so that we can stop
1048 // them, if required. 1137 // them, if required.
1049 std::vector<cricket::FakeVideoCapturer*> video_capturers_; 1138 std::vector<cricket::FakeVideoCapturer*> video_capturers_;
1050 webrtc::VideoRotation capture_rotation_ = webrtc::kVideoRotation_0; 1139 webrtc::VideoRotation capture_rotation_ = webrtc::kVideoRotation_0;
1051 // |local_video_renderer_| attached to the first created local video track. 1140 // |local_video_renderer_| attached to the first created local video track.
1052 std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_; 1141 std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_;
1053 1142
1054 webrtc::FakeConstraints offer_answer_constraints_; 1143 webrtc::FakeConstraints offer_answer_constraints_;
1055 PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_; 1144 PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 } 1261 }
1173 if (receiving_client_) { 1262 if (receiving_client_) {
1174 receiving_client_->set_signaling_message_receiver(nullptr); 1263 receiving_client_->set_signaling_message_receiver(nullptr);
1175 } 1264 }
1176 } 1265 }
1177 1266
1178 bool CreateTestClients() { return CreateTestClients(nullptr, nullptr); } 1267 bool CreateTestClients() { return CreateTestClients(nullptr, nullptr); }
1179 1268
1180 bool CreateTestClients(MediaConstraintsInterface* init_constraints, 1269 bool CreateTestClients(MediaConstraintsInterface* init_constraints,
1181 MediaConstraintsInterface* recv_constraints) { 1270 MediaConstraintsInterface* recv_constraints) {
1182 return CreateTestClients(init_constraints, nullptr, recv_constraints, 1271 return CreateTestClients(init_constraints, nullptr, nullptr,
1183 nullptr); 1272 recv_constraints, nullptr, nullptr);
1184 } 1273 }
1185 1274
1186 bool CreateTestClientsThatPreferNoConstraints() { 1275 bool CreateTestClientsThatPreferNoConstraints() {
1187 initiating_client_.reset( 1276 initiating_client_.reset(
1188 PeerConnectionTestClient::CreateClientPreferNoConstraints( 1277 PeerConnectionTestClient::CreateClientPreferNoConstraints(
1189 "Caller: ", nullptr, network_thread_.get(), worker_thread_.get())); 1278 "Caller: ", nullptr, network_thread_.get(), worker_thread_.get()));
1190 receiving_client_.reset( 1279 receiving_client_.reset(
1191 PeerConnectionTestClient::CreateClientPreferNoConstraints( 1280 PeerConnectionTestClient::CreateClientPreferNoConstraints(
1192 "Callee: ", nullptr, network_thread_.get(), worker_thread_.get())); 1281 "Callee: ", nullptr, network_thread_.get(), worker_thread_.get()));
1193 if (!initiating_client_ || !receiving_client_) { 1282 if (!initiating_client_ || !receiving_client_) {
1194 return false; 1283 return false;
1195 } 1284 }
1196 // Remember the choice for possible later resets of the clients. 1285 // Remember the choice for possible later resets of the clients.
1197 prefer_constraint_apis_ = false; 1286 prefer_constraint_apis_ = false;
1198 SetSignalingReceivers(); 1287 SetSignalingReceivers();
1199 return true; 1288 return true;
1200 } 1289 }
1201 1290
1202 void SetSignalingReceivers() { 1291 void SetSignalingReceivers() {
1203 initiating_client_->set_signaling_message_receiver(receiving_client_.get()); 1292 initiating_client_->set_signaling_message_receiver(receiving_client_.get());
1204 receiving_client_->set_signaling_message_receiver(initiating_client_.get()); 1293 receiving_client_->set_signaling_message_receiver(initiating_client_.get());
1205 } 1294 }
1206 1295
1207 bool CreateTestClients(MediaConstraintsInterface* init_constraints, 1296 void SetSignalingDelayMs(int delay_ms) {
1208 PeerConnectionFactory::Options* init_options, 1297 initiating_client_->set_signaling_delay_ms(delay_ms);
1209 MediaConstraintsInterface* recv_constraints, 1298 receiving_client_->set_signaling_delay_ms(delay_ms);
1210 PeerConnectionFactory::Options* recv_options) { 1299 }
1300
1301 bool CreateTestClients(
1302 MediaConstraintsInterface* init_constraints,
1303 const webrtc::PeerConnectionInterface::RTCConfiguration* init_config,
1304 PeerConnectionFactory::Options* init_options,
1305 MediaConstraintsInterface* recv_constraints,
1306 const webrtc::PeerConnectionInterface::RTCConfiguration* recv_config,
1307 PeerConnectionFactory::Options* recv_options) {
1211 initiating_client_.reset(PeerConnectionTestClient::CreateClient( 1308 initiating_client_.reset(PeerConnectionTestClient::CreateClient(
1212 "Caller: ", init_constraints, init_options, network_thread_.get(), 1309 "Caller: ", init_constraints, init_config, init_options,
1213 worker_thread_.get())); 1310 network_thread_.get(), worker_thread_.get()));
1214 receiving_client_.reset(PeerConnectionTestClient::CreateClient( 1311 receiving_client_.reset(PeerConnectionTestClient::CreateClient(
1215 "Callee: ", recv_constraints, recv_options, network_thread_.get(), 1312 "Callee: ", recv_constraints, recv_config, recv_options,
1216 worker_thread_.get())); 1313 network_thread_.get(), worker_thread_.get()));
1217 if (!initiating_client_ || !receiving_client_) { 1314 if (!initiating_client_ || !receiving_client_) {
1218 return false; 1315 return false;
1219 } 1316 }
1220 SetSignalingReceivers(); 1317 SetSignalingReceivers();
1221 return true; 1318 return true;
1222 } 1319 }
1223 1320
1224 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints, 1321 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints,
1225 const webrtc::FakeConstraints& recv_constraints) { 1322 const webrtc::FakeConstraints& recv_constraints) {
1226 initiating_client_->SetVideoConstraints(init_constraints); 1323 initiating_client_->SetVideoConstraints(init_constraints);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, 1403 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1307 true); 1404 true);
1308 1405
1309 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( 1406 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
1310 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? 1407 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
1311 new FakeRTCCertificateGenerator() : nullptr); 1408 new FakeRTCCertificateGenerator() : nullptr);
1312 cert_generator->use_alternate_key(); 1409 cert_generator->use_alternate_key();
1313 1410
1314 // Make sure the new client is using a different certificate. 1411 // Make sure the new client is using a different certificate.
1315 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore( 1412 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore(
1316 "New Peer: ", &setup_constraints, nullptr, 1413 "New Peer: ", &setup_constraints, nullptr, nullptr,
1317 std::move(cert_generator), prefer_constraint_apis_, 1414 std::move(cert_generator), prefer_constraint_apis_,
1318 network_thread_.get(), worker_thread_.get()); 1415 network_thread_.get(), worker_thread_.get());
1319 } 1416 }
1320 1417
1321 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { 1418 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) {
1322 // Messages may get lost on the unreliable DataChannel, so we send multiple 1419 // Messages may get lost on the unreliable DataChannel, so we send multiple
1323 // times to avoid test flakiness. 1420 // times to avoid test flakiness.
1324 static const size_t kSendAttempts = 5; 1421 static const size_t kSendAttempts = 5;
1325 1422
1326 for (size_t i = 0; i < kSendAttempts; ++i) { 1423 for (size_t i = 0; i < kSendAttempts; ++i) {
1327 dc->Send(DataBuffer(data)); 1424 dc->Send(DataBuffer(data));
1328 } 1425 }
1329 } 1426 }
1330 1427
1428 rtc::Thread* network_thread() { return network_thread_.get(); }
1429
1430 rtc::VirtualSocketServer* virtual_socket_server() { return ss_.get(); }
1431
1331 PeerConnectionTestClient* initializing_client() { 1432 PeerConnectionTestClient* initializing_client() {
1332 return initiating_client_.get(); 1433 return initiating_client_.get();
1333 } 1434 }
1334 1435
1335 // Set the |initiating_client_| to the |client| passed in and return the 1436 // Set the |initiating_client_| to the |client| passed in and return the
1336 // original |initiating_client_|. 1437 // original |initiating_client_|.
1337 PeerConnectionTestClient* set_initializing_client( 1438 PeerConnectionTestClient* set_initializing_client(
1338 PeerConnectionTestClient* client) { 1439 PeerConnectionTestClient* client) {
1339 PeerConnectionTestClient* old = initiating_client_.release(); 1440 PeerConnectionTestClient* old = initiating_client_.release();
1340 initiating_client_.reset(client); 1441 initiating_client_.reset(client);
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
1711 initializing_client()->GetBytesSentStats(local_video_track) > 0, 1812 initializing_client()->GetBytesSentStats(local_video_track) > 0,
1712 kMaxWaitForStatsMs); 1813 kMaxWaitForStatsMs);
1713 } 1814 }
1714 1815
1715 // Test that DTLS 1.0 is used if both sides only support DTLS 1.0. 1816 // Test that DTLS 1.0 is used if both sides only support DTLS 1.0.
1716 TEST_F(P2PTestConductor, GetDtls12None) { 1817 TEST_F(P2PTestConductor, GetDtls12None) {
1717 PeerConnectionFactory::Options init_options; 1818 PeerConnectionFactory::Options init_options;
1718 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; 1819 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1719 PeerConnectionFactory::Options recv_options; 1820 PeerConnectionFactory::Options recv_options;
1720 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; 1821 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1721 ASSERT_TRUE( 1822 ASSERT_TRUE(CreateTestClients(nullptr, nullptr, &init_options, nullptr,
1722 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); 1823 nullptr, &recv_options));
1723 rtc::scoped_refptr<webrtc::FakeMetricsObserver> 1824 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1724 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); 1825 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1725 initializing_client()->pc()->RegisterUMAObserver(init_observer); 1826 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1726 LocalP2PTest(); 1827 LocalP2PTest();
1727 1828
1728 EXPECT_TRUE_WAIT( 1829 EXPECT_TRUE_WAIT(
1729 rtc::SSLStreamAdapter::IsAcceptableCipher( 1830 rtc::SSLStreamAdapter::IsAcceptableCipher(
1730 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), 1831 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1731 kMaxWaitForStatsMs); 1832 kMaxWaitForStatsMs);
1732 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), 1833 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
1733 initializing_client()->GetSrtpCipherStats(), 1834 initializing_client()->GetSrtpCipherStats(),
1734 kMaxWaitForStatsMs); 1835 kMaxWaitForStatsMs);
1735 EXPECT_EQ(1, 1836 EXPECT_EQ(1,
1736 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, 1837 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1737 kDefaultSrtpCryptoSuite)); 1838 kDefaultSrtpCryptoSuite));
1738 } 1839 }
1739 1840
1740 // Test that DTLS 1.2 is used if both ends support it. 1841 // Test that DTLS 1.2 is used if both ends support it.
1741 TEST_F(P2PTestConductor, GetDtls12Both) { 1842 TEST_F(P2PTestConductor, GetDtls12Both) {
1742 PeerConnectionFactory::Options init_options; 1843 PeerConnectionFactory::Options init_options;
1743 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; 1844 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1744 PeerConnectionFactory::Options recv_options; 1845 PeerConnectionFactory::Options recv_options;
1745 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; 1846 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1746 ASSERT_TRUE( 1847 ASSERT_TRUE(CreateTestClients(nullptr, nullptr, &init_options, nullptr,
1747 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); 1848 nullptr, &recv_options));
1748 rtc::scoped_refptr<webrtc::FakeMetricsObserver> 1849 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1749 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); 1850 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1750 initializing_client()->pc()->RegisterUMAObserver(init_observer); 1851 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1751 LocalP2PTest(); 1852 LocalP2PTest();
1752 1853
1753 EXPECT_TRUE_WAIT( 1854 EXPECT_TRUE_WAIT(
1754 rtc::SSLStreamAdapter::IsAcceptableCipher( 1855 rtc::SSLStreamAdapter::IsAcceptableCipher(
1755 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), 1856 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1756 kMaxWaitForStatsMs); 1857 kMaxWaitForStatsMs);
1757 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), 1858 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
1758 initializing_client()->GetSrtpCipherStats(), 1859 initializing_client()->GetSrtpCipherStats(),
1759 kMaxWaitForStatsMs); 1860 kMaxWaitForStatsMs);
1760 EXPECT_EQ(1, 1861 EXPECT_EQ(1,
1761 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, 1862 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1762 kDefaultSrtpCryptoSuite)); 1863 kDefaultSrtpCryptoSuite));
1763 } 1864 }
1764 1865
1765 // Test that DTLS 1.0 is used if the initator supports DTLS 1.2 and the 1866 // Test that DTLS 1.0 is used if the initator supports DTLS 1.2 and the
1766 // received supports 1.0. 1867 // received supports 1.0.
1767 TEST_F(P2PTestConductor, GetDtls12Init) { 1868 TEST_F(P2PTestConductor, GetDtls12Init) {
1768 PeerConnectionFactory::Options init_options; 1869 PeerConnectionFactory::Options init_options;
1769 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; 1870 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1770 PeerConnectionFactory::Options recv_options; 1871 PeerConnectionFactory::Options recv_options;
1771 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; 1872 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1772 ASSERT_TRUE( 1873 ASSERT_TRUE(CreateTestClients(nullptr, nullptr, &init_options, nullptr,
1773 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); 1874 nullptr, &recv_options));
1774 rtc::scoped_refptr<webrtc::FakeMetricsObserver> 1875 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1775 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); 1876 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1776 initializing_client()->pc()->RegisterUMAObserver(init_observer); 1877 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1777 LocalP2PTest(); 1878 LocalP2PTest();
1778 1879
1779 EXPECT_TRUE_WAIT( 1880 EXPECT_TRUE_WAIT(
1780 rtc::SSLStreamAdapter::IsAcceptableCipher( 1881 rtc::SSLStreamAdapter::IsAcceptableCipher(
1781 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), 1882 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1782 kMaxWaitForStatsMs); 1883 kMaxWaitForStatsMs);
1783 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), 1884 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
1784 initializing_client()->GetSrtpCipherStats(), 1885 initializing_client()->GetSrtpCipherStats(),
1785 kMaxWaitForStatsMs); 1886 kMaxWaitForStatsMs);
1786 EXPECT_EQ(1, 1887 EXPECT_EQ(1,
1787 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, 1888 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1788 kDefaultSrtpCryptoSuite)); 1889 kDefaultSrtpCryptoSuite));
1789 } 1890 }
1790 1891
1791 // Test that DTLS 1.0 is used if the initator supports DTLS 1.0 and the 1892 // Test that DTLS 1.0 is used if the initator supports DTLS 1.0 and the
1792 // received supports 1.2. 1893 // received supports 1.2.
1793 TEST_F(P2PTestConductor, GetDtls12Recv) { 1894 TEST_F(P2PTestConductor, GetDtls12Recv) {
1794 PeerConnectionFactory::Options init_options; 1895 PeerConnectionFactory::Options init_options;
1795 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; 1896 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1796 PeerConnectionFactory::Options recv_options; 1897 PeerConnectionFactory::Options recv_options;
1797 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; 1898 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1798 ASSERT_TRUE( 1899 ASSERT_TRUE(CreateTestClients(nullptr, nullptr, &init_options, nullptr,
1799 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); 1900 nullptr, &recv_options));
1800 rtc::scoped_refptr<webrtc::FakeMetricsObserver> 1901 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1801 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); 1902 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1802 initializing_client()->pc()->RegisterUMAObserver(init_observer); 1903 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1803 LocalP2PTest(); 1904 LocalP2PTest();
1804 1905
1805 EXPECT_TRUE_WAIT( 1906 EXPECT_TRUE_WAIT(
1806 rtc::SSLStreamAdapter::IsAcceptableCipher( 1907 rtc::SSLStreamAdapter::IsAcceptableCipher(
1807 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), 1908 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1808 kMaxWaitForStatsMs); 1909 kMaxWaitForStatsMs);
1809 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), 1910 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 // Echo the stream back. 2200 // Echo the stream back.
2100 receiving_client()->pc()->AddStream( 2201 receiving_client()->pc()->AddStream(
2101 receiving_client()->remote_streams()->at(0)); 2202 receiving_client()->remote_streams()->at(0));
2102 receiving_client()->Negotiate(); 2203 receiving_client()->Negotiate();
2103 2204
2104 EXPECT_TRUE_WAIT( 2205 EXPECT_TRUE_WAIT(
2105 initializing_client()->VideoFramesReceivedCheck(kEndVideoFrameCount), 2206 initializing_client()->VideoFramesReceivedCheck(kEndVideoFrameCount),
2106 kMaxWaitForFramesMs); 2207 kMaxWaitForFramesMs);
2107 } 2208 }
2108 2209
2210 // Test that we achieve the expected end-to-end connection time, using a
2211 // fake clock and simulated latency on the media and signaling paths.
2212 // We use a TURN<->TURN connection because this is usually the quickest to
2213 // set up initially, especially when we're confident the connection will work
2214 // and can start sending media before we get a STUN response.
2215 //
2216 // With various optimizations enabled, here are the trips we expect to be
2217 // required:
2218 // 1. 2 signaling trip: Signaling offer and offerer's TURN candidate, then
2219 // signaling answer (with DTLS fingerprint).
2220 // 2. 9 media trips: Rest of the DTLS handshake. 3 hops in each direction when
2221 // using TURN<->TURN pair, and DTLS exchange is 4 packets,
2222 // the first of which should have arrived before the answer.
2223 TEST_F(P2PTestConductor, EndToEndConnectionTimeWithTurnTurnPair) {
2224 rtc::ScopedFakeClock fake_clock;
2225 // Some things use a time of "0" as a special value, so we need to start out
2226 // the fake clock at a nonzero time.
2227 // TODO(deadbeef): Fix this.
2228 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
2229
2230 static constexpr int media_trip_delay_ms = 50;
2231 static constexpr int signaling_trip_delay_ms = 500;
2232 // For explanation of these values, see comment above.
2233 static constexpr int required_media_trips = 9;
2234 static constexpr int required_signaling_trips = 2;
2235 // For internal delays (such as posting an event asychronously).
2236 static constexpr int allowed_internal_delay_ms = 20;
2237 static constexpr int total_connection_time_ms =
2238 media_trip_delay_ms * required_media_trips +
2239 signaling_trip_delay_ms * required_signaling_trips +
2240 allowed_internal_delay_ms;
2241
2242 static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0",
2243 3478};
2244 static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1",
2245 0};
2246 static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0",
2247 3478};
2248 static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1",
2249 0};
2250 cricket::TestTurnServer turn_server_1(network_thread(),
2251 turn_server_1_internal_address,
2252 turn_server_1_external_address);
2253 cricket::TestTurnServer turn_server_2(network_thread(),
2254 turn_server_2_internal_address,
2255 turn_server_2_external_address);
2256 // Bypass permission check on received packets so media can be sent before
2257 // the candidate is signaled.
2258 turn_server_1.set_enable_permission_checks(false);
2259 turn_server_2.set_enable_permission_checks(false);
2260
2261 webrtc::PeerConnectionInterface::RTCConfiguration client_1_config;
2262 webrtc::PeerConnectionInterface::IceServer ice_server_1;
2263 ice_server_1.urls.push_back("turn:88.88.88.0:3478");
2264 ice_server_1.username = "test";
2265 ice_server_1.password = "test";
2266 client_1_config.servers.push_back(ice_server_1);
2267 client_1_config.type = webrtc::PeerConnectionInterface::kRelay;
2268 client_1_config.presume_writable_when_fully_relayed = true;
2269
2270 webrtc::PeerConnectionInterface::RTCConfiguration client_2_config;
2271 webrtc::PeerConnectionInterface::IceServer ice_server_2;
2272 ice_server_2.urls.push_back("turn:99.99.99.0:3478");
2273 ice_server_2.username = "test";
2274 ice_server_2.password = "test";
2275 client_2_config.servers.push_back(ice_server_2);
2276 client_2_config.type = webrtc::PeerConnectionInterface::kRelay;
2277 client_2_config.presume_writable_when_fully_relayed = true;
2278
2279 ASSERT_TRUE(CreateTestClients(nullptr, &client_1_config, nullptr, nullptr,
2280 &client_2_config, nullptr));
2281 // Set up the simulated delays.
2282 SetSignalingDelayMs(signaling_trip_delay_ms);
2283 virtual_socket_server()->set_delay_mean(media_trip_delay_ms);
2284 virtual_socket_server()->UpdateDelayDistribution();
2285
2286 initializing_client()->SetOfferToReceiveAudioVideo(true, true);
2287 initializing_client()->Negotiate();
2288 // TODO(deadbeef): kIceConnectionConnected currently means both ICE and DTLS
2289 // are connected. This is an important distinction. Once we have separate ICE
2290 // and DTLS state, this check needs to use the DTLS state.
2291 EXPECT_TRUE_SIMULATED_WAIT(
2292 (receiving_client()->ice_connection_state() ==
2293 webrtc::PeerConnectionInterface::kIceConnectionConnected ||
2294 receiving_client()->ice_connection_state() ==
2295 webrtc::PeerConnectionInterface::kIceConnectionCompleted) &&
2296 (initializing_client()->ice_connection_state() ==
2297 webrtc::PeerConnectionInterface::kIceConnectionConnected ||
2298 initializing_client()->ice_connection_state() ==
2299 webrtc::PeerConnectionInterface::kIceConnectionCompleted),
2300 total_connection_time_ms, fake_clock);
2301 // Need to free the clients here since they're using things we created on
2302 // the stack.
2303 delete set_initializing_client(nullptr);
2304 delete set_receiving_client(nullptr);
2305 }
2306
2109 class IceServerParsingTest : public testing::Test { 2307 class IceServerParsingTest : public testing::Test {
2110 public: 2308 public:
2111 // Convenience for parsing a single URL. 2309 // Convenience for parsing a single URL.
2112 bool ParseUrl(const std::string& url) { 2310 bool ParseUrl(const std::string& url) {
2113 return ParseUrl(url, std::string(), std::string()); 2311 return ParseUrl(url, std::string(), std::string());
2114 } 2312 }
2115 2313
2116 bool ParseUrl(const std::string& url, 2314 bool ParseUrl(const std::string& url,
2117 const std::string& username, 2315 const std::string& username,
2118 const std::string& password) { 2316 const std::string& password) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2291 server.urls.push_back("turn:hostname2"); 2489 server.urls.push_back("turn:hostname2");
2292 servers.push_back(server); 2490 servers.push_back(server);
2293 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); 2491 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
2294 EXPECT_EQ(2U, turn_servers_.size()); 2492 EXPECT_EQ(2U, turn_servers_.size());
2295 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); 2493 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority);
2296 } 2494 }
2297 2495
2298 #endif // if !defined(THREAD_SANITIZER) 2496 #endif // if !defined(THREAD_SANITIZER)
2299 2497
2300 } // namespace 2498 } // namespace
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/fakenetwork.h » ('j') | webrtc/base/fakenetwork.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698