blob: 981cec778a690108de0b21850e4c3328a035cabe [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
11#include <stdio.h>
12
13#include <algorithm>
14#include <list>
15#include <map>
kwibergd1fe2812016-04-27 06:47:29 -070016#include <memory>
kwiberg0eb15ed2015-12-17 03:04:15 -080017#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <vector>
19
Henrik Kjellander15583c12016-02-10 10:53:12 +010020#include "webrtc/api/dtmfsender.h"
21#include "webrtc/api/fakemetricsobserver.h"
22#include "webrtc/api/localaudiosource.h"
23#include "webrtc/api/mediastreaminterface.h"
24#include "webrtc/api/peerconnection.h"
25#include "webrtc/api/peerconnectionfactory.h"
26#include "webrtc/api/peerconnectioninterface.h"
27#include "webrtc/api/test/fakeaudiocapturemodule.h"
28#include "webrtc/api/test/fakeconstraints.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010029#include "webrtc/api/test/fakeperiodicvideocapturer.h"
Henrik Boströmd79599d2016-06-01 13:58:50 +020030#include "webrtc/api/test/fakertccertificategenerator.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010031#include "webrtc/api/test/fakevideotrackrenderer.h"
32#include "webrtc/api/test/mockpeerconnectionobservers.h"
Taylor Brandstettere5835f52016-09-16 15:07:50 -070033#include "webrtc/base/fakenetwork.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000034#include "webrtc/base/gunit.h"
Taylor Brandstetter9b5306c2016-08-18 11:40:37 -070035#include "webrtc/base/helpers.h"
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +000036#include "webrtc/base/physicalsocketserver.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000037#include "webrtc/base/ssladapter.h"
38#include "webrtc/base/sslstreamadapter.h"
39#include "webrtc/base/thread.h"
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +000040#include "webrtc/base/virtualsocketserver.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010041#include "webrtc/media/engine/fakewebrtcvideoengine.h"
kjellanderf4752772016-03-02 05:42:30 -080042#include "webrtc/p2p/base/p2pconstants.h"
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +000043#include "webrtc/p2p/base/sessiondescription.h"
Taylor Brandstettere5835f52016-09-16 15:07:50 -070044#include "webrtc/p2p/base/testturnserver.h"
45#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010046#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
48#define MAYBE_SKIP_TEST(feature) \
49 if (!(feature())) { \
50 LOG(LS_INFO) << "Feature disabled... skipping"; \
51 return; \
52 }
53
54using cricket::ContentInfo;
55using cricket::FakeWebRtcVideoDecoder;
56using cricket::FakeWebRtcVideoDecoderFactory;
57using cricket::FakeWebRtcVideoEncoder;
58using cricket::FakeWebRtcVideoEncoderFactory;
59using cricket::MediaContentDescription;
60using webrtc::DataBuffer;
61using webrtc::DataChannelInterface;
62using webrtc::DtmfSender;
63using webrtc::DtmfSenderInterface;
64using webrtc::DtmfSenderObserverInterface;
65using webrtc::FakeConstraints;
66using webrtc::MediaConstraintsInterface;
deadbeeffaac4972015-11-12 15:33:07 -080067using webrtc::MediaStreamInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068using webrtc::MediaStreamTrackInterface;
69using webrtc::MockCreateSessionDescriptionObserver;
70using webrtc::MockDataChannelObserver;
71using webrtc::MockSetSessionDescriptionObserver;
72using webrtc::MockStatsObserver;
deadbeeffaac4972015-11-12 15:33:07 -080073using webrtc::ObserverInterface;
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +000074using webrtc::PeerConnectionInterface;
Joachim Bauch04e5b492015-05-29 09:40:39 +020075using webrtc::PeerConnectionFactory;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076using webrtc::SessionDescriptionInterface;
77using webrtc::StreamCollectionInterface;
78
hta6b4f8392016-03-10 00:24:31 -080079namespace {
80
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000081static const int kMaxWaitMs = 10000;
pbos@webrtc.org044bdac2014-06-03 09:40:01 +000082// Disable for TSan v2, see
83// https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
84// This declaration is also #ifdef'd as it causes uninitialized-variable
85// warnings.
86#if !defined(THREAD_SANITIZER)
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087static const int kMaxWaitForStatsMs = 3000;
pbos@webrtc.org044bdac2014-06-03 09:40:01 +000088#endif
deadbeeffac06552015-11-25 11:26:01 -080089static const int kMaxWaitForActivationMs = 5000;
buildbot@webrtc.org3e01e0b2014-05-13 17:54:10 +000090static const int kMaxWaitForFramesMs = 10000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091static const int kEndAudioFrameCount = 3;
92static const int kEndVideoFrameCount = 3;
93
94static const char kStreamLabelBase[] = "stream_label";
95static const char kVideoTrackLabelBase[] = "video_track";
96static const char kAudioTrackLabelBase[] = "audio_track";
97static const char kDataChannelLabel[] = "data_channel";
98
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +000099// Disable for TSan v2, see
100// https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
101// This declaration is also #ifdef'd as it causes unused-variable errors.
102#if !defined(THREAD_SANITIZER)
103// SRTP cipher name negotiated by the tests. This must be updated if the
104// default changes.
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800105static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32;
jbauchcb560652016-08-04 05:20:32 -0700106static const int kDefaultSrtpCryptoSuiteGcm = rtc::SRTP_AEAD_AES_256_GCM;
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000107#endif
108
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700109// Used to simulate signaling ICE/SDP between two PeerConnections.
110enum Message { MSG_SDP_MESSAGE, MSG_ICE_MESSAGE };
111
112struct SdpMessage {
113 std::string type;
114 std::string msg;
115};
116
117struct IceMessage {
118 std::string sdp_mid;
119 int sdp_mline_index;
120 std::string msg;
121};
122
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123static void RemoveLinesFromSdp(const std::string& line_start,
124 std::string* sdp) {
125 const char kSdpLineEnd[] = "\r\n";
126 size_t ssrc_pos = 0;
127 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) !=
128 std::string::npos) {
129 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos);
130 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd));
131 }
132}
133
hta6b4f8392016-03-10 00:24:31 -0800134bool StreamsHaveAudioTrack(StreamCollectionInterface* streams) {
135 for (size_t idx = 0; idx < streams->count(); idx++) {
136 auto stream = streams->at(idx);
137 if (stream->GetAudioTracks().size() > 0) {
138 return true;
139 }
140 }
141 return false;
142}
143
144bool StreamsHaveVideoTrack(StreamCollectionInterface* streams) {
145 for (size_t idx = 0; idx < streams->count(); idx++) {
146 auto stream = streams->at(idx);
147 if (stream->GetVideoTracks().size() > 0) {
148 return true;
149 }
150 }
151 return false;
152}
153
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154class SignalingMessageReceiver {
155 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156 virtual void ReceiveSdpMessage(const std::string& type,
157 std::string& msg) = 0;
158 virtual void ReceiveIceMessage(const std::string& sdp_mid,
159 int sdp_mline_index,
160 const std::string& msg) = 0;
161
162 protected:
deadbeefaf1b59c2015-10-15 12:08:41 -0700163 SignalingMessageReceiver() {}
164 virtual ~SignalingMessageReceiver() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165};
166
zhihuang184a3fd2016-06-14 11:47:14 -0700167class MockRtpReceiverObserver : public webrtc::RtpReceiverObserverInterface {
168 public:
169 MockRtpReceiverObserver(cricket::MediaType media_type)
170 : expected_media_type_(media_type) {}
171
172 void OnFirstPacketReceived(cricket::MediaType media_type) override {
173 ASSERT_EQ(expected_media_type_, media_type);
174 first_packet_received_ = true;
175 }
176
177 bool first_packet_received() { return first_packet_received_; }
178
179 virtual ~MockRtpReceiverObserver() {}
180
181 private:
182 bool first_packet_received_ = false;
183 cricket::MediaType expected_media_type_;
184};
185
deadbeefaf1b59c2015-10-15 12:08:41 -0700186class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
deadbeeffaac4972015-11-12 15:33:07 -0800187 public SignalingMessageReceiver,
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700188 public ObserverInterface,
189 public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 public:
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700191 // If |config| is not provided, uses a default constructed RTCConfiguration.
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800192 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore(
Guo-wei Shieh9c38c2d2015-12-05 09:46:07 -0800193 const std::string& id,
194 const MediaConstraintsInterface* constraints,
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800195 const PeerConnectionFactory::Options* options,
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700196 const PeerConnectionInterface::RTCConfiguration* config,
Henrik Boströmd79599d2016-06-01 13:58:50 +0200197 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
perkj8aba9972016-04-10 23:54:34 -0700198 bool prefer_constraint_apis,
danilchape9021a32016-05-17 01:52:02 -0700199 rtc::Thread* network_thread,
perkj8aba9972016-04-10 23:54:34 -0700200 rtc::Thread* worker_thread) {
Guo-wei Shieh86aaa4b2015-12-05 09:55:44 -0800201 PeerConnectionTestClient* client(new PeerConnectionTestClient(id));
zhihuang9763d562016-08-05 11:14:50 -0700202 if (!client->Init(constraints, options, config, std::move(cert_generator),
danilchape9021a32016-05-17 01:52:02 -0700203 prefer_constraint_apis, network_thread, worker_thread)) {
Guo-wei Shieh86aaa4b2015-12-05 09:55:44 -0800204 delete client;
205 return nullptr;
206 }
207 return client;
Guo-wei Shieh9c38c2d2015-12-05 09:46:07 -0800208 }
209
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800210 static PeerConnectionTestClient* CreateClient(
211 const std::string& id,
212 const MediaConstraintsInterface* constraints,
perkj8aba9972016-04-10 23:54:34 -0700213 const PeerConnectionFactory::Options* options,
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700214 const PeerConnectionInterface::RTCConfiguration* config,
danilchape9021a32016-05-17 01:52:02 -0700215 rtc::Thread* network_thread,
perkj8aba9972016-04-10 23:54:34 -0700216 rtc::Thread* worker_thread) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200217 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
218 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
219 new FakeRTCCertificateGenerator() : nullptr);
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800220
zhihuang9763d562016-08-05 11:14:50 -0700221 return CreateClientWithDtlsIdentityStore(id, constraints, options, config,
222 std::move(cert_generator), true,
223 network_thread, worker_thread);
htaaac2dea2016-03-10 13:35:55 -0800224 }
225
226 static PeerConnectionTestClient* CreateClientPreferNoConstraints(
227 const std::string& id,
perkj8aba9972016-04-10 23:54:34 -0700228 const PeerConnectionFactory::Options* options,
danilchape9021a32016-05-17 01:52:02 -0700229 rtc::Thread* network_thread,
perkj8aba9972016-04-10 23:54:34 -0700230 rtc::Thread* worker_thread) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200231 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
232 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
233 new FakeRTCCertificateGenerator() : nullptr);
htaaac2dea2016-03-10 13:35:55 -0800234
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700235 return CreateClientWithDtlsIdentityStore(id, nullptr, options, nullptr,
zhihuang9763d562016-08-05 11:14:50 -0700236 std::move(cert_generator), false,
237 network_thread, worker_thread);
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800238 }
239
deadbeefaf1b59c2015-10-15 12:08:41 -0700240 ~PeerConnectionTestClient() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 }
242
deadbeefaf1b59c2015-10-15 12:08:41 -0700243 void Negotiate() { Negotiate(true, true); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244
deadbeefaf1b59c2015-10-15 12:08:41 -0700245 void Negotiate(bool audio, bool video) {
kwibergd1fe2812016-04-27 06:47:29 -0700246 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700247 ASSERT_TRUE(DoCreateOffer(&offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248
deadbeefaf1b59c2015-10-15 12:08:41 -0700249 if (offer->description()->GetContentByName("audio")) {
250 offer->description()->GetContentByName("audio")->rejected = !audio;
251 }
252 if (offer->description()->GetContentByName("video")) {
253 offer->description()->GetContentByName("video")->rejected = !video;
254 }
255
256 std::string sdp;
257 EXPECT_TRUE(offer->ToString(&sdp));
258 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700259 SendSdpMessage(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 }
deadbeefaf1b59c2015-10-15 12:08:41 -0700317 }
318
319 // SignalingMessageReceiver callback.
320 void ReceiveSdpMessage(const std::string& type, std::string& msg) override {
321 FilterIncomingSdpMessage(&msg);
322 if (type == webrtc::SessionDescriptionInterface::kOffer) {
323 HandleIncomingOffer(msg);
324 } else {
325 HandleIncomingAnswer(msg);
326 }
327 }
328
329 // SignalingMessageReceiver callback.
330 void ReceiveIceMessage(const std::string& sdp_mid,
331 int sdp_mline_index,
332 const std::string& msg) override {
333 LOG(INFO) << id_ << "ReceiveIceMessage";
kwibergd1fe2812016-04-27 06:47:29 -0700334 std::unique_ptr<webrtc::IceCandidateInterface> candidate(
deadbeefaf1b59c2015-10-15 12:08:41 -0700335 webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, msg, nullptr));
336 EXPECT_TRUE(pc()->AddIceCandidate(candidate.get()));
337 }
338
339 // PeerConnectionObserver callbacks.
340 void OnSignalingChange(
341 webrtc::PeerConnectionInterface::SignalingState new_state) override {
342 EXPECT_EQ(pc()->signaling_state(), new_state);
343 }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700344 void OnAddStream(
345 rtc::scoped_refptr<MediaStreamInterface> media_stream) override {
deadbeeffaac4972015-11-12 15:33:07 -0800346 media_stream->RegisterObserver(this);
deadbeefaf1b59c2015-10-15 12:08:41 -0700347 for (size_t i = 0; i < media_stream->GetVideoTracks().size(); ++i) {
348 const std::string id = media_stream->GetVideoTracks()[i]->id();
349 ASSERT_TRUE(fake_video_renderers_.find(id) ==
350 fake_video_renderers_.end());
deadbeefc9be0072015-12-14 18:27:57 -0800351 fake_video_renderers_[id].reset(new webrtc::FakeVideoTrackRenderer(
352 media_stream->GetVideoTracks()[i]));
deadbeefaf1b59c2015-10-15 12:08:41 -0700353 }
354 }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700355 void OnRemoveStream(
356 rtc::scoped_refptr<MediaStreamInterface> media_stream) override {}
deadbeefaf1b59c2015-10-15 12:08:41 -0700357 void OnRenegotiationNeeded() override {}
358 void OnIceConnectionChange(
359 webrtc::PeerConnectionInterface::IceConnectionState new_state) override {
360 EXPECT_EQ(pc()->ice_connection_state(), new_state);
361 }
362 void OnIceGatheringChange(
363 webrtc::PeerConnectionInterface::IceGatheringState new_state) override {
364 EXPECT_EQ(pc()->ice_gathering_state(), new_state);
365 }
366 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
367 LOG(INFO) << id_ << "OnIceCandidate";
368
369 std::string ice_sdp;
370 EXPECT_TRUE(candidate->ToString(&ice_sdp));
371 if (signaling_message_receiver_ == nullptr) {
372 // Remote party may be deleted.
373 return;
374 }
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700375 SendIceMessage(candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp);
deadbeefaf1b59c2015-10-15 12:08:41 -0700376 }
377
deadbeeffaac4972015-11-12 15:33:07 -0800378 // MediaStreamInterface callback
379 void OnChanged() override {
380 // Track added or removed from MediaStream, so update our renderers.
381 rtc::scoped_refptr<StreamCollectionInterface> remote_streams =
382 pc()->remote_streams();
383 // Remove renderers for tracks that were removed.
384 for (auto it = fake_video_renderers_.begin();
385 it != fake_video_renderers_.end();) {
386 if (remote_streams->FindVideoTrack(it->first) == nullptr) {
deadbeefc9be0072015-12-14 18:27:57 -0800387 auto to_remove = it++;
388 removed_fake_video_renderers_.push_back(std::move(to_remove->second));
389 fake_video_renderers_.erase(to_remove);
deadbeeffaac4972015-11-12 15:33:07 -0800390 } else {
391 ++it;
392 }
393 }
394 // Create renderers for new video tracks.
395 for (size_t stream_index = 0; stream_index < remote_streams->count();
396 ++stream_index) {
397 MediaStreamInterface* remote_stream = remote_streams->at(stream_index);
398 for (size_t track_index = 0;
399 track_index < remote_stream->GetVideoTracks().size();
400 ++track_index) {
401 const std::string id =
402 remote_stream->GetVideoTracks()[track_index]->id();
403 if (fake_video_renderers_.find(id) != fake_video_renderers_.end()) {
404 continue;
405 }
deadbeefc9be0072015-12-14 18:27:57 -0800406 fake_video_renderers_[id].reset(new webrtc::FakeVideoTrackRenderer(
407 remote_stream->GetVideoTracks()[track_index]));
deadbeeffaac4972015-11-12 15:33:07 -0800408 }
409 }
410 }
411
deadbeefaf1b59c2015-10-15 12:08:41 -0700412 void SetVideoConstraints(const webrtc::FakeConstraints& video_constraint) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000413 video_constraints_ = video_constraint;
414 }
415
416 void AddMediaStream(bool audio, bool video) {
deadbeefaf1b59c2015-10-15 12:08:41 -0700417 std::string stream_label =
418 kStreamLabelBase +
419 rtc::ToString<int>(static_cast<int>(pc()->local_streams()->count()));
deadbeeffaac4972015-11-12 15:33:07 -0800420 rtc::scoped_refptr<MediaStreamInterface> stream =
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000421 peer_connection_factory_->CreateLocalMediaStream(stream_label);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422
423 if (audio && can_receive_audio()) {
deadbeeffac06552015-11-25 11:26:01 -0800424 stream->AddTrack(CreateLocalAudioTrack(stream_label));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425 }
426 if (video && can_receive_video()) {
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000427 stream->AddTrack(CreateLocalVideoTrack(stream_label));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428 }
429
deadbeefaf1b59c2015-10-15 12:08:41 -0700430 EXPECT_TRUE(pc()->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431 }
432
deadbeefaf1b59c2015-10-15 12:08:41 -0700433 size_t NumberOfLocalMediaStreams() { return pc()->local_streams()->count(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434
435 bool SessionActive() {
deadbeefaf1b59c2015-10-15 12:08:41 -0700436 return pc()->signaling_state() == webrtc::PeerConnectionInterface::kStable;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437 }
438
deadbeeffaac4972015-11-12 15:33:07 -0800439 // Automatically add a stream when receiving an offer, if we don't have one.
440 // Defaults to true.
441 void set_auto_add_stream(bool auto_add_stream) {
442 auto_add_stream_ = auto_add_stream;
443 }
444
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445 void set_signaling_message_receiver(
deadbeefaf1b59c2015-10-15 12:08:41 -0700446 SignalingMessageReceiver* signaling_message_receiver) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447 signaling_message_receiver_ = signaling_message_receiver;
448 }
449
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700450 void set_signaling_delay_ms(int delay_ms) { signaling_delay_ms_ = delay_ms; }
451
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452 void EnableVideoDecoderFactory() {
453 video_decoder_factory_enabled_ = true;
454 fake_video_decoder_factory_->AddSupportedVideoCodecType(
455 webrtc::kVideoCodecVP8);
456 }
457
deadbeefaf1b59c2015-10-15 12:08:41 -0700458 void IceRestart() {
htaaac2dea2016-03-10 13:35:55 -0800459 offer_answer_constraints_.SetMandatoryIceRestart(true);
460 offer_answer_options_.ice_restart = true;
deadbeefaf1b59c2015-10-15 12:08:41 -0700461 SetExpectIceRestart(true);
462 }
463
464 void SetExpectIceRestart(bool expect_restart) {
465 expect_ice_restart_ = expect_restart;
466 }
467
468 bool ExpectIceRestart() const { return expect_ice_restart_; }
469
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700470 void SetExpectIceRenomination(bool expect_renomination) {
471 expect_ice_renomination_ = expect_renomination;
472 }
473 void SetExpectRemoteIceRenomination(bool expect_renomination) {
474 expect_remote_ice_renomination_ = expect_renomination;
475 }
476 bool ExpectIceRenomination() { return expect_ice_renomination_; }
477 bool ExpectRemoteIceRenomination() { return expect_remote_ice_renomination_; }
478
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700479 // 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.
deadbeefaf1b59c2015-10-15 12:08:41 -0700482 void SetReceiveAudioVideo(bool audio, bool video) {
483 SetReceiveAudio(audio);
484 SetReceiveVideo(video);
485 ASSERT_EQ(audio, can_receive_audio());
486 ASSERT_EQ(video, can_receive_video());
487 }
488
489 void SetReceiveAudio(bool audio) {
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700490 if (audio && can_receive_audio()) {
deadbeefaf1b59c2015-10-15 12:08:41 -0700491 return;
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700492 }
htaaac2dea2016-03-10 13:35:55 -0800493 offer_answer_constraints_.SetMandatoryReceiveAudio(audio);
494 offer_answer_options_.offer_to_receive_audio = audio ? 1 : 0;
deadbeefaf1b59c2015-10-15 12:08:41 -0700495 }
496
497 void SetReceiveVideo(bool video) {
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700498 if (video && can_receive_video()) {
deadbeefaf1b59c2015-10-15 12:08:41 -0700499 return;
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700500 }
501 offer_answer_constraints_.SetMandatoryReceiveVideo(video);
502 offer_answer_options_.offer_to_receive_video = video ? 1 : 0;
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;
htaaac2dea2016-03-10 13:35:55 -0800508 offer_answer_constraints_.SetMandatoryReceiveVideo(video);
509 offer_answer_options_.offer_to_receive_video = video ? 1 : 0;
deadbeefaf1b59c2015-10-15 12:08:41 -0700510 }
511
512 void RemoveMsidFromReceivedSdp(bool remove) { remove_msid_ = remove; }
513
514 void RemoveSdesCryptoFromReceivedSdp(bool remove) { remove_sdes_ = remove; }
515
516 void RemoveBundleFromReceivedSdp(bool remove) { remove_bundle_ = remove; }
517
perkjcaafdba2016-03-20 07:34:29 -0700518 void RemoveCvoFromReceivedSdp(bool remove) { remove_cvo_ = remove; }
519
deadbeefaf1b59c2015-10-15 12:08:41 -0700520 bool can_receive_audio() {
521 bool value;
htaaac2dea2016-03-10 13:35:55 -0800522 if (prefer_constraint_apis_) {
523 if (webrtc::FindConstraint(
524 &offer_answer_constraints_,
525 MediaConstraintsInterface::kOfferToReceiveAudio, &value,
526 nullptr)) {
527 return value;
528 }
529 return true;
deadbeefaf1b59c2015-10-15 12:08:41 -0700530 }
htaaac2dea2016-03-10 13:35:55 -0800531 return offer_answer_options_.offer_to_receive_audio > 0 ||
532 offer_answer_options_.offer_to_receive_audio ==
533 PeerConnectionInterface::RTCOfferAnswerOptions::kUndefined;
deadbeefaf1b59c2015-10-15 12:08:41 -0700534 }
535
536 bool can_receive_video() {
537 bool value;
htaaac2dea2016-03-10 13:35:55 -0800538 if (prefer_constraint_apis_) {
539 if (webrtc::FindConstraint(
540 &offer_answer_constraints_,
541 MediaConstraintsInterface::kOfferToReceiveVideo, &value,
542 nullptr)) {
543 return value;
544 }
545 return true;
deadbeefaf1b59c2015-10-15 12:08:41 -0700546 }
htaaac2dea2016-03-10 13:35:55 -0800547 return offer_answer_options_.offer_to_receive_video > 0 ||
548 offer_answer_options_.offer_to_receive_video ==
549 PeerConnectionInterface::RTCOfferAnswerOptions::kUndefined;
deadbeefaf1b59c2015-10-15 12:08:41 -0700550 }
551
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700552 void OnDataChannel(
553 rtc::scoped_refptr<DataChannelInterface> data_channel) override {
deadbeefaf1b59c2015-10-15 12:08:41 -0700554 LOG(INFO) << id_ << "OnDataChannel";
555 data_channel_ = data_channel;
556 data_observer_.reset(new MockDataChannelObserver(data_channel));
557 }
558
zhihuang9763d562016-08-05 11:14:50 -0700559 void CreateDataChannel() { CreateDataChannel(nullptr); }
560
561 void CreateDataChannel(const webrtc::DataChannelInit* init) {
562 data_channel_ = pc()->CreateDataChannel(kDataChannelLabel, init);
deadbeefaf1b59c2015-10-15 12:08:41 -0700563 ASSERT_TRUE(data_channel_.get() != nullptr);
564 data_observer_.reset(new MockDataChannelObserver(data_channel_));
565 }
566
deadbeeffac06552015-11-25 11:26:01 -0800567 rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack(
568 const std::string& stream_label) {
569 FakeConstraints constraints;
570 // Disable highpass filter so that we can get all the test audio frames.
571 constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false);
572 rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
573 peer_connection_factory_->CreateAudioSource(&constraints);
574 // TODO(perkj): Test audio source when it is implemented. Currently audio
575 // always use the default input.
576 std::string label = stream_label + kAudioTrackLabelBase;
577 return peer_connection_factory_->CreateAudioTrack(label, source);
578 }
579
580 rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack(
581 const std::string& stream_label) {
582 // Set max frame rate to 10fps to reduce the risk of the tests to be flaky.
583 FakeConstraints source_constraints = video_constraints_;
584 source_constraints.SetMandatoryMaxFrameRate(10);
585
586 cricket::FakeVideoCapturer* fake_capturer =
587 new webrtc::FakePeriodicVideoCapturer();
perkjcaafdba2016-03-20 07:34:29 -0700588 fake_capturer->SetRotation(capture_rotation_);
deadbeeffac06552015-11-25 11:26:01 -0800589 video_capturers_.push_back(fake_capturer);
perkja3ede6c2016-03-08 01:27:48 +0100590 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
deadbeeffac06552015-11-25 11:26:01 -0800591 peer_connection_factory_->CreateVideoSource(fake_capturer,
592 &source_constraints);
593 std::string label = stream_label + kVideoTrackLabelBase;
perkjcaafdba2016-03-20 07:34:29 -0700594
595 rtc::scoped_refptr<webrtc::VideoTrackInterface> track(
596 peer_connection_factory_->CreateVideoTrack(label, source));
597 if (!local_video_renderer_) {
598 local_video_renderer_.reset(new webrtc::FakeVideoTrackRenderer(track));
599 }
600 return track;
deadbeeffac06552015-11-25 11:26:01 -0800601 }
602
deadbeefaf1b59c2015-10-15 12:08:41 -0700603 DataChannelInterface* data_channel() { return data_channel_; }
604 const MockDataChannelObserver* data_observer() const {
605 return data_observer_.get();
606 }
607
hta6b4f8392016-03-10 00:24:31 -0800608 webrtc::PeerConnectionInterface* pc() const { return peer_connection_.get(); }
deadbeefaf1b59c2015-10-15 12:08:41 -0700609
610 void StopVideoCapturers() {
perkjcaafdba2016-03-20 07:34:29 -0700611 for (auto* capturer : video_capturers_) {
612 capturer->Stop();
deadbeefaf1b59c2015-10-15 12:08:41 -0700613 }
614 }
615
perkjcaafdba2016-03-20 07:34:29 -0700616 void SetCaptureRotation(webrtc::VideoRotation rotation) {
617 ASSERT_TRUE(video_capturers_.empty());
618 capture_rotation_ = rotation;
619 }
620
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000621 bool AudioFramesReceivedCheck(int number_of_frames) const {
622 return number_of_frames <= fake_audio_capture_module_->frames_received();
623 }
624
deadbeefc9be0072015-12-14 18:27:57 -0800625 int audio_frames_received() const {
626 return fake_audio_capture_module_->frames_received();
627 }
628
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000629 bool VideoFramesReceivedCheck(int number_of_frames) {
630 if (video_decoder_factory_enabled_) {
631 const std::vector<FakeWebRtcVideoDecoder*>& decoders
632 = fake_video_decoder_factory_->decoders();
633 if (decoders.empty()) {
634 return number_of_frames <= 0;
635 }
hta6b4f8392016-03-10 00:24:31 -0800636 // Note - this checks that EACH decoder has the requisite number
637 // of frames. The video_frames_received() function sums them.
deadbeefc9be0072015-12-14 18:27:57 -0800638 for (FakeWebRtcVideoDecoder* decoder : decoders) {
639 if (number_of_frames > decoder->GetNumFramesReceived()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000640 return false;
641 }
642 }
643 return true;
644 } else {
645 if (fake_video_renderers_.empty()) {
646 return number_of_frames <= 0;
647 }
648
deadbeefc9be0072015-12-14 18:27:57 -0800649 for (const auto& pair : fake_video_renderers_) {
650 if (number_of_frames > pair.second->num_rendered_frames()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000651 return false;
652 }
653 }
654 return true;
655 }
656 }
deadbeefaf1b59c2015-10-15 12:08:41 -0700657
deadbeefc9be0072015-12-14 18:27:57 -0800658 int video_frames_received() const {
659 int total = 0;
660 if (video_decoder_factory_enabled_) {
661 const std::vector<FakeWebRtcVideoDecoder*>& decoders =
662 fake_video_decoder_factory_->decoders();
663 for (const FakeWebRtcVideoDecoder* decoder : decoders) {
664 total += decoder->GetNumFramesReceived();
665 }
666 } else {
667 for (const auto& pair : fake_video_renderers_) {
668 total += pair.second->num_rendered_frames();
669 }
670 for (const auto& renderer : removed_fake_video_renderers_) {
671 total += renderer->num_rendered_frames();
672 }
673 }
674 return total;
675 }
676
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000677 // Verify the CreateDtmfSender interface
678 void VerifyDtmf() {
kwibergd1fe2812016-04-27 06:47:29 -0700679 std::unique_ptr<DummyDtmfObserver> observer(new DummyDtmfObserver());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000680 rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681
682 // We can't create a DTMF sender with an invalid audio track or a non local
683 // track.
deadbeefaf1b59c2015-10-15 12:08:41 -0700684 EXPECT_TRUE(peer_connection_->CreateDtmfSender(nullptr) == nullptr);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000685 rtc::scoped_refptr<webrtc::AudioTrackInterface> non_localtrack(
deadbeefaf1b59c2015-10-15 12:08:41 -0700686 peer_connection_factory_->CreateAudioTrack("dummy_track", nullptr));
687 EXPECT_TRUE(peer_connection_->CreateDtmfSender(non_localtrack) == nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000688
689 // We should be able to create a DTMF sender from a local track.
690 webrtc::AudioTrackInterface* localtrack =
691 peer_connection_->local_streams()->at(0)->GetAudioTracks()[0];
692 dtmf_sender = peer_connection_->CreateDtmfSender(localtrack);
deadbeefaf1b59c2015-10-15 12:08:41 -0700693 EXPECT_TRUE(dtmf_sender.get() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 dtmf_sender->RegisterObserver(observer.get());
695
696 // Test the DtmfSender object just created.
697 EXPECT_TRUE(dtmf_sender->CanInsertDtmf());
698 EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50));
699
700 // We don't need to verify that the DTMF tones are actually sent out because
701 // that is already covered by the tests of the lower level components.
702
703 EXPECT_TRUE_WAIT(observer->completed(), kMaxWaitMs);
704 std::vector<std::string> tones;
705 tones.push_back("1");
706 tones.push_back("a");
707 tones.push_back("");
708 observer->Verify(tones);
709
710 dtmf_sender->UnregisterObserver();
711 }
712
713 // Verifies that the SessionDescription have rejected the appropriate media
714 // content.
715 void VerifyRejectedMediaInSessionDescription() {
deadbeefaf1b59c2015-10-15 12:08:41 -0700716 ASSERT_TRUE(peer_connection_->remote_description() != nullptr);
717 ASSERT_TRUE(peer_connection_->local_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 const cricket::SessionDescription* remote_desc =
719 peer_connection_->remote_description()->description();
720 const cricket::SessionDescription* local_desc =
721 peer_connection_->local_description()->description();
722
723 const ContentInfo* remote_audio_content = GetFirstAudioContent(remote_desc);
724 if (remote_audio_content) {
725 const ContentInfo* audio_content =
726 GetFirstAudioContent(local_desc);
727 EXPECT_EQ(can_receive_audio(), !audio_content->rejected);
728 }
729
730 const ContentInfo* remote_video_content = GetFirstVideoContent(remote_desc);
731 if (remote_video_content) {
732 const ContentInfo* video_content =
733 GetFirstVideoContent(local_desc);
734 EXPECT_EQ(can_receive_video(), !video_content->rejected);
735 }
736 }
737
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738 void VerifyLocalIceUfragAndPassword() {
deadbeefaf1b59c2015-10-15 12:08:41 -0700739 ASSERT_TRUE(peer_connection_->local_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 const cricket::SessionDescription* desc =
741 peer_connection_->local_description()->description();
742 const cricket::ContentInfos& contents = desc->contents();
743
744 for (size_t index = 0; index < contents.size(); ++index) {
745 if (contents[index].rejected)
746 continue;
747 const cricket::TransportDescription* transport_desc =
748 desc->GetTransportDescriptionByName(contents[index].name);
749
750 std::map<int, IceUfragPwdPair>::const_iterator ufragpair_it =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000751 ice_ufrag_pwd_.find(static_cast<int>(index));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 if (ufragpair_it == ice_ufrag_pwd_.end()) {
753 ASSERT_FALSE(ExpectIceRestart());
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000754 ice_ufrag_pwd_[static_cast<int>(index)] =
755 IceUfragPwdPair(transport_desc->ice_ufrag, transport_desc->ice_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 } else if (ExpectIceRestart()) {
757 const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second;
758 EXPECT_NE(ufrag_pwd.first, transport_desc->ice_ufrag);
759 EXPECT_NE(ufrag_pwd.second, transport_desc->ice_pwd);
760 } else {
761 const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second;
762 EXPECT_EQ(ufrag_pwd.first, transport_desc->ice_ufrag);
763 EXPECT_EQ(ufrag_pwd.second, transport_desc->ice_pwd);
764 }
765 }
766 }
767
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700768 void VerifyLocalIceRenomination() {
769 ASSERT_TRUE(peer_connection_->local_description() != nullptr);
770 const cricket::SessionDescription* desc =
771 peer_connection_->local_description()->description();
772 const cricket::ContentInfos& contents = desc->contents();
773
774 for (auto content : contents) {
775 if (content.rejected)
776 continue;
777 const cricket::TransportDescription* transport_desc =
778 desc->GetTransportDescriptionByName(content.name);
779 const auto& options = transport_desc->transport_options;
780 auto iter = std::find(options.begin(), options.end(),
781 cricket::ICE_RENOMINATION_STR);
782 EXPECT_EQ(ExpectIceRenomination(), iter != options.end());
783 }
784 }
785
786 void VerifyRemoteIceRenomination() {
787 ASSERT_TRUE(peer_connection_->remote_description() != nullptr);
788 const cricket::SessionDescription* desc =
789 peer_connection_->remote_description()->description();
790 const cricket::ContentInfos& contents = desc->contents();
791
792 for (auto content : contents) {
793 if (content.rejected)
794 continue;
795 const cricket::TransportDescription* transport_desc =
796 desc->GetTransportDescriptionByName(content.name);
797 const auto& options = transport_desc->transport_options;
798 auto iter = std::find(options.begin(), options.end(),
799 cricket::ICE_RENOMINATION_STR);
800 EXPECT_EQ(ExpectRemoteIceRenomination(), iter != options.end());
801 }
802 }
803
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 int GetAudioOutputLevelStats(webrtc::MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000805 rtc::scoped_refptr<MockStatsObserver>
806 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000807 EXPECT_TRUE(peer_connection_->GetStats(
808 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700810 EXPECT_NE(0, observer->timestamp());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 return observer->AudioOutputLevel();
812 }
813
814 int GetAudioInputLevelStats() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000815 rtc::scoped_refptr<MockStatsObserver>
816 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000817 EXPECT_TRUE(peer_connection_->GetStats(
deadbeefaf1b59c2015-10-15 12:08:41 -0700818 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700820 EXPECT_NE(0, observer->timestamp());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 return observer->AudioInputLevel();
822 }
823
824 int GetBytesReceivedStats(webrtc::MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000825 rtc::scoped_refptr<MockStatsObserver>
826 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000827 EXPECT_TRUE(peer_connection_->GetStats(
828 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700830 EXPECT_NE(0, observer->timestamp());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 return observer->BytesReceived();
832 }
833
834 int GetBytesSentStats(webrtc::MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000835 rtc::scoped_refptr<MockStatsObserver>
836 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000837 EXPECT_TRUE(peer_connection_->GetStats(
838 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700840 EXPECT_NE(0, observer->timestamp());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841 return observer->BytesSent();
842 }
843
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000844 int GetAvailableReceivedBandwidthStats() {
845 rtc::scoped_refptr<MockStatsObserver>
846 observer(new rtc::RefCountedObject<MockStatsObserver>());
847 EXPECT_TRUE(peer_connection_->GetStats(
deadbeefaf1b59c2015-10-15 12:08:41 -0700848 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard));
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000849 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700850 EXPECT_NE(0, observer->timestamp());
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000851 int bw = observer->AvailableReceiveBandwidth();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000852 return bw;
853 }
854
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000855 std::string GetDtlsCipherStats() {
856 rtc::scoped_refptr<MockStatsObserver>
857 observer(new rtc::RefCountedObject<MockStatsObserver>());
858 EXPECT_TRUE(peer_connection_->GetStats(
deadbeefaf1b59c2015-10-15 12:08:41 -0700859 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard));
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000860 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700861 EXPECT_NE(0, observer->timestamp());
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000862 return observer->DtlsCipher();
863 }
864
865 std::string GetSrtpCipherStats() {
866 rtc::scoped_refptr<MockStatsObserver>
867 observer(new rtc::RefCountedObject<MockStatsObserver>());
868 EXPECT_TRUE(peer_connection_->GetStats(
deadbeefaf1b59c2015-10-15 12:08:41 -0700869 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard));
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000870 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700871 EXPECT_NE(0, observer->timestamp());
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000872 return observer->SrtpCipher();
873 }
874
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 int rendered_width() {
876 EXPECT_FALSE(fake_video_renderers_.empty());
877 return fake_video_renderers_.empty() ? 1 :
878 fake_video_renderers_.begin()->second->width();
879 }
880
881 int rendered_height() {
882 EXPECT_FALSE(fake_video_renderers_.empty());
883 return fake_video_renderers_.empty() ? 1 :
884 fake_video_renderers_.begin()->second->height();
885 }
886
perkjcaafdba2016-03-20 07:34:29 -0700887 webrtc::VideoRotation rendered_rotation() {
888 EXPECT_FALSE(fake_video_renderers_.empty());
889 return fake_video_renderers_.empty()
890 ? webrtc::kVideoRotation_0
891 : fake_video_renderers_.begin()->second->rotation();
892 }
893
894 int local_rendered_width() {
895 return local_video_renderer_ ? local_video_renderer_->width() : 1;
896 }
897
898 int local_rendered_height() {
899 return local_video_renderer_ ? local_video_renderer_->height() : 1;
900 }
901
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 size_t number_of_remote_streams() {
903 if (!pc())
904 return 0;
905 return pc()->remote_streams()->count();
906 }
907
hta6b4f8392016-03-10 00:24:31 -0800908 StreamCollectionInterface* remote_streams() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 if (!pc()) {
910 ADD_FAILURE();
deadbeefaf1b59c2015-10-15 12:08:41 -0700911 return nullptr;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 }
913 return pc()->remote_streams();
914 }
915
916 StreamCollectionInterface* local_streams() {
917 if (!pc()) {
918 ADD_FAILURE();
deadbeefaf1b59c2015-10-15 12:08:41 -0700919 return nullptr;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 }
921 return pc()->local_streams();
922 }
923
hta6b4f8392016-03-10 00:24:31 -0800924 bool HasLocalAudioTrack() { return StreamsHaveAudioTrack(local_streams()); }
925
926 bool HasLocalVideoTrack() { return StreamsHaveVideoTrack(local_streams()); }
927
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 webrtc::PeerConnectionInterface::SignalingState signaling_state() {
929 return pc()->signaling_state();
930 }
931
932 webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() {
933 return pc()->ice_connection_state();
934 }
935
936 webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() {
937 return pc()->ice_gathering_state();
938 }
939
zhihuang184a3fd2016-06-14 11:47:14 -0700940 std::vector<std::unique_ptr<MockRtpReceiverObserver>> const&
941 rtp_receiver_observers() {
942 return rtp_receiver_observers_;
943 }
944
945 void SetRtpReceiverObservers() {
946 rtp_receiver_observers_.clear();
947 for (auto receiver : pc()->GetReceivers()) {
948 std::unique_ptr<MockRtpReceiverObserver> observer(
949 new MockRtpReceiverObserver(receiver->media_type()));
950 receiver->SetObserver(observer.get());
951 rtp_receiver_observers_.push_back(std::move(observer));
952 }
953 }
954
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 private:
956 class DummyDtmfObserver : public DtmfSenderObserverInterface {
957 public:
958 DummyDtmfObserver() : completed_(false) {}
959
960 // Implements DtmfSenderObserverInterface.
deadbeefaf1b59c2015-10-15 12:08:41 -0700961 void OnToneChange(const std::string& tone) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 tones_.push_back(tone);
963 if (tone.empty()) {
964 completed_ = true;
965 }
966 }
967
968 void Verify(const std::vector<std::string>& tones) const {
969 ASSERT_TRUE(tones_.size() == tones.size());
970 EXPECT_TRUE(std::equal(tones.begin(), tones.end(), tones_.begin()));
971 }
972
973 bool completed() const { return completed_; }
974
975 private:
976 bool completed_;
977 std::vector<std::string> tones_;
978 };
979
deadbeefaf1b59c2015-10-15 12:08:41 -0700980 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {}
981
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800982 bool Init(
983 const MediaConstraintsInterface* constraints,
984 const PeerConnectionFactory::Options* options,
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700985 const PeerConnectionInterface::RTCConfiguration* config,
Henrik Boströmd79599d2016-06-01 13:58:50 +0200986 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
perkj8aba9972016-04-10 23:54:34 -0700987 bool prefer_constraint_apis,
danilchape9021a32016-05-17 01:52:02 -0700988 rtc::Thread* network_thread,
perkj8aba9972016-04-10 23:54:34 -0700989 rtc::Thread* worker_thread) {
deadbeefaf1b59c2015-10-15 12:08:41 -0700990 EXPECT_TRUE(!peer_connection_);
991 EXPECT_TRUE(!peer_connection_factory_);
htaaac2dea2016-03-10 13:35:55 -0800992 if (!prefer_constraint_apis) {
993 EXPECT_TRUE(!constraints);
994 }
995 prefer_constraint_apis_ = prefer_constraint_apis;
996
Taylor Brandstettere5835f52016-09-16 15:07:50 -0700997 fake_network_manager_.reset(new rtc::FakeNetworkManager());
998 fake_network_manager_->AddInterface(rtc::SocketAddress("192.168.1.1", 0));
999
kwibergd1fe2812016-04-27 06:47:29 -07001000 std::unique_ptr<cricket::PortAllocator> port_allocator(
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001001 new cricket::BasicPortAllocator(fake_network_manager_.get()));
deadbeefaf1b59c2015-10-15 12:08:41 -07001002 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
1003
1004 if (fake_audio_capture_module_ == nullptr) {
1005 return false;
1006 }
1007 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory();
1008 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory();
danilchape9021a32016-05-17 01:52:02 -07001009 rtc::Thread* const signaling_thread = rtc::Thread::Current();
deadbeefaf1b59c2015-10-15 12:08:41 -07001010 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -07001011 network_thread, worker_thread, signaling_thread,
1012 fake_audio_capture_module_, fake_video_encoder_factory_,
1013 fake_video_decoder_factory_);
deadbeefaf1b59c2015-10-15 12:08:41 -07001014 if (!peer_connection_factory_) {
1015 return false;
1016 }
1017 if (options) {
1018 peer_connection_factory_->SetOptions(*options);
1019 }
zhihuang9763d562016-08-05 11:14:50 -07001020 peer_connection_ =
1021 CreatePeerConnection(std::move(port_allocator), constraints, config,
1022 std::move(cert_generator));
deadbeefaf1b59c2015-10-15 12:08:41 -07001023 return peer_connection_.get() != nullptr;
1024 }
1025
deadbeefaf1b59c2015-10-15 12:08:41 -07001026 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(
kwibergd1fe2812016-04-27 06:47:29 -07001027 std::unique_ptr<cricket::PortAllocator> port_allocator,
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001028 const MediaConstraintsInterface* constraints,
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001029 const PeerConnectionInterface::RTCConfiguration* config,
Henrik Boströmd79599d2016-06-01 13:58:50 +02001030 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001031 // CreatePeerConnection with RTCConfiguration.
1032 PeerConnectionInterface::RTCConfiguration default_config;
1033
1034 if (!config) {
1035 config = &default_config;
1036 }
1037
Henrik Boströmd79599d2016-06-01 13:58:50 +02001038 return peer_connection_factory_->CreatePeerConnection(
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001039 *config, constraints, std::move(port_allocator),
Henrik Boströmd79599d2016-06-01 13:58:50 +02001040 std::move(cert_generator), this);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041 }
1042
1043 void HandleIncomingOffer(const std::string& msg) {
deadbeefaf1b59c2015-10-15 12:08:41 -07001044 LOG(INFO) << id_ << "HandleIncomingOffer ";
deadbeeffaac4972015-11-12 15:33:07 -08001045 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001046 // If we are not sending any streams ourselves it is time to add some.
1047 AddMediaStream(true, true);
1048 }
kwibergd1fe2812016-04-27 06:47:29 -07001049 std::unique_ptr<SessionDescriptionInterface> desc(
deadbeefaf1b59c2015-10-15 12:08:41 -07001050 webrtc::CreateSessionDescription("offer", msg, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001051 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
zhihuang184a3fd2016-06-14 11:47:14 -07001052 // Set the RtpReceiverObserver after receivers are created.
1053 SetRtpReceiverObservers();
kwibergd1fe2812016-04-27 06:47:29 -07001054 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001055 EXPECT_TRUE(DoCreateAnswer(&answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056 std::string sdp;
1057 EXPECT_TRUE(answer->ToString(&sdp));
1058 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001059 SendSdpMessage(webrtc::SessionDescriptionInterface::kAnswer, sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 }
1061
1062 void HandleIncomingAnswer(const std::string& msg) {
deadbeefaf1b59c2015-10-15 12:08:41 -07001063 LOG(INFO) << id_ << "HandleIncomingAnswer";
kwibergd1fe2812016-04-27 06:47:29 -07001064 std::unique_ptr<SessionDescriptionInterface> desc(
deadbeefaf1b59c2015-10-15 12:08:41 -07001065 webrtc::CreateSessionDescription("answer", msg, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001066 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
zhihuang184a3fd2016-06-14 11:47:14 -07001067 // Set the RtpReceiverObserver after receivers are created.
1068 SetRtpReceiverObservers();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 }
1070
kwibergd1fe2812016-04-27 06:47:29 -07001071 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 bool offer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001073 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
1074 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 MockCreateSessionDescriptionObserver>());
htaaac2dea2016-03-10 13:35:55 -08001076 if (prefer_constraint_apis_) {
1077 if (offer) {
1078 pc()->CreateOffer(observer, &offer_answer_constraints_);
1079 } else {
1080 pc()->CreateAnswer(observer, &offer_answer_constraints_);
1081 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082 } else {
htaaac2dea2016-03-10 13:35:55 -08001083 if (offer) {
1084 pc()->CreateOffer(observer, offer_answer_options_);
1085 } else {
1086 pc()->CreateAnswer(observer, offer_answer_options_);
1087 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088 }
1089 EXPECT_EQ_WAIT(true, observer->called(), kMaxWaitMs);
kwiberg2bbff992016-03-16 11:03:04 -07001090 desc->reset(observer->release_desc());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001091 if (observer->result() && ExpectIceRestart()) {
1092 EXPECT_EQ(0u, (*desc)->candidates(0)->count());
1093 }
1094 return observer->result();
1095 }
1096
kwibergd1fe2812016-04-27 06:47:29 -07001097 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098 return DoCreateOfferAnswer(desc, true);
1099 }
1100
kwibergd1fe2812016-04-27 06:47:29 -07001101 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 return DoCreateOfferAnswer(desc, false);
1103 }
1104
1105 bool DoSetLocalDescription(SessionDescriptionInterface* desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001106 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
1107 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001108 MockSetSessionDescriptionObserver>());
deadbeefaf1b59c2015-10-15 12:08:41 -07001109 LOG(INFO) << id_ << "SetLocalDescription ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110 pc()->SetLocalDescription(observer, desc);
1111 // Ignore the observer result. If we wait for the result with
1112 // EXPECT_TRUE_WAIT, local ice candidates might be sent to the remote peer
1113 // before the offer which is an error.
1114 // The reason is that EXPECT_TRUE_WAIT uses
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001115 // rtc::Thread::Current()->ProcessMessages(1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001116 // ProcessMessages waits at least 1ms but processes all messages before
1117 // returning. Since this test is synchronous and send messages to the remote
1118 // peer whenever a callback is invoked, this can lead to messages being
1119 // sent to the remote peer in the wrong order.
1120 // TODO(perkj): Find a way to check the result without risking that the
1121 // order of sent messages are changed. Ex- by posting all messages that are
1122 // sent to the remote peer.
1123 return true;
1124 }
1125
1126 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001127 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
1128 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001129 MockSetSessionDescriptionObserver>());
deadbeefaf1b59c2015-10-15 12:08:41 -07001130 LOG(INFO) << id_ << "SetRemoteDescription ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131 pc()->SetRemoteDescription(observer, desc);
1132 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
1133 return observer->result();
1134 }
1135
1136 // This modifies all received SDP messages before they are processed.
1137 void FilterIncomingSdpMessage(std::string* sdp) {
1138 if (remove_msid_) {
1139 const char kSdpSsrcAttribute[] = "a=ssrc:";
1140 RemoveLinesFromSdp(kSdpSsrcAttribute, sdp);
1141 const char kSdpMsidSupportedAttribute[] = "a=msid-semantic:";
1142 RemoveLinesFromSdp(kSdpMsidSupportedAttribute, sdp);
1143 }
1144 if (remove_bundle_) {
1145 const char kSdpBundleAttribute[] = "a=group:BUNDLE";
1146 RemoveLinesFromSdp(kSdpBundleAttribute, sdp);
1147 }
1148 if (remove_sdes_) {
1149 const char kSdpSdesCryptoAttribute[] = "a=crypto";
1150 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp);
1151 }
perkjcaafdba2016-03-20 07:34:29 -07001152 if (remove_cvo_) {
1153 const char kSdpCvoExtenstion[] = "urn:3gpp:video-orientation";
1154 RemoveLinesFromSdp(kSdpCvoExtenstion, sdp);
1155 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001156 }
1157
deadbeefaf1b59c2015-10-15 12:08:41 -07001158 std::string id_;
1159
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001160 std::unique_ptr<rtc::FakeNetworkManager> fake_network_manager_;
1161
deadbeefaf1b59c2015-10-15 12:08:41 -07001162 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
1163 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
1164 peer_connection_factory_;
1165
htaaac2dea2016-03-10 13:35:55 -08001166 bool prefer_constraint_apis_ = true;
deadbeeffaac4972015-11-12 15:33:07 -08001167 bool auto_add_stream_ = true;
1168
deadbeefaf1b59c2015-10-15 12:08:41 -07001169 typedef std::pair<std::string, std::string> IceUfragPwdPair;
1170 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_;
1171 bool expect_ice_restart_ = false;
Honghai Zhang4cedf2b2016-08-31 08:18:11 -07001172 bool expect_ice_renomination_ = false;
1173 bool expect_remote_ice_renomination_ = false;
deadbeefaf1b59c2015-10-15 12:08:41 -07001174
deadbeefc9be0072015-12-14 18:27:57 -08001175 // Needed to keep track of number of frames sent.
deadbeefaf1b59c2015-10-15 12:08:41 -07001176 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
1177 // Needed to keep track of number of frames received.
kwibergd1fe2812016-04-27 06:47:29 -07001178 std::map<std::string, std::unique_ptr<webrtc::FakeVideoTrackRenderer>>
deadbeefc9be0072015-12-14 18:27:57 -08001179 fake_video_renderers_;
1180 // Needed to ensure frames aren't received for removed tracks.
kwibergd1fe2812016-04-27 06:47:29 -07001181 std::vector<std::unique_ptr<webrtc::FakeVideoTrackRenderer>>
deadbeefc9be0072015-12-14 18:27:57 -08001182 removed_fake_video_renderers_;
deadbeefaf1b59c2015-10-15 12:08:41 -07001183 // Needed to keep track of number of frames received when external decoder
1184 // used.
1185 FakeWebRtcVideoDecoderFactory* fake_video_decoder_factory_ = nullptr;
1186 FakeWebRtcVideoEncoderFactory* fake_video_encoder_factory_ = nullptr;
1187 bool video_decoder_factory_enabled_ = false;
1188 webrtc::FakeConstraints video_constraints_;
1189
1190 // For remote peer communication.
1191 SignalingMessageReceiver* signaling_message_receiver_ = nullptr;
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001192 int signaling_delay_ms_ = 0;
deadbeefaf1b59c2015-10-15 12:08:41 -07001193
1194 // Store references to the video capturers we've created, so that we can stop
1195 // them, if required.
perkjcaafdba2016-03-20 07:34:29 -07001196 std::vector<cricket::FakeVideoCapturer*> video_capturers_;
1197 webrtc::VideoRotation capture_rotation_ = webrtc::kVideoRotation_0;
1198 // |local_video_renderer_| attached to the first created local video track.
kwibergd1fe2812016-04-27 06:47:29 -07001199 std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_;
deadbeefaf1b59c2015-10-15 12:08:41 -07001200
htaaac2dea2016-03-10 13:35:55 -08001201 webrtc::FakeConstraints offer_answer_constraints_;
1202 PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_;
deadbeefaf1b59c2015-10-15 12:08:41 -07001203 bool remove_msid_ = false; // True if MSID should be removed in received SDP.
1204 bool remove_bundle_ =
1205 false; // True if bundle should be removed in received SDP.
1206 bool remove_sdes_ =
1207 false; // True if a=crypto should be removed in received SDP.
perkjcaafdba2016-03-20 07:34:29 -07001208 // |remove_cvo_| is true if extension urn:3gpp:video-orientation should be
1209 // removed in the received SDP.
1210 bool remove_cvo_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001211
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001212 rtc::scoped_refptr<DataChannelInterface> data_channel_;
kwibergd1fe2812016-04-27 06:47:29 -07001213 std::unique_ptr<MockDataChannelObserver> data_observer_;
zhihuang184a3fd2016-06-14 11:47:14 -07001214
1215 std::vector<std::unique_ptr<MockRtpReceiverObserver>> rtp_receiver_observers_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001216};
1217
deadbeef7c73bdb2015-12-10 15:10:44 -08001218class P2PTestConductor : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001219 public:
deadbeef7c73bdb2015-12-10 15:10:44 -08001220 P2PTestConductor()
deadbeefeff5b852016-05-27 14:18:01 -07001221 : pss_(new rtc::PhysicalSocketServer),
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +00001222 ss_(new rtc::VirtualSocketServer(pss_.get())),
deadbeefeff5b852016-05-27 14:18:01 -07001223 network_thread_(new rtc::Thread(ss_.get())),
1224 worker_thread_(rtc::Thread::Create()) {
danilchape9021a32016-05-17 01:52:02 -07001225 RTC_CHECK(network_thread_->Start());
1226 RTC_CHECK(worker_thread_->Start());
perkj8aba9972016-04-10 23:54:34 -07001227 }
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +00001228
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001229 bool SessionActive() {
1230 return initiating_client_->SessionActive() &&
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +00001231 receiving_client_->SessionActive();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 }
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +00001233
hta6b4f8392016-03-10 00:24:31 -08001234 // Return true if the number of frames provided have been received
1235 // on the video and audio tracks provided.
1236 bool FramesHaveArrived(int audio_frames_to_receive,
1237 int video_frames_to_receive) {
1238 bool all_good = true;
1239 if (initiating_client_->HasLocalAudioTrack() &&
1240 receiving_client_->can_receive_audio()) {
1241 all_good &=
1242 receiving_client_->AudioFramesReceivedCheck(audio_frames_to_receive);
1243 }
1244 if (initiating_client_->HasLocalVideoTrack() &&
1245 receiving_client_->can_receive_video()) {
1246 all_good &=
1247 receiving_client_->VideoFramesReceivedCheck(video_frames_to_receive);
1248 }
1249 if (receiving_client_->HasLocalAudioTrack() &&
1250 initiating_client_->can_receive_audio()) {
1251 all_good &=
1252 initiating_client_->AudioFramesReceivedCheck(audio_frames_to_receive);
1253 }
1254 if (receiving_client_->HasLocalVideoTrack() &&
1255 initiating_client_->can_receive_video()) {
1256 all_good &=
1257 initiating_client_->VideoFramesReceivedCheck(video_frames_to_receive);
1258 }
1259 return all_good;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001260 }
hta6b4f8392016-03-10 00:24:31 -08001261
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001262 void VerifyDtmf() {
1263 initiating_client_->VerifyDtmf();
1264 receiving_client_->VerifyDtmf();
1265 }
1266
1267 void TestUpdateOfferWithRejectedContent() {
deadbeefc9be0072015-12-14 18:27:57 -08001268 // Renegotiate, rejecting the video m-line.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001269 initiating_client_->Negotiate(true, false);
deadbeefc9be0072015-12-14 18:27:57 -08001270 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
1271
1272 int pc1_audio_received = initiating_client_->audio_frames_received();
1273 int pc1_video_received = initiating_client_->video_frames_received();
1274 int pc2_audio_received = receiving_client_->audio_frames_received();
1275 int pc2_video_received = receiving_client_->video_frames_received();
1276
1277 // Wait for some additional audio frames to be received.
1278 EXPECT_TRUE_WAIT(initiating_client_->AudioFramesReceivedCheck(
1279 pc1_audio_received + kEndAudioFrameCount) &&
1280 receiving_client_->AudioFramesReceivedCheck(
1281 pc2_audio_received + kEndAudioFrameCount),
1282 kMaxWaitForFramesMs);
1283
1284 // During this time, we shouldn't have received any additional video frames
1285 // for the rejected video tracks.
1286 EXPECT_EQ(pc1_video_received, initiating_client_->video_frames_received());
1287 EXPECT_EQ(pc2_video_received, receiving_client_->video_frames_received());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 }
1289
1290 void VerifyRenderedSize(int width, int height) {
perkjcaafdba2016-03-20 07:34:29 -07001291 VerifyRenderedSize(width, height, webrtc::kVideoRotation_0);
1292 }
1293
1294 void VerifyRenderedSize(int width,
1295 int height,
1296 webrtc::VideoRotation rotation) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001297 EXPECT_EQ(width, receiving_client()->rendered_width());
1298 EXPECT_EQ(height, receiving_client()->rendered_height());
perkjcaafdba2016-03-20 07:34:29 -07001299 EXPECT_EQ(rotation, receiving_client()->rendered_rotation());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 EXPECT_EQ(width, initializing_client()->rendered_width());
1301 EXPECT_EQ(height, initializing_client()->rendered_height());
perkjcaafdba2016-03-20 07:34:29 -07001302 EXPECT_EQ(rotation, initializing_client()->rendered_rotation());
1303
1304 // Verify size of the local preview.
1305 EXPECT_EQ(width, initializing_client()->local_rendered_width());
1306 EXPECT_EQ(height, initializing_client()->local_rendered_height());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001307 }
1308
1309 void VerifySessionDescriptions() {
1310 initiating_client_->VerifyRejectedMediaInSessionDescription();
1311 receiving_client_->VerifyRejectedMediaInSessionDescription();
1312 initiating_client_->VerifyLocalIceUfragAndPassword();
1313 receiving_client_->VerifyLocalIceUfragAndPassword();
1314 }
1315
deadbeef7c73bdb2015-12-10 15:10:44 -08001316 ~P2PTestConductor() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317 if (initiating_client_) {
deadbeefaf1b59c2015-10-15 12:08:41 -07001318 initiating_client_->set_signaling_message_receiver(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001319 }
1320 if (receiving_client_) {
deadbeefaf1b59c2015-10-15 12:08:41 -07001321 receiving_client_->set_signaling_message_receiver(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001323 }
1324
deadbeefaf1b59c2015-10-15 12:08:41 -07001325 bool CreateTestClients() { return CreateTestClients(nullptr, nullptr); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326
1327 bool CreateTestClients(MediaConstraintsInterface* init_constraints,
1328 MediaConstraintsInterface* recv_constraints) {
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001329 return CreateTestClients(init_constraints, nullptr, 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);
Joachim Bauch04e5b492015-05-29 09:40:39 +02001338 }
1339
htaaac2dea2016-03-10 13:35:55 -08001340 bool CreateTestClientsThatPreferNoConstraints() {
1341 initiating_client_.reset(
perkj8aba9972016-04-10 23:54:34 -07001342 PeerConnectionTestClient::CreateClientPreferNoConstraints(
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001343 "Caller: ", nullptr, network_thread_.get(), worker_thread_.get()));
htaaac2dea2016-03-10 13:35:55 -08001344 receiving_client_.reset(
perkj8aba9972016-04-10 23:54:34 -07001345 PeerConnectionTestClient::CreateClientPreferNoConstraints(
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001346 "Callee: ", nullptr, network_thread_.get(), worker_thread_.get()));
htaaac2dea2016-03-10 13:35:55 -08001347 if (!initiating_client_ || !receiving_client_) {
1348 return false;
1349 }
1350 // Remember the choice for possible later resets of the clients.
1351 prefer_constraint_apis_ = false;
1352 SetSignalingReceivers();
1353 return true;
1354 }
1355
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001356 bool CreateTestClients(
1357 MediaConstraintsInterface* init_constraints,
1358 PeerConnectionFactory::Options* init_options,
1359 const PeerConnectionInterface::RTCConfiguration* init_config,
1360 MediaConstraintsInterface* recv_constraints,
1361 PeerConnectionFactory::Options* recv_options,
1362 const PeerConnectionInterface::RTCConfiguration* recv_config) {
deadbeefaf1b59c2015-10-15 12:08:41 -07001363 initiating_client_.reset(PeerConnectionTestClient::CreateClient(
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001364 "Caller: ", init_constraints, init_options, init_config,
zhihuang9763d562016-08-05 11:14:50 -07001365 network_thread_.get(), worker_thread_.get()));
deadbeefaf1b59c2015-10-15 12:08:41 -07001366 receiving_client_.reset(PeerConnectionTestClient::CreateClient(
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001367 "Callee: ", recv_constraints, recv_options, recv_config,
zhihuang9763d562016-08-05 11:14:50 -07001368 network_thread_.get(), worker_thread_.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001369 if (!initiating_client_ || !receiving_client_) {
1370 return false;
1371 }
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001372 SetSignalingReceivers();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001373 return true;
1374 }
1375
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001376 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
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001386 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints,
1387 const webrtc::FakeConstraints& recv_constraints) {
1388 initiating_client_->SetVideoConstraints(init_constraints);
1389 receiving_client_->SetVideoConstraints(recv_constraints);
1390 }
1391
perkjcaafdba2016-03-20 07:34:29 -07001392 void SetCaptureRotation(webrtc::VideoRotation rotation) {
1393 initiating_client_->SetCaptureRotation(rotation);
1394 receiving_client_->SetCaptureRotation(rotation);
1395 }
1396
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397 void EnableVideoDecoderFactory() {
1398 initiating_client_->EnableVideoDecoderFactory();
1399 receiving_client_->EnableVideoDecoderFactory();
1400 }
1401
1402 // This test sets up a call between two parties. Both parties send static
1403 // frames to each other. Once the test is finished the number of sent frames
1404 // is compared to the number of received frames.
Taylor Brandstetter0a1bc532016-04-19 18:03:26 -07001405 void LocalP2PTest() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001406 if (initiating_client_->NumberOfLocalMediaStreams() == 0) {
1407 initiating_client_->AddMediaStream(true, true);
1408 }
1409 initiating_client_->Negotiate();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001410 // Assert true is used here since next tests are guaranteed to fail and
1411 // would eat up 5 seconds.
1412 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
1413 VerifySessionDescriptions();
1414
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001415 int audio_frame_count = kEndAudioFrameCount;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001416 int video_frame_count = kEndVideoFrameCount;
hta6b4f8392016-03-10 00:24:31 -08001417 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly.
1418
1419 if ((!initiating_client_->can_receive_audio() &&
1420 !initiating_client_->can_receive_video()) ||
1421 (!receiving_client_->can_receive_audio() &&
1422 !receiving_client_->can_receive_video())) {
1423 // Neither audio nor video will flow, so connections won't be
1424 // established. There's nothing more to check.
1425 // TODO(hta): Check connection if there's a data channel.
1426 return;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 }
1428
hta6b4f8392016-03-10 00:24:31 -08001429 // Audio or video is expected to flow, so both clients should reach the
1430 // Connected state, and the offerer (ICE controller) should proceed to
1431 // Completed.
1432 // Note: These tests have been observed to fail under heavy load at
1433 // shorter timeouts, so they may be flaky.
Taylor Brandstetter0a1bc532016-04-19 18:03:26 -07001434 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
1435 initiating_client_->ice_connection_state(),
1436 kMaxWaitForFramesMs);
hta6b4f8392016-03-10 00:24:31 -08001437 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
1438 receiving_client_->ice_connection_state(),
1439 kMaxWaitForFramesMs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001440
hta6b4f8392016-03-10 00:24:31 -08001441 // The ICE gathering state should end up in kIceGatheringComplete,
1442 // but there's a bug that prevents this at the moment, and the state
1443 // machine is being updated by the WEBRTC WG.
1444 // TODO(hta): Update this check when spec revisions finish.
1445 EXPECT_NE(webrtc::PeerConnectionInterface::kIceGatheringNew,
1446 initiating_client_->ice_gathering_state());
1447 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
1448 receiving_client_->ice_gathering_state(),
1449 kMaxWaitForFramesMs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450
hta6b4f8392016-03-10 00:24:31 -08001451 // Check that the expected number of frames have arrived.
1452 EXPECT_TRUE_WAIT(FramesHaveArrived(audio_frame_count, video_frame_count),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001453 kMaxWaitForFramesMs);
1454 }
1455
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001456 void SetupAndVerifyDtlsCall() {
1457 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1458 FakeConstraints setup_constraints;
1459 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1460 true);
1461 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1462 LocalP2PTest();
1463 VerifyRenderedSize(640, 480);
1464 }
1465
1466 PeerConnectionTestClient* CreateDtlsClientWithAlternateKey() {
1467 FakeConstraints setup_constraints;
1468 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1469 true);
1470
Henrik Boströmd79599d2016-06-01 13:58:50 +02001471 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
1472 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
1473 new FakeRTCCertificateGenerator() : nullptr);
1474 cert_generator->use_alternate_key();
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001475
1476 // Make sure the new client is using a different certificate.
1477 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore(
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001478 "New Peer: ", &setup_constraints, nullptr, nullptr,
Henrik Boströmd79599d2016-06-01 13:58:50 +02001479 std::move(cert_generator), prefer_constraint_apis_,
danilchape9021a32016-05-17 01:52:02 -07001480 network_thread_.get(), worker_thread_.get());
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001481 }
1482
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001483 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) {
1484 // Messages may get lost on the unreliable DataChannel, so we send multiple
1485 // times to avoid test flakiness.
1486 static const size_t kSendAttempts = 5;
1487
1488 for (size_t i = 0; i < kSendAttempts; ++i) {
1489 dc->Send(DataBuffer(data));
1490 }
1491 }
1492
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001493 rtc::Thread* network_thread() { return network_thread_.get(); }
1494
Taylor Brandstetter9b5306c2016-08-18 11:40:37 -07001495 rtc::VirtualSocketServer* virtual_socket_server() { return ss_.get(); }
1496
deadbeefaf1b59c2015-10-15 12:08:41 -07001497 PeerConnectionTestClient* initializing_client() {
1498 return initiating_client_.get();
1499 }
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001500
1501 // Set the |initiating_client_| to the |client| passed in and return the
1502 // original |initiating_client_|.
1503 PeerConnectionTestClient* set_initializing_client(
1504 PeerConnectionTestClient* client) {
1505 PeerConnectionTestClient* old = initiating_client_.release();
1506 initiating_client_.reset(client);
1507 return old;
1508 }
1509
deadbeefaf1b59c2015-10-15 12:08:41 -07001510 PeerConnectionTestClient* receiving_client() {
1511 return receiving_client_.get();
1512 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001513
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001514 // Set the |receiving_client_| to the |client| passed in and return the
1515 // original |receiving_client_|.
1516 PeerConnectionTestClient* set_receiving_client(
1517 PeerConnectionTestClient* client) {
1518 PeerConnectionTestClient* old = receiving_client_.release();
1519 receiving_client_.reset(client);
1520 return old;
1521 }
1522
zhihuang184a3fd2016-06-14 11:47:14 -07001523 bool AllObserversReceived(
1524 const std::vector<std::unique_ptr<MockRtpReceiverObserver>>& observers) {
1525 for (auto& observer : observers) {
1526 if (!observer->first_packet_received()) {
1527 return false;
1528 }
1529 }
1530 return true;
1531 }
1532
jbauchcb560652016-08-04 05:20:32 -07001533 void TestGcmNegotiation(bool local_gcm_enabled, bool remote_gcm_enabled,
1534 int expected_cipher_suite) {
1535 PeerConnectionFactory::Options init_options;
1536 init_options.crypto_options.enable_gcm_crypto_suites = local_gcm_enabled;
1537 PeerConnectionFactory::Options recv_options;
1538 recv_options.crypto_options.enable_gcm_crypto_suites = remote_gcm_enabled;
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001539 ASSERT_TRUE(CreateTestClients(nullptr, &init_options, nullptr, nullptr,
1540 &recv_options, nullptr));
jbauchcb560652016-08-04 05:20:32 -07001541 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1542 init_observer =
1543 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1544 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1545 LocalP2PTest();
1546
1547 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite),
1548 initializing_client()->GetSrtpCipherStats(),
1549 kMaxWaitMs);
1550 EXPECT_EQ(1,
1551 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1552 expected_cipher_suite));
1553 }
1554
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555 private:
deadbeefeff5b852016-05-27 14:18:01 -07001556 // |ss_| is used by |network_thread_| so it must be destroyed later.
kwibergd1fe2812016-04-27 06:47:29 -07001557 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1558 std::unique_ptr<rtc::VirtualSocketServer> ss_;
deadbeefeff5b852016-05-27 14:18:01 -07001559 // |network_thread_| and |worker_thread_| are used by both
1560 // |initiating_client_| and |receiving_client_| so they must be destroyed
1561 // later.
1562 std::unique_ptr<rtc::Thread> network_thread_;
1563 std::unique_ptr<rtc::Thread> worker_thread_;
kwibergd1fe2812016-04-27 06:47:29 -07001564 std::unique_ptr<PeerConnectionTestClient> initiating_client_;
1565 std::unique_ptr<PeerConnectionTestClient> receiving_client_;
htaaac2dea2016-03-10 13:35:55 -08001566 bool prefer_constraint_apis_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001567};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568
kjellander@webrtc.orgd1cfa712013-10-16 16:51:52 +00001569// Disable for TSan v2, see
1570// https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
1571#if !defined(THREAD_SANITIZER)
1572
zhihuang184a3fd2016-06-14 11:47:14 -07001573TEST_F(P2PTestConductor, TestRtpReceiverObserverCallbackFunction) {
1574 ASSERT_TRUE(CreateTestClients());
1575 LocalP2PTest();
1576 EXPECT_TRUE_WAIT(
1577 AllObserversReceived(initializing_client()->rtp_receiver_observers()),
1578 kMaxWaitForFramesMs);
1579 EXPECT_TRUE_WAIT(
1580 AllObserversReceived(receiving_client()->rtp_receiver_observers()),
1581 kMaxWaitForFramesMs);
1582}
1583
1584// The observers are expected to fire the signal even if they are set after the
1585// first packet is received.
1586TEST_F(P2PTestConductor, TestSetRtpReceiverObserverAfterFirstPacketIsReceived) {
1587 ASSERT_TRUE(CreateTestClients());
1588 LocalP2PTest();
1589 // Reset the RtpReceiverObservers.
1590 initializing_client()->SetRtpReceiverObservers();
1591 receiving_client()->SetRtpReceiverObservers();
1592 EXPECT_TRUE_WAIT(
1593 AllObserversReceived(initializing_client()->rtp_receiver_observers()),
1594 kMaxWaitForFramesMs);
1595 EXPECT_TRUE_WAIT(
1596 AllObserversReceived(receiving_client()->rtp_receiver_observers()),
1597 kMaxWaitForFramesMs);
1598}
1599
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001600// This test sets up a Jsep call between two parties and test Dtmf.
stefan@webrtc.orgda790082013-09-17 13:11:38 +00001601// TODO(holmer): Disabled due to sometimes crashing on buildbots.
1602// See issue webrtc/2378.
deadbeef7c73bdb2015-12-10 15:10:44 -08001603TEST_F(P2PTestConductor, DISABLED_LocalP2PTestDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 ASSERT_TRUE(CreateTestClients());
1605 LocalP2PTest();
1606 VerifyDtmf();
1607}
1608
1609// This test sets up a Jsep call between two parties and test that we can get a
1610// video aspect ratio of 16:9.
deadbeef7c73bdb2015-12-10 15:10:44 -08001611TEST_F(P2PTestConductor, LocalP2PTest16To9) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 ASSERT_TRUE(CreateTestClients());
1613 FakeConstraints constraint;
1614 double requested_ratio = 640.0/360;
1615 constraint.SetMandatoryMinAspectRatio(requested_ratio);
1616 SetVideoConstraints(constraint, constraint);
1617 LocalP2PTest();
1618
1619 ASSERT_LE(0, initializing_client()->rendered_height());
1620 double initiating_video_ratio =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001621 static_cast<double>(initializing_client()->rendered_width()) /
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622 initializing_client()->rendered_height();
1623 EXPECT_LE(requested_ratio, initiating_video_ratio);
1624
1625 ASSERT_LE(0, receiving_client()->rendered_height());
1626 double receiving_video_ratio =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001627 static_cast<double>(receiving_client()->rendered_width()) /
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628 receiving_client()->rendered_height();
1629 EXPECT_LE(requested_ratio, receiving_video_ratio);
1630}
1631
1632// This test sets up a Jsep call between two parties and test that the
1633// received video has a resolution of 1280*720.
1634// TODO(mallinath): Enable when
1635// http://code.google.com/p/webrtc/issues/detail?id=981 is fixed.
deadbeef7c73bdb2015-12-10 15:10:44 -08001636TEST_F(P2PTestConductor, DISABLED_LocalP2PTest1280By720) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637 ASSERT_TRUE(CreateTestClients());
1638 FakeConstraints constraint;
1639 constraint.SetMandatoryMinWidth(1280);
1640 constraint.SetMandatoryMinHeight(720);
1641 SetVideoConstraints(constraint, constraint);
1642 LocalP2PTest();
1643 VerifyRenderedSize(1280, 720);
1644}
1645
1646// This test sets up a call between two endpoints that are configured to use
1647// DTLS key agreement. As a result, DTLS is negotiated and used for transport.
deadbeef7c73bdb2015-12-10 15:10:44 -08001648TEST_F(P2PTestConductor, LocalP2PTestDtls) {
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001649 SetupAndVerifyDtlsCall();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650}
1651
hta6b4f8392016-03-10 00:24:31 -08001652// This test sets up an one-way call, with media only from initiator to
1653// responder.
1654TEST_F(P2PTestConductor, OneWayMediaCall) {
1655 ASSERT_TRUE(CreateTestClients());
1656 receiving_client()->set_auto_add_stream(false);
1657 LocalP2PTest();
1658}
1659
htaaac2dea2016-03-10 13:35:55 -08001660TEST_F(P2PTestConductor, OneWayMediaCallWithoutConstraints) {
1661 ASSERT_TRUE(CreateTestClientsThatPreferNoConstraints());
1662 receiving_client()->set_auto_add_stream(false);
1663 LocalP2PTest();
1664}
1665
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001666// This test sets up a audio call initially and then upgrades to audio/video,
1667// using DTLS.
deadbeef7c73bdb2015-12-10 15:10:44 -08001668TEST_F(P2PTestConductor, LocalP2PTestDtlsRenegotiate) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001669 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001670 FakeConstraints setup_constraints;
1671 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1672 true);
1673 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1674 receiving_client()->SetReceiveAudioVideo(true, false);
1675 LocalP2PTest();
1676 receiving_client()->SetReceiveAudioVideo(true, true);
1677 receiving_client()->Negotiate();
1678}
1679
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001680// This test sets up a call transfer to a new caller with a different DTLS
1681// fingerprint.
deadbeef7c73bdb2015-12-10 15:10:44 -08001682TEST_F(P2PTestConductor, LocalP2PTestDtlsTransferCallee) {
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001683 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1684 SetupAndVerifyDtlsCall();
1685
1686 // Keeping the original peer around which will still send packets to the
1687 // receiving client. These SRTP packets will be dropped.
kwibergd1fe2812016-04-27 06:47:29 -07001688 std::unique_ptr<PeerConnectionTestClient> original_peer(
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001689 set_initializing_client(CreateDtlsClientWithAlternateKey()));
1690 original_peer->pc()->Close();
1691
1692 SetSignalingReceivers();
1693 receiving_client()->SetExpectIceRestart(true);
1694 LocalP2PTest();
1695 VerifyRenderedSize(640, 480);
1696}
1697
guoweis46383312015-12-17 16:45:59 -08001698// This test sets up a non-bundle call and apply bundle during ICE restart. When
1699// bundle is in effect in the restart, the channel can successfully reset its
1700// DTLS-SRTP context.
1701TEST_F(P2PTestConductor, LocalP2PTestDtlsBundleInIceRestart) {
1702 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1703 FakeConstraints setup_constraints;
1704 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1705 true);
1706 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1707 receiving_client()->RemoveBundleFromReceivedSdp(true);
1708 LocalP2PTest();
1709 VerifyRenderedSize(640, 480);
1710
1711 initializing_client()->IceRestart();
1712 receiving_client()->SetExpectIceRestart(true);
1713 receiving_client()->RemoveBundleFromReceivedSdp(false);
1714 LocalP2PTest();
1715 VerifyRenderedSize(640, 480);
1716}
1717
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001718// This test sets up a call transfer to a new callee with a different DTLS
1719// fingerprint.
deadbeef7c73bdb2015-12-10 15:10:44 -08001720TEST_F(P2PTestConductor, LocalP2PTestDtlsTransferCaller) {
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001721 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1722 SetupAndVerifyDtlsCall();
1723
1724 // Keeping the original peer around which will still send packets to the
1725 // receiving client. These SRTP packets will be dropped.
kwibergd1fe2812016-04-27 06:47:29 -07001726 std::unique_ptr<PeerConnectionTestClient> original_peer(
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001727 set_receiving_client(CreateDtlsClientWithAlternateKey()));
1728 original_peer->pc()->Close();
1729
1730 SetSignalingReceivers();
1731 initializing_client()->IceRestart();
Taylor Brandstetter0a1bc532016-04-19 18:03:26 -07001732 LocalP2PTest();
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001733 VerifyRenderedSize(640, 480);
1734}
1735
perkjcaafdba2016-03-20 07:34:29 -07001736TEST_F(P2PTestConductor, LocalP2PTestCVO) {
1737 ASSERT_TRUE(CreateTestClients());
1738 SetCaptureRotation(webrtc::kVideoRotation_90);
1739 LocalP2PTest();
1740 VerifyRenderedSize(640, 480, webrtc::kVideoRotation_90);
1741}
1742
1743TEST_F(P2PTestConductor, LocalP2PTestReceiverDoesntSupportCVO) {
1744 ASSERT_TRUE(CreateTestClients());
1745 SetCaptureRotation(webrtc::kVideoRotation_90);
1746 receiving_client()->RemoveCvoFromReceivedSdp(true);
1747 LocalP2PTest();
1748 VerifyRenderedSize(480, 640, webrtc::kVideoRotation_0);
1749}
1750
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751// This test sets up a call between two endpoints that are configured to use
1752// DTLS key agreement. The offerer don't support SDES. As a result, DTLS is
1753// negotiated and used for transport.
deadbeef7c73bdb2015-12-10 15:10:44 -08001754TEST_F(P2PTestConductor, LocalP2PTestOfferDtlsButNotSdes) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001755 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 FakeConstraints setup_constraints;
1757 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1758 true);
1759 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1760 receiving_client()->RemoveSdesCryptoFromReceivedSdp(true);
1761 LocalP2PTest();
1762 VerifyRenderedSize(640, 480);
1763}
1764
1765// This test sets up a Jsep call between two parties, and the callee only
1766// accept to receive video.
deadbeef7c73bdb2015-12-10 15:10:44 -08001767TEST_F(P2PTestConductor, LocalP2PTestAnswerVideo) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 ASSERT_TRUE(CreateTestClients());
1769 receiving_client()->SetReceiveAudioVideo(false, true);
1770 LocalP2PTest();
1771}
1772
1773// This test sets up a Jsep call between two parties, and the callee only
1774// accept to receive audio.
deadbeef7c73bdb2015-12-10 15:10:44 -08001775TEST_F(P2PTestConductor, LocalP2PTestAnswerAudio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 ASSERT_TRUE(CreateTestClients());
1777 receiving_client()->SetReceiveAudioVideo(true, false);
1778 LocalP2PTest();
1779}
1780
1781// This test sets up a Jsep call between two parties, and the callee reject both
1782// audio and video.
deadbeef7c73bdb2015-12-10 15:10:44 -08001783TEST_F(P2PTestConductor, LocalP2PTestAnswerNone) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784 ASSERT_TRUE(CreateTestClients());
1785 receiving_client()->SetReceiveAudioVideo(false, false);
1786 LocalP2PTest();
1787}
1788
1789// This test sets up an audio and video call between two parties. After the call
1790// runs for a while (10 frames), the caller sends an update offer with video
1791// being rejected. Once the re-negotiation is done, the video flow should stop
1792// and the audio flow should continue.
deadbeefc9be0072015-12-14 18:27:57 -08001793TEST_F(P2PTestConductor, UpdateOfferWithRejectedContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794 ASSERT_TRUE(CreateTestClients());
1795 LocalP2PTest();
1796 TestUpdateOfferWithRejectedContent();
1797}
1798
1799// This test sets up a Jsep call between two parties. The MSID is removed from
1800// the SDP strings from the caller.
deadbeefc9be0072015-12-14 18:27:57 -08001801TEST_F(P2PTestConductor, LocalP2PTestWithoutMsid) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802 ASSERT_TRUE(CreateTestClients());
1803 receiving_client()->RemoveMsidFromReceivedSdp(true);
1804 // TODO(perkj): Currently there is a bug that cause audio to stop playing if
1805 // audio and video is muxed when MSID is disabled. Remove
1806 // SetRemoveBundleFromSdp once
1807 // https://code.google.com/p/webrtc/issues/detail?id=1193 is fixed.
1808 receiving_client()->RemoveBundleFromReceivedSdp(true);
1809 LocalP2PTest();
1810}
1811
1812// This test sets up a Jsep call between two parties and the initiating peer
1813// sends two steams.
1814// TODO(perkj): Disabled due to
1815// https://code.google.com/p/webrtc/issues/detail?id=1454
deadbeef7c73bdb2015-12-10 15:10:44 -08001816TEST_F(P2PTestConductor, DISABLED_LocalP2PTestTwoStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817 ASSERT_TRUE(CreateTestClients());
1818 // Set optional video constraint to max 320pixels to decrease CPU usage.
1819 FakeConstraints constraint;
1820 constraint.SetOptionalMaxWidth(320);
1821 SetVideoConstraints(constraint, constraint);
1822 initializing_client()->AddMediaStream(true, true);
1823 initializing_client()->AddMediaStream(false, true);
1824 ASSERT_EQ(2u, initializing_client()->NumberOfLocalMediaStreams());
1825 LocalP2PTest();
1826 EXPECT_EQ(2u, receiving_client()->number_of_remote_streams());
1827}
1828
1829// Test that we can receive the audio output level from a remote audio track.
deadbeef7c73bdb2015-12-10 15:10:44 -08001830TEST_F(P2PTestConductor, GetAudioOutputLevelStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831 ASSERT_TRUE(CreateTestClients());
1832 LocalP2PTest();
1833
1834 StreamCollectionInterface* remote_streams =
1835 initializing_client()->remote_streams();
1836 ASSERT_GT(remote_streams->count(), 0u);
1837 ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u);
1838 MediaStreamTrackInterface* remote_audio_track =
1839 remote_streams->at(0)->GetAudioTracks()[0];
1840
1841 // Get the audio output level stats. Note that the level is not available
1842 // until a RTCP packet has been received.
1843 EXPECT_TRUE_WAIT(
1844 initializing_client()->GetAudioOutputLevelStats(remote_audio_track) > 0,
1845 kMaxWaitForStatsMs);
1846}
1847
1848// Test that an audio input level is reported.
deadbeef7c73bdb2015-12-10 15:10:44 -08001849TEST_F(P2PTestConductor, GetAudioInputLevelStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001850 ASSERT_TRUE(CreateTestClients());
1851 LocalP2PTest();
1852
1853 // Get the audio input level stats. The level should be available very
1854 // soon after the test starts.
1855 EXPECT_TRUE_WAIT(initializing_client()->GetAudioInputLevelStats() > 0,
1856 kMaxWaitForStatsMs);
1857}
1858
1859// Test that we can get incoming byte counts from both audio and video tracks.
deadbeef7c73bdb2015-12-10 15:10:44 -08001860TEST_F(P2PTestConductor, GetBytesReceivedStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 ASSERT_TRUE(CreateTestClients());
1862 LocalP2PTest();
1863
1864 StreamCollectionInterface* remote_streams =
1865 initializing_client()->remote_streams();
1866 ASSERT_GT(remote_streams->count(), 0u);
1867 ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u);
1868 MediaStreamTrackInterface* remote_audio_track =
1869 remote_streams->at(0)->GetAudioTracks()[0];
1870 EXPECT_TRUE_WAIT(
1871 initializing_client()->GetBytesReceivedStats(remote_audio_track) > 0,
1872 kMaxWaitForStatsMs);
1873
1874 MediaStreamTrackInterface* remote_video_track =
1875 remote_streams->at(0)->GetVideoTracks()[0];
1876 EXPECT_TRUE_WAIT(
1877 initializing_client()->GetBytesReceivedStats(remote_video_track) > 0,
1878 kMaxWaitForStatsMs);
1879}
1880
1881// Test that we can get outgoing byte counts from both audio and video tracks.
deadbeef7c73bdb2015-12-10 15:10:44 -08001882TEST_F(P2PTestConductor, GetBytesSentStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883 ASSERT_TRUE(CreateTestClients());
1884 LocalP2PTest();
1885
1886 StreamCollectionInterface* local_streams =
1887 initializing_client()->local_streams();
1888 ASSERT_GT(local_streams->count(), 0u);
1889 ASSERT_GT(local_streams->at(0)->GetAudioTracks().size(), 0u);
1890 MediaStreamTrackInterface* local_audio_track =
1891 local_streams->at(0)->GetAudioTracks()[0];
1892 EXPECT_TRUE_WAIT(
1893 initializing_client()->GetBytesSentStats(local_audio_track) > 0,
1894 kMaxWaitForStatsMs);
1895
1896 MediaStreamTrackInterface* local_video_track =
1897 local_streams->at(0)->GetVideoTracks()[0];
1898 EXPECT_TRUE_WAIT(
1899 initializing_client()->GetBytesSentStats(local_video_track) > 0,
1900 kMaxWaitForStatsMs);
1901}
1902
Joachim Bauch04e5b492015-05-29 09:40:39 +02001903// Test that DTLS 1.0 is used if both sides only support DTLS 1.0.
torbjorng43166b82016-03-11 00:06:47 -08001904TEST_F(P2PTestConductor, GetDtls12None) {
Joachim Bauch04e5b492015-05-29 09:40:39 +02001905 PeerConnectionFactory::Options init_options;
1906 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1907 PeerConnectionFactory::Options recv_options;
1908 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001909 ASSERT_TRUE(CreateTestClients(nullptr, &init_options, nullptr, nullptr,
1910 &recv_options, nullptr));
jbauchac8869e2015-07-03 01:36:14 -07001911 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1912 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1913 initializing_client()->pc()->RegisterUMAObserver(init_observer);
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +00001914 LocalP2PTest();
1915
torbjorng43166b82016-03-11 00:06:47 -08001916 EXPECT_TRUE_WAIT(
1917 rtc::SSLStreamAdapter::IsAcceptableCipher(
1918 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1919 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001920 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001921 initializing_client()->GetSrtpCipherStats(),
1922 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001923 EXPECT_EQ(1,
1924 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1925 kDefaultSrtpCryptoSuite));
Joachim Bauch04e5b492015-05-29 09:40:39 +02001926}
1927
1928// Test that DTLS 1.2 is used if both ends support it.
torbjorng79a5a832016-01-15 07:16:51 -08001929TEST_F(P2PTestConductor, GetDtls12Both) {
Joachim Bauch04e5b492015-05-29 09:40:39 +02001930 PeerConnectionFactory::Options init_options;
1931 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1932 PeerConnectionFactory::Options recv_options;
1933 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001934 ASSERT_TRUE(CreateTestClients(nullptr, &init_options, nullptr, nullptr,
1935 &recv_options, nullptr));
jbauchac8869e2015-07-03 01:36:14 -07001936 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1937 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1938 initializing_client()->pc()->RegisterUMAObserver(init_observer);
Joachim Bauch04e5b492015-05-29 09:40:39 +02001939 LocalP2PTest();
1940
torbjorng43166b82016-03-11 00:06:47 -08001941 EXPECT_TRUE_WAIT(
1942 rtc::SSLStreamAdapter::IsAcceptableCipher(
1943 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1944 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001945 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001946 initializing_client()->GetSrtpCipherStats(),
1947 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001948 EXPECT_EQ(1,
1949 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1950 kDefaultSrtpCryptoSuite));
Joachim Bauch04e5b492015-05-29 09:40:39 +02001951}
1952
1953// Test that DTLS 1.0 is used if the initator supports DTLS 1.2 and the
1954// received supports 1.0.
torbjorng43166b82016-03-11 00:06:47 -08001955TEST_F(P2PTestConductor, GetDtls12Init) {
Joachim Bauch04e5b492015-05-29 09:40:39 +02001956 PeerConnectionFactory::Options init_options;
1957 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1958 PeerConnectionFactory::Options recv_options;
1959 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001960 ASSERT_TRUE(CreateTestClients(nullptr, &init_options, nullptr, nullptr,
1961 &recv_options, nullptr));
jbauchac8869e2015-07-03 01:36:14 -07001962 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1963 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1964 initializing_client()->pc()->RegisterUMAObserver(init_observer);
Joachim Bauch04e5b492015-05-29 09:40:39 +02001965 LocalP2PTest();
1966
torbjorng43166b82016-03-11 00:06:47 -08001967 EXPECT_TRUE_WAIT(
1968 rtc::SSLStreamAdapter::IsAcceptableCipher(
1969 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1970 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001971 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001972 initializing_client()->GetSrtpCipherStats(),
1973 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001974 EXPECT_EQ(1,
1975 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1976 kDefaultSrtpCryptoSuite));
Joachim Bauch04e5b492015-05-29 09:40:39 +02001977}
1978
1979// Test that DTLS 1.0 is used if the initator supports DTLS 1.0 and the
1980// received supports 1.2.
torbjorng43166b82016-03-11 00:06:47 -08001981TEST_F(P2PTestConductor, GetDtls12Recv) {
Joachim Bauch04e5b492015-05-29 09:40:39 +02001982 PeerConnectionFactory::Options init_options;
1983 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1984 PeerConnectionFactory::Options recv_options;
1985 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
Taylor Brandstettere5835f52016-09-16 15:07:50 -07001986 ASSERT_TRUE(CreateTestClients(nullptr, &init_options, nullptr, nullptr,
1987 &recv_options, nullptr));
jbauchac8869e2015-07-03 01:36:14 -07001988 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1989 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1990 initializing_client()->pc()->RegisterUMAObserver(init_observer);
Joachim Bauch04e5b492015-05-29 09:40:39 +02001991 LocalP2PTest();
1992
torbjorng43166b82016-03-11 00:06:47 -08001993 EXPECT_TRUE_WAIT(
1994 rtc::SSLStreamAdapter::IsAcceptableCipher(
1995 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1996 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001997 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001998 initializing_client()->GetSrtpCipherStats(),
1999 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08002000 EXPECT_EQ(1,
2001 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
2002 kDefaultSrtpCryptoSuite));
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +00002003}
2004
jbauchcb560652016-08-04 05:20:32 -07002005// Test that a non-GCM cipher is used if both sides only support non-GCM.
2006TEST_F(P2PTestConductor, GetGcmNone) {
2007 TestGcmNegotiation(false, false, kDefaultSrtpCryptoSuite);
2008}
2009
2010// Test that a GCM cipher is used if both ends support it.
2011TEST_F(P2PTestConductor, GetGcmBoth) {
2012 TestGcmNegotiation(true, true, kDefaultSrtpCryptoSuiteGcm);
2013}
2014
2015// Test that GCM isn't used if only the initiator supports it.
2016TEST_F(P2PTestConductor, GetGcmInit) {
2017 TestGcmNegotiation(true, false, kDefaultSrtpCryptoSuite);
2018}
2019
2020// Test that GCM isn't used if only the receiver supports it.
2021TEST_F(P2PTestConductor, GetGcmRecv) {
2022 TestGcmNegotiation(false, true, kDefaultSrtpCryptoSuite);
2023}
2024
deadbeefb5cb19b2015-11-23 16:39:12 -08002025// This test sets up a call between two parties with audio, video and an RTP
2026// data channel.
deadbeef7c73bdb2015-12-10 15:10:44 -08002027TEST_F(P2PTestConductor, LocalP2PTestRtpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028 FakeConstraints setup_constraints;
2029 setup_constraints.SetAllowRtpDataChannels();
2030 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
2031 initializing_client()->CreateDataChannel();
2032 LocalP2PTest();
deadbeefaf1b59c2015-10-15 12:08:41 -07002033 ASSERT_TRUE(initializing_client()->data_channel() != nullptr);
2034 ASSERT_TRUE(receiving_client()->data_channel() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
2036 kMaxWaitMs);
2037 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(),
2038 kMaxWaitMs);
2039
2040 std::string data = "hello world";
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00002041
2042 SendRtpData(initializing_client()->data_channel(), data);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(),
2044 kMaxWaitMs);
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00002045
2046 SendRtpData(receiving_client()->data_channel(), data);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(),
2048 kMaxWaitMs);
2049
2050 receiving_client()->data_channel()->Close();
2051 // Send new offer and answer.
2052 receiving_client()->Negotiate();
2053 EXPECT_FALSE(initializing_client()->data_observer()->IsOpen());
2054 EXPECT_FALSE(receiving_client()->data_observer()->IsOpen());
2055}
2056
deadbeefb5cb19b2015-11-23 16:39:12 -08002057// This test sets up a call between two parties with audio, video and an SCTP
2058// data channel.
deadbeef7c73bdb2015-12-10 15:10:44 -08002059TEST_F(P2PTestConductor, LocalP2PTestSctpDataChannel) {
deadbeefb5cb19b2015-11-23 16:39:12 -08002060 ASSERT_TRUE(CreateTestClients());
2061 initializing_client()->CreateDataChannel();
2062 LocalP2PTest();
2063 ASSERT_TRUE(initializing_client()->data_channel() != nullptr);
2064 EXPECT_TRUE_WAIT(receiving_client()->data_channel() != nullptr, kMaxWaitMs);
2065 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
2066 kMaxWaitMs);
2067 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), kMaxWaitMs);
2068
2069 std::string data = "hello world";
2070
2071 initializing_client()->data_channel()->Send(DataBuffer(data));
2072 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(),
2073 kMaxWaitMs);
2074
2075 receiving_client()->data_channel()->Send(DataBuffer(data));
2076 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(),
2077 kMaxWaitMs);
2078
2079 receiving_client()->data_channel()->Close();
deadbeef15887932015-12-14 19:32:34 -08002080 EXPECT_TRUE_WAIT(!initializing_client()->data_observer()->IsOpen(),
2081 kMaxWaitMs);
2082 EXPECT_TRUE_WAIT(!receiving_client()->data_observer()->IsOpen(), kMaxWaitMs);
deadbeefb5cb19b2015-11-23 16:39:12 -08002083}
2084
Taylor Brandstetter9b5306c2016-08-18 11:40:37 -07002085TEST_F(P2PTestConductor, UnorderedSctpDataChannel) {
2086 ASSERT_TRUE(CreateTestClients());
2087 webrtc::DataChannelInit init;
2088 init.ordered = false;
2089 initializing_client()->CreateDataChannel(&init);
2090
2091 // Introduce random network delays.
2092 // Otherwise it's not a true "unordered" test.
2093 virtual_socket_server()->set_delay_mean(20);
2094 virtual_socket_server()->set_delay_stddev(5);
2095 virtual_socket_server()->UpdateDelayDistribution();
2096
2097 initializing_client()->Negotiate();
2098 ASSERT_TRUE(initializing_client()->data_channel() != nullptr);
2099 EXPECT_TRUE_WAIT(receiving_client()->data_channel() != nullptr, kMaxWaitMs);
2100 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
2101 kMaxWaitMs);
2102 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), kMaxWaitMs);
2103
2104 static constexpr int kNumMessages = 100;
2105 // Deliberately chosen to be larger than the MTU so messages get fragmented.
2106 static constexpr size_t kMaxMessageSize = 4096;
2107 // Create and send random messages.
2108 std::vector<std::string> sent_messages;
2109 for (int i = 0; i < kNumMessages; ++i) {
2110 size_t length = (rand() % kMaxMessageSize) + 1;
2111 std::string message;
2112 ASSERT_TRUE(rtc::CreateRandomString(length, &message));
2113 initializing_client()->data_channel()->Send(DataBuffer(message));
2114 receiving_client()->data_channel()->Send(DataBuffer(message));
2115 sent_messages.push_back(message);
2116 }
2117
2118 EXPECT_EQ_WAIT(
2119 kNumMessages,
2120 initializing_client()->data_observer()->received_message_count(),
2121 kMaxWaitMs);
2122 EXPECT_EQ_WAIT(kNumMessages,
2123 receiving_client()->data_observer()->received_message_count(),
2124 kMaxWaitMs);
2125
2126 // Sort and compare to make sure none of the messages were corrupted.
2127 std::vector<std::string> initializing_client_received_messages =
2128 initializing_client()->data_observer()->messages();
2129 std::vector<std::string> receiving_client_received_messages =
2130 receiving_client()->data_observer()->messages();
2131 std::sort(sent_messages.begin(), sent_messages.end());
2132 std::sort(initializing_client_received_messages.begin(),
2133 initializing_client_received_messages.end());
2134 std::sort(receiving_client_received_messages.begin(),
2135 receiving_client_received_messages.end());
2136 EXPECT_EQ(sent_messages, initializing_client_received_messages);
2137 EXPECT_EQ(sent_messages, receiving_client_received_messages);
2138
2139 receiving_client()->data_channel()->Close();
2140 EXPECT_TRUE_WAIT(!initializing_client()->data_observer()->IsOpen(),
2141 kMaxWaitMs);
2142 EXPECT_TRUE_WAIT(!receiving_client()->data_observer()->IsOpen(), kMaxWaitMs);
2143}
2144
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145// This test sets up a call between two parties and creates a data channel.
2146// The test tests that received data is buffered unless an observer has been
2147// registered.
2148// Rtp data channels can receive data before the underlying
2149// transport has detected that a channel is writable and thus data can be
2150// received before the data channel state changes to open. That is hard to test
2151// but the same buffering is used in that case.
deadbeef7c73bdb2015-12-10 15:10:44 -08002152TEST_F(P2PTestConductor, RegisterDataChannelObserver) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 FakeConstraints setup_constraints;
2154 setup_constraints.SetAllowRtpDataChannels();
2155 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
2156 initializing_client()->CreateDataChannel();
2157 initializing_client()->Negotiate();
2158
deadbeefaf1b59c2015-10-15 12:08:41 -07002159 ASSERT_TRUE(initializing_client()->data_channel() != nullptr);
2160 ASSERT_TRUE(receiving_client()->data_channel() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
2162 kMaxWaitMs);
2163 EXPECT_EQ_WAIT(DataChannelInterface::kOpen,
2164 receiving_client()->data_channel()->state(), kMaxWaitMs);
2165
2166 // Unregister the existing observer.
2167 receiving_client()->data_channel()->UnregisterObserver();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00002168
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169 std::string data = "hello world";
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00002170 SendRtpData(initializing_client()->data_channel(), data);
2171
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002172 // Wait a while to allow the sent data to arrive before an observer is
2173 // registered..
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002174 rtc::Thread::Current()->ProcessMessages(100);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175
2176 MockDataChannelObserver new_observer(receiving_client()->data_channel());
2177 EXPECT_EQ_WAIT(data, new_observer.last_message(), kMaxWaitMs);
2178}
2179
2180// This test sets up a call between two parties with audio, video and but only
2181// the initiating client support data.
deadbeef7c73bdb2015-12-10 15:10:44 -08002182TEST_F(P2PTestConductor, LocalP2PTestReceiverDoesntSupportData) {
buildbot@webrtc.org61c1b8e2014-04-09 06:06:38 +00002183 FakeConstraints setup_constraints_1;
2184 setup_constraints_1.SetAllowRtpDataChannels();
2185 // Must disable DTLS to make negotiation succeed.
2186 setup_constraints_1.SetMandatory(
2187 MediaConstraintsInterface::kEnableDtlsSrtp, false);
2188 FakeConstraints setup_constraints_2;
2189 setup_constraints_2.SetMandatory(
2190 MediaConstraintsInterface::kEnableDtlsSrtp, false);
2191 ASSERT_TRUE(CreateTestClients(&setup_constraints_1, &setup_constraints_2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002192 initializing_client()->CreateDataChannel();
2193 LocalP2PTest();
deadbeefaf1b59c2015-10-15 12:08:41 -07002194 EXPECT_TRUE(initializing_client()->data_channel() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002195 EXPECT_FALSE(receiving_client()->data_channel());
2196 EXPECT_FALSE(initializing_client()->data_observer()->IsOpen());
2197}
2198
2199// This test sets up a call between two parties with audio, video. When audio
2200// and video is setup and flowing and data channel is negotiated.
deadbeef7c73bdb2015-12-10 15:10:44 -08002201TEST_F(P2PTestConductor, AddDataChannelAfterRenegotiation) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002202 FakeConstraints setup_constraints;
2203 setup_constraints.SetAllowRtpDataChannels();
2204 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
2205 LocalP2PTest();
2206 initializing_client()->CreateDataChannel();
2207 // Send new offer and answer.
2208 initializing_client()->Negotiate();
deadbeefaf1b59c2015-10-15 12:08:41 -07002209 ASSERT_TRUE(initializing_client()->data_channel() != nullptr);
2210 ASSERT_TRUE(receiving_client()->data_channel() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
2212 kMaxWaitMs);
2213 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(),
2214 kMaxWaitMs);
2215}
2216
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002217// This test sets up a Jsep call with SCTP DataChannel and verifies the
2218// negotiation is completed without error.
2219#ifdef HAVE_SCTP
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002220TEST_F(P2PTestConductor, CreateOfferWithSctpDataChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002221 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00002222 FakeConstraints constraints;
2223 constraints.SetMandatory(
2224 MediaConstraintsInterface::kEnableDtlsSrtp, true);
2225 ASSERT_TRUE(CreateTestClients(&constraints, &constraints));
2226 initializing_client()->CreateDataChannel();
2227 initializing_client()->Negotiate(false, false);
2228}
2229#endif
2230
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231// This test sets up a call between two parties with audio, and video.
2232// During the call, the initializing side restart ice and the test verifies that
2233// new ice candidates are generated and audio and video still can flow.
deadbeef7c73bdb2015-12-10 15:10:44 -08002234TEST_F(P2PTestConductor, IceRestart) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235 ASSERT_TRUE(CreateTestClients());
2236
2237 // Negotiate and wait for ice completion and make sure audio and video plays.
2238 LocalP2PTest();
2239
2240 // Create a SDP string of the first audio candidate for both clients.
2241 const webrtc::IceCandidateCollection* audio_candidates_initiator =
2242 initializing_client()->pc()->local_description()->candidates(0);
2243 const webrtc::IceCandidateCollection* audio_candidates_receiver =
2244 receiving_client()->pc()->local_description()->candidates(0);
2245 ASSERT_GT(audio_candidates_initiator->count(), 0u);
2246 ASSERT_GT(audio_candidates_receiver->count(), 0u);
2247 std::string initiator_candidate;
2248 EXPECT_TRUE(
2249 audio_candidates_initiator->at(0)->ToString(&initiator_candidate));
2250 std::string receiver_candidate;
2251 EXPECT_TRUE(audio_candidates_receiver->at(0)->ToString(&receiver_candidate));
2252
2253 // Restart ice on the initializing client.
2254 receiving_client()->SetExpectIceRestart(true);
2255 initializing_client()->IceRestart();
2256
2257 // Negotiate and wait for ice completion again and make sure audio and video
2258 // plays.
2259 LocalP2PTest();
2260
2261 // Create a SDP string of the first audio candidate for both clients again.
2262 const webrtc::IceCandidateCollection* audio_candidates_initiator_restart =
2263 initializing_client()->pc()->local_description()->candidates(0);
2264 const webrtc::IceCandidateCollection* audio_candidates_reciever_restart =
2265 receiving_client()->pc()->local_description()->candidates(0);
2266 ASSERT_GT(audio_candidates_initiator_restart->count(), 0u);
2267 ASSERT_GT(audio_candidates_reciever_restart->count(), 0u);
2268 std::string initiator_candidate_restart;
2269 EXPECT_TRUE(audio_candidates_initiator_restart->at(0)->ToString(
2270 &initiator_candidate_restart));
2271 std::string receiver_candidate_restart;
2272 EXPECT_TRUE(audio_candidates_reciever_restart->at(0)->ToString(
2273 &receiver_candidate_restart));
2274
2275 // Verify that the first candidates in the local session descriptions has
2276 // changed.
2277 EXPECT_NE(initiator_candidate, initiator_candidate_restart);
2278 EXPECT_NE(receiver_candidate, receiver_candidate_restart);
2279}
2280
Honghai Zhang4cedf2b2016-08-31 08:18:11 -07002281TEST_F(P2PTestConductor, IceRenominationDisabled) {
Taylor Brandstettere5835f52016-09-16 15:07:50 -07002282 PeerConnectionInterface::RTCConfiguration config;
2283 config.enable_ice_renomination = false;
2284 ASSERT_TRUE(CreateTestClients(config, config));
Honghai Zhang4cedf2b2016-08-31 08:18:11 -07002285 LocalP2PTest();
2286
2287 initializing_client()->VerifyLocalIceRenomination();
2288 receiving_client()->VerifyLocalIceRenomination();
2289 initializing_client()->VerifyRemoteIceRenomination();
2290 receiving_client()->VerifyRemoteIceRenomination();
2291}
2292
2293TEST_F(P2PTestConductor, IceRenominationEnabled) {
Taylor Brandstettere5835f52016-09-16 15:07:50 -07002294 PeerConnectionInterface::RTCConfiguration config;
2295 config.enable_ice_renomination = true;
2296 ASSERT_TRUE(CreateTestClients(config, config));
Honghai Zhang4cedf2b2016-08-31 08:18:11 -07002297 initializing_client()->SetExpectIceRenomination(true);
2298 initializing_client()->SetExpectRemoteIceRenomination(true);
2299 receiving_client()->SetExpectIceRenomination(true);
2300 receiving_client()->SetExpectRemoteIceRenomination(true);
2301 LocalP2PTest();
2302
2303 initializing_client()->VerifyLocalIceRenomination();
2304 receiving_client()->VerifyLocalIceRenomination();
2305 initializing_client()->VerifyRemoteIceRenomination();
2306 receiving_client()->VerifyRemoteIceRenomination();
2307}
2308
deadbeeffaac4972015-11-12 15:33:07 -08002309// This test sets up a call between two parties with audio, and video.
2310// It then renegotiates setting the video m-line to "port 0", then later
2311// renegotiates again, enabling video.
deadbeef7c73bdb2015-12-10 15:10:44 -08002312TEST_F(P2PTestConductor, LocalP2PTestVideoDisableEnable) {
deadbeeffaac4972015-11-12 15:33:07 -08002313 ASSERT_TRUE(CreateTestClients());
2314
2315 // Do initial negotiation. Will result in video and audio sendonly m-lines.
2316 receiving_client()->set_auto_add_stream(false);
2317 initializing_client()->AddMediaStream(true, true);
2318 initializing_client()->Negotiate();
2319
2320 // Negotiate again, disabling the video m-line (receiving client will
2321 // set port to 0 due to mandatory "OfferToReceiveVideo: false" constraint).
2322 receiving_client()->SetReceiveVideo(false);
2323 initializing_client()->Negotiate();
2324
2325 // Enable video and do negotiation again, making sure video is received
2326 // end-to-end.
2327 receiving_client()->SetReceiveVideo(true);
2328 receiving_client()->AddMediaStream(true, true);
2329 LocalP2PTest();
2330}
2331
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332// This test sets up a Jsep call between two parties with external
2333// VideoDecoderFactory.
stefan@webrtc.orgda790082013-09-17 13:11:38 +00002334// TODO(holmer): Disabled due to sometimes crashing on buildbots.
2335// See issue webrtc/2378.
deadbeef7c73bdb2015-12-10 15:10:44 -08002336TEST_F(P2PTestConductor, DISABLED_LocalP2PTestWithVideoDecoderFactory) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337 ASSERT_TRUE(CreateTestClients());
2338 EnableVideoDecoderFactory();
2339 LocalP2PTest();
2340}
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00002341
deadbeeffac06552015-11-25 11:26:01 -08002342// This tests that if we negotiate after calling CreateSender but before we
2343// have a track, then set a track later, frames from the newly-set track are
2344// received end-to-end.
deadbeef7c73bdb2015-12-10 15:10:44 -08002345TEST_F(P2PTestConductor, EarlyWarmupTest) {
deadbeeffac06552015-11-25 11:26:01 -08002346 ASSERT_TRUE(CreateTestClients());
deadbeefbd7d8f72015-12-18 16:58:44 -08002347 auto audio_sender =
2348 initializing_client()->pc()->CreateSender("audio", "stream_id");
2349 auto video_sender =
2350 initializing_client()->pc()->CreateSender("video", "stream_id");
deadbeeffac06552015-11-25 11:26:01 -08002351 initializing_client()->Negotiate();
2352 // Wait for ICE connection to complete, without any tracks.
2353 // Note that the receiving client WILL (in HandleIncomingOffer) create
2354 // tracks, so it's only the initiator here that's doing early warmup.
2355 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
2356 VerifySessionDescriptions();
2357 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
2358 initializing_client()->ice_connection_state(),
2359 kMaxWaitForFramesMs);
2360 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
2361 receiving_client()->ice_connection_state(),
2362 kMaxWaitForFramesMs);
2363 // Now set the tracks, and expect frames to immediately start flowing.
2364 EXPECT_TRUE(
2365 audio_sender->SetTrack(initializing_client()->CreateLocalAudioTrack("")));
2366 EXPECT_TRUE(
2367 video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack("")));
hta6b4f8392016-03-10 00:24:31 -08002368 EXPECT_TRUE_WAIT(FramesHaveArrived(kEndAudioFrameCount, kEndVideoFrameCount),
deadbeeffac06552015-11-25 11:26:01 -08002369 kMaxWaitForFramesMs);
2370}
2371
zhihuang9763d562016-08-05 11:14:50 -07002372#ifdef HAVE_QUIC
2373// This test sets up a call between two parties using QUIC instead of DTLS for
2374// audio and video, and a QUIC data channel.
2375TEST_F(P2PTestConductor, LocalP2PTestQuicDataChannel) {
Taylor Brandstettere5835f52016-09-16 15:07:50 -07002376 PeerConnectionInterface::RTCConfiguration quic_config;
2377 quic_config.enable_quic = true;
2378 ASSERT_TRUE(CreateTestClients(quic_config, quic_config));
zhihuang9763d562016-08-05 11:14:50 -07002379 webrtc::DataChannelInit init;
2380 init.ordered = false;
2381 init.reliable = true;
2382 init.id = 1;
2383 initializing_client()->CreateDataChannel(&init);
2384 receiving_client()->CreateDataChannel(&init);
2385 LocalP2PTest();
2386 ASSERT_NE(nullptr, initializing_client()->data_channel());
2387 ASSERT_NE(nullptr, receiving_client()->data_channel());
2388 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
2389 kMaxWaitMs);
2390 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), kMaxWaitMs);
2391
2392 std::string data = "hello world";
2393
2394 initializing_client()->data_channel()->Send(DataBuffer(data));
2395 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(),
2396 kMaxWaitMs);
2397
2398 receiving_client()->data_channel()->Send(DataBuffer(data));
2399 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(),
2400 kMaxWaitMs);
2401}
2402
2403// Tests that negotiation of QUIC data channels is completed without error.
2404TEST_F(P2PTestConductor, NegotiateQuicDataChannel) {
Taylor Brandstettere5835f52016-09-16 15:07:50 -07002405 PeerConnectionInterface::RTCConfiguration quic_config;
2406 quic_config.enable_quic = true;
2407 ASSERT_TRUE(CreateTestClients(quic_config, quic_config));
zhihuang9763d562016-08-05 11:14:50 -07002408 FakeConstraints constraints;
2409 constraints.SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true);
2410 ASSERT_TRUE(CreateTestClients(&constraints, &constraints));
2411 webrtc::DataChannelInit init;
2412 init.ordered = false;
2413 init.reliable = true;
2414 init.id = 1;
2415 initializing_client()->CreateDataChannel(&init);
2416 initializing_client()->Negotiate(false, false);
2417}
2418
2419// This test sets up a JSEP call using QUIC. The callee only receives video.
2420TEST_F(P2PTestConductor, LocalP2PTestVideoOnlyWithQuic) {
Taylor Brandstettere5835f52016-09-16 15:07:50 -07002421 PeerConnectionInterface::RTCConfiguration quic_config;
2422 quic_config.enable_quic = true;
2423 ASSERT_TRUE(CreateTestClients(quic_config, quic_config));
zhihuang9763d562016-08-05 11:14:50 -07002424 receiving_client()->SetReceiveAudioVideo(false, true);
2425 LocalP2PTest();
2426}
2427
2428// This test sets up a JSEP call using QUIC. The callee only receives audio.
2429TEST_F(P2PTestConductor, LocalP2PTestAudioOnlyWithQuic) {
Taylor Brandstettere5835f52016-09-16 15:07:50 -07002430 PeerConnectionInterface::RTCConfiguration quic_config;
2431 quic_config.enable_quic = true;
2432 ASSERT_TRUE(CreateTestClients(quic_config, quic_config));
zhihuang9763d562016-08-05 11:14:50 -07002433 receiving_client()->SetReceiveAudioVideo(true, false);
2434 LocalP2PTest();
2435}
2436
2437// This test sets up a JSEP call using QUIC. The callee rejects both audio and
2438// video.
2439TEST_F(P2PTestConductor, LocalP2PTestNoVideoAudioWithQuic) {
Taylor Brandstettere5835f52016-09-16 15:07:50 -07002440 PeerConnectionInterface::RTCConfiguration quic_config;
2441 quic_config.enable_quic = true;
2442 ASSERT_TRUE(CreateTestClients(quic_config, quic_config));
zhihuang9763d562016-08-05 11:14:50 -07002443 receiving_client()->SetReceiveAudioVideo(false, false);
2444 LocalP2PTest();
2445}
2446
2447#endif // HAVE_QUIC
2448
nissed98cf1f2016-04-22 07:27:36 -07002449TEST_F(P2PTestConductor, ForwardVideoOnlyStream) {
2450 ASSERT_TRUE(CreateTestClients());
2451 // One-way stream
2452 receiving_client()->set_auto_add_stream(false);
2453 // Video only, audio forwarding not expected to work.
2454 initializing_client()->AddMediaStream(false, true);
2455 initializing_client()->Negotiate();
2456
2457 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
2458 VerifySessionDescriptions();
2459
2460 ASSERT_TRUE(initializing_client()->can_receive_video());
2461 ASSERT_TRUE(receiving_client()->can_receive_video());
2462
2463 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
2464 initializing_client()->ice_connection_state(),
2465 kMaxWaitForFramesMs);
2466 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
2467 receiving_client()->ice_connection_state(),
2468 kMaxWaitForFramesMs);
2469
2470 ASSERT_TRUE(receiving_client()->remote_streams()->count() == 1);
2471
2472 // Echo the stream back.
2473 receiving_client()->pc()->AddStream(
2474 receiving_client()->remote_streams()->at(0));
2475 receiving_client()->Negotiate();
2476
2477 EXPECT_TRUE_WAIT(
2478 initializing_client()->VideoFramesReceivedCheck(kEndVideoFrameCount),
2479 kMaxWaitForFramesMs);
2480}
2481
Taylor Brandstettere5835f52016-09-16 15:07:50 -07002482// 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.
2495TEST_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
deadbeef0a6c4ca2015-10-06 11:38:28 -07002578class IceServerParsingTest : public testing::Test {
2579 public:
2580 // Convenience for parsing a single URL.
2581 bool ParseUrl(const std::string& url) {
2582 return ParseUrl(url, std::string(), std::string());
2583 }
2584
2585 bool ParseUrl(const std::string& url,
2586 const std::string& username,
2587 const std::string& password) {
2588 PeerConnectionInterface::IceServers servers;
2589 PeerConnectionInterface::IceServer server;
2590 server.urls.push_back(url);
2591 server.username = username;
2592 server.password = password;
2593 servers.push_back(server);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002594 return webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_);
deadbeef0a6c4ca2015-10-06 11:38:28 -07002595 }
2596
2597 protected:
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002598 cricket::ServerAddresses stun_servers_;
2599 std::vector<cricket::RelayServerConfig> turn_servers_;
deadbeef0a6c4ca2015-10-06 11:38:28 -07002600};
2601
2602// Make sure all STUN/TURN prefixes are parsed correctly.
2603TEST_F(IceServerParsingTest, ParseStunPrefixes) {
2604 EXPECT_TRUE(ParseUrl("stun:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002605 EXPECT_EQ(1U, stun_servers_.size());
2606 EXPECT_EQ(0U, turn_servers_.size());
2607 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002608
2609 EXPECT_TRUE(ParseUrl("stuns:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002610 EXPECT_EQ(1U, stun_servers_.size());
2611 EXPECT_EQ(0U, turn_servers_.size());
2612 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002613
2614 EXPECT_TRUE(ParseUrl("turn:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002615 EXPECT_EQ(0U, stun_servers_.size());
2616 EXPECT_EQ(1U, turn_servers_.size());
2617 EXPECT_FALSE(turn_servers_[0].ports[0].secure);
2618 turn_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002619
2620 EXPECT_TRUE(ParseUrl("turns:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002621 EXPECT_EQ(0U, stun_servers_.size());
2622 EXPECT_EQ(1U, turn_servers_.size());
2623 EXPECT_TRUE(turn_servers_[0].ports[0].secure);
2624 turn_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002625
2626 // invalid prefixes
2627 EXPECT_FALSE(ParseUrl("stunn:hostname"));
2628 EXPECT_FALSE(ParseUrl(":hostname"));
2629 EXPECT_FALSE(ParseUrl(":"));
2630 EXPECT_FALSE(ParseUrl(""));
2631}
2632
2633TEST_F(IceServerParsingTest, VerifyDefaults) {
2634 // TURNS defaults
2635 EXPECT_TRUE(ParseUrl("turns:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002636 EXPECT_EQ(1U, turn_servers_.size());
2637 EXPECT_EQ(5349, turn_servers_[0].ports[0].address.port());
2638 EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto);
2639 turn_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002640
2641 // TURN defaults
2642 EXPECT_TRUE(ParseUrl("turn:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002643 EXPECT_EQ(1U, turn_servers_.size());
2644 EXPECT_EQ(3478, turn_servers_[0].ports[0].address.port());
2645 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto);
2646 turn_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002647
2648 // STUN defaults
2649 EXPECT_TRUE(ParseUrl("stun:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002650 EXPECT_EQ(1U, stun_servers_.size());
2651 EXPECT_EQ(3478, stun_servers_.begin()->port());
2652 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002653}
2654
2655// Check that the 6 combinations of IPv4/IPv6/hostname and with/without port
2656// can be parsed correctly.
2657TEST_F(IceServerParsingTest, ParseHostnameAndPort) {
2658 EXPECT_TRUE(ParseUrl("stun:1.2.3.4:1234"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002659 EXPECT_EQ(1U, stun_servers_.size());
2660 EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname());
2661 EXPECT_EQ(1234, stun_servers_.begin()->port());
2662 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002663
2664 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]:4321"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002665 EXPECT_EQ(1U, stun_servers_.size());
2666 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname());
2667 EXPECT_EQ(4321, stun_servers_.begin()->port());
2668 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002669
2670 EXPECT_TRUE(ParseUrl("stun:hostname:9999"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002671 EXPECT_EQ(1U, stun_servers_.size());
2672 EXPECT_EQ("hostname", stun_servers_.begin()->hostname());
2673 EXPECT_EQ(9999, stun_servers_.begin()->port());
2674 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002675
2676 EXPECT_TRUE(ParseUrl("stun:1.2.3.4"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002677 EXPECT_EQ(1U, stun_servers_.size());
2678 EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname());
2679 EXPECT_EQ(3478, stun_servers_.begin()->port());
2680 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002681
2682 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002683 EXPECT_EQ(1U, stun_servers_.size());
2684 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname());
2685 EXPECT_EQ(3478, stun_servers_.begin()->port());
2686 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002687
2688 EXPECT_TRUE(ParseUrl("stun:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002689 EXPECT_EQ(1U, stun_servers_.size());
2690 EXPECT_EQ("hostname", stun_servers_.begin()->hostname());
2691 EXPECT_EQ(3478, stun_servers_.begin()->port());
2692 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002693
2694 // Try some invalid hostname:port strings.
2695 EXPECT_FALSE(ParseUrl("stun:hostname:99a99"));
2696 EXPECT_FALSE(ParseUrl("stun:hostname:-1"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002697 EXPECT_FALSE(ParseUrl("stun:hostname:port:more"));
2698 EXPECT_FALSE(ParseUrl("stun:hostname:port more"));
deadbeef0a6c4ca2015-10-06 11:38:28 -07002699 EXPECT_FALSE(ParseUrl("stun:hostname:"));
2700 EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000"));
2701 EXPECT_FALSE(ParseUrl("stun::5555"));
2702 EXPECT_FALSE(ParseUrl("stun:"));
2703}
2704
2705// Test parsing the "?transport=xxx" part of the URL.
2706TEST_F(IceServerParsingTest, ParseTransport) {
2707 EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002708 EXPECT_EQ(1U, turn_servers_.size());
2709 EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto);
2710 turn_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002711
2712 EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002713 EXPECT_EQ(1U, turn_servers_.size());
2714 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto);
2715 turn_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002716
2717 EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid"));
2718}
2719
2720// Test parsing ICE username contained in URL.
2721TEST_F(IceServerParsingTest, ParseUsername) {
2722 EXPECT_TRUE(ParseUrl("turn:user@hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002723 EXPECT_EQ(1U, turn_servers_.size());
2724 EXPECT_EQ("user", turn_servers_[0].credentials.username);
2725 turn_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002726
2727 EXPECT_FALSE(ParseUrl("turn:@hostname"));
2728 EXPECT_FALSE(ParseUrl("turn:username@"));
2729 EXPECT_FALSE(ParseUrl("turn:@"));
2730 EXPECT_FALSE(ParseUrl("turn:user@name@hostname"));
2731}
2732
2733// Test that username and password from IceServer is copied into the resulting
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002734// RelayServerConfig.
deadbeef0a6c4ca2015-10-06 11:38:28 -07002735TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) {
2736 EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002737 EXPECT_EQ(1U, turn_servers_.size());
2738 EXPECT_EQ("username", turn_servers_[0].credentials.username);
2739 EXPECT_EQ("password", turn_servers_[0].credentials.password);
deadbeef0a6c4ca2015-10-06 11:38:28 -07002740}
2741
2742// Ensure that if a server has multiple URLs, each one is parsed.
2743TEST_F(IceServerParsingTest, ParseMultipleUrls) {
2744 PeerConnectionInterface::IceServers servers;
2745 PeerConnectionInterface::IceServer server;
2746 server.urls.push_back("stun:hostname");
2747 server.urls.push_back("turn:hostname");
2748 servers.push_back(server);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002749 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
2750 EXPECT_EQ(1U, stun_servers_.size());
2751 EXPECT_EQ(1U, turn_servers_.size());
deadbeef0a6c4ca2015-10-06 11:38:28 -07002752}
2753
Taylor Brandstetter893505d2016-01-07 15:12:48 -08002754// Ensure that TURN servers are given unique priorities,
2755// so that their resulting candidates have unique priorities.
2756TEST_F(IceServerParsingTest, TurnServerPrioritiesUnique) {
2757 PeerConnectionInterface::IceServers servers;
2758 PeerConnectionInterface::IceServer server;
2759 server.urls.push_back("turn:hostname");
2760 server.urls.push_back("turn:hostname2");
2761 servers.push_back(server);
2762 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
2763 EXPECT_EQ(2U, turn_servers_.size());
2764 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority);
2765}
2766
kjellander@webrtc.orgd1cfa712013-10-16 16:51:52 +00002767#endif // if !defined(THREAD_SANITIZER)
hta6b4f8392016-03-10 00:24:31 -08002768
2769} // namespace