blob: 18d360692f6cd652bf4b1453f292c74fe24b1588 [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"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000033#include "webrtc/base/gunit.h"
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +000034#include "webrtc/base/physicalsocketserver.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000035#include "webrtc/base/ssladapter.h"
36#include "webrtc/base/sslstreamadapter.h"
37#include "webrtc/base/thread.h"
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +000038#include "webrtc/base/virtualsocketserver.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010039#include "webrtc/media/engine/fakewebrtcvideoengine.h"
Taylor Brandstettera1c30352016-05-13 08:15:11 -070040#include "webrtc/p2p/base/fakeportallocator.h"
kjellanderf4752772016-03-02 05:42:30 -080041#include "webrtc/p2p/base/p2pconstants.h"
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +000042#include "webrtc/p2p/base/sessiondescription.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010043#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044
45#define MAYBE_SKIP_TEST(feature) \
46 if (!(feature())) { \
47 LOG(LS_INFO) << "Feature disabled... skipping"; \
48 return; \
49 }
50
51using cricket::ContentInfo;
52using cricket::FakeWebRtcVideoDecoder;
53using cricket::FakeWebRtcVideoDecoderFactory;
54using cricket::FakeWebRtcVideoEncoder;
55using cricket::FakeWebRtcVideoEncoderFactory;
56using cricket::MediaContentDescription;
57using webrtc::DataBuffer;
58using webrtc::DataChannelInterface;
59using webrtc::DtmfSender;
60using webrtc::DtmfSenderInterface;
61using webrtc::DtmfSenderObserverInterface;
62using webrtc::FakeConstraints;
63using webrtc::MediaConstraintsInterface;
deadbeeffaac4972015-11-12 15:33:07 -080064using webrtc::MediaStreamInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065using webrtc::MediaStreamTrackInterface;
66using webrtc::MockCreateSessionDescriptionObserver;
67using webrtc::MockDataChannelObserver;
68using webrtc::MockSetSessionDescriptionObserver;
69using webrtc::MockStatsObserver;
deadbeeffaac4972015-11-12 15:33:07 -080070using webrtc::ObserverInterface;
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +000071using webrtc::PeerConnectionInterface;
Joachim Bauch04e5b492015-05-29 09:40:39 +020072using webrtc::PeerConnectionFactory;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073using webrtc::SessionDescriptionInterface;
74using webrtc::StreamCollectionInterface;
75
hta6b4f8392016-03-10 00:24:31 -080076namespace {
77
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000078static const int kMaxWaitMs = 10000;
pbos@webrtc.org044bdac2014-06-03 09:40:01 +000079// Disable for TSan v2, see
80// https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
81// This declaration is also #ifdef'd as it causes uninitialized-variable
82// warnings.
83#if !defined(THREAD_SANITIZER)
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084static const int kMaxWaitForStatsMs = 3000;
pbos@webrtc.org044bdac2014-06-03 09:40:01 +000085#endif
deadbeeffac06552015-11-25 11:26:01 -080086static const int kMaxWaitForActivationMs = 5000;
buildbot@webrtc.org3e01e0b2014-05-13 17:54:10 +000087static const int kMaxWaitForFramesMs = 10000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088static const int kEndAudioFrameCount = 3;
89static const int kEndVideoFrameCount = 3;
90
91static const char kStreamLabelBase[] = "stream_label";
92static const char kVideoTrackLabelBase[] = "video_track";
93static const char kAudioTrackLabelBase[] = "audio_track";
94static const char kDataChannelLabel[] = "data_channel";
95
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +000096// Disable for TSan v2, see
97// https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
98// This declaration is also #ifdef'd as it causes unused-variable errors.
99#if !defined(THREAD_SANITIZER)
100// SRTP cipher name negotiated by the tests. This must be updated if the
101// default changes.
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800102static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32;
jbauchcb560652016-08-04 05:20:32 -0700103static const int kDefaultSrtpCryptoSuiteGcm = rtc::SRTP_AEAD_AES_256_GCM;
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000104#endif
105
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106static void RemoveLinesFromSdp(const std::string& line_start,
107 std::string* sdp) {
108 const char kSdpLineEnd[] = "\r\n";
109 size_t ssrc_pos = 0;
110 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) !=
111 std::string::npos) {
112 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos);
113 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd));
114 }
115}
116
hta6b4f8392016-03-10 00:24:31 -0800117bool StreamsHaveAudioTrack(StreamCollectionInterface* streams) {
118 for (size_t idx = 0; idx < streams->count(); idx++) {
119 auto stream = streams->at(idx);
120 if (stream->GetAudioTracks().size() > 0) {
121 return true;
122 }
123 }
124 return false;
125}
126
127bool StreamsHaveVideoTrack(StreamCollectionInterface* streams) {
128 for (size_t idx = 0; idx < streams->count(); idx++) {
129 auto stream = streams->at(idx);
130 if (stream->GetVideoTracks().size() > 0) {
131 return true;
132 }
133 }
134 return false;
135}
136
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137class SignalingMessageReceiver {
138 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139 virtual void ReceiveSdpMessage(const std::string& type,
140 std::string& msg) = 0;
141 virtual void ReceiveIceMessage(const std::string& sdp_mid,
142 int sdp_mline_index,
143 const std::string& msg) = 0;
144
145 protected:
deadbeefaf1b59c2015-10-15 12:08:41 -0700146 SignalingMessageReceiver() {}
147 virtual ~SignalingMessageReceiver() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148};
149
zhihuang184a3fd2016-06-14 11:47:14 -0700150class MockRtpReceiverObserver : public webrtc::RtpReceiverObserverInterface {
151 public:
152 MockRtpReceiverObserver(cricket::MediaType media_type)
153 : expected_media_type_(media_type) {}
154
155 void OnFirstPacketReceived(cricket::MediaType media_type) override {
156 ASSERT_EQ(expected_media_type_, media_type);
157 first_packet_received_ = true;
158 }
159
160 bool first_packet_received() { return first_packet_received_; }
161
162 virtual ~MockRtpReceiverObserver() {}
163
164 private:
165 bool first_packet_received_ = false;
166 cricket::MediaType expected_media_type_;
167};
168
deadbeefaf1b59c2015-10-15 12:08:41 -0700169class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
deadbeeffaac4972015-11-12 15:33:07 -0800170 public SignalingMessageReceiver,
171 public ObserverInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 public:
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800173 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore(
Guo-wei Shieh9c38c2d2015-12-05 09:46:07 -0800174 const std::string& id,
175 const MediaConstraintsInterface* constraints,
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800176 const PeerConnectionFactory::Options* options,
Henrik Boströmd79599d2016-06-01 13:58:50 +0200177 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
perkj8aba9972016-04-10 23:54:34 -0700178 bool prefer_constraint_apis,
danilchape9021a32016-05-17 01:52:02 -0700179 rtc::Thread* network_thread,
perkj8aba9972016-04-10 23:54:34 -0700180 rtc::Thread* worker_thread) {
Guo-wei Shieh86aaa4b2015-12-05 09:55:44 -0800181 PeerConnectionTestClient* client(new PeerConnectionTestClient(id));
Henrik Boströmd79599d2016-06-01 13:58:50 +0200182 if (!client->Init(constraints, options, std::move(cert_generator),
danilchape9021a32016-05-17 01:52:02 -0700183 prefer_constraint_apis, network_thread, worker_thread)) {
Guo-wei Shieh86aaa4b2015-12-05 09:55:44 -0800184 delete client;
185 return nullptr;
186 }
187 return client;
Guo-wei Shieh9c38c2d2015-12-05 09:46:07 -0800188 }
189
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800190 static PeerConnectionTestClient* CreateClient(
191 const std::string& id,
192 const MediaConstraintsInterface* constraints,
perkj8aba9972016-04-10 23:54:34 -0700193 const PeerConnectionFactory::Options* options,
danilchape9021a32016-05-17 01:52:02 -0700194 rtc::Thread* network_thread,
perkj8aba9972016-04-10 23:54:34 -0700195 rtc::Thread* worker_thread) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200196 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
197 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
198 new FakeRTCCertificateGenerator() : nullptr);
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800199
danilchape9021a32016-05-17 01:52:02 -0700200 return CreateClientWithDtlsIdentityStore(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200201 id, constraints, options, std::move(cert_generator), true,
danilchape9021a32016-05-17 01:52:02 -0700202 network_thread, worker_thread);
htaaac2dea2016-03-10 13:35:55 -0800203 }
204
205 static PeerConnectionTestClient* CreateClientPreferNoConstraints(
206 const std::string& id,
perkj8aba9972016-04-10 23:54:34 -0700207 const PeerConnectionFactory::Options* options,
danilchape9021a32016-05-17 01:52:02 -0700208 rtc::Thread* network_thread,
perkj8aba9972016-04-10 23:54:34 -0700209 rtc::Thread* worker_thread) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200210 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
211 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
212 new FakeRTCCertificateGenerator() : nullptr);
htaaac2dea2016-03-10 13:35:55 -0800213
danilchape9021a32016-05-17 01:52:02 -0700214 return CreateClientWithDtlsIdentityStore(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200215 id, nullptr, options, std::move(cert_generator), false,
danilchape9021a32016-05-17 01:52:02 -0700216 network_thread, worker_thread);
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800217 }
218
deadbeefaf1b59c2015-10-15 12:08:41 -0700219 ~PeerConnectionTestClient() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220 }
221
deadbeefaf1b59c2015-10-15 12:08:41 -0700222 void Negotiate() { Negotiate(true, true); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223
deadbeefaf1b59c2015-10-15 12:08:41 -0700224 void Negotiate(bool audio, bool video) {
kwibergd1fe2812016-04-27 06:47:29 -0700225 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700226 ASSERT_TRUE(DoCreateOffer(&offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227
deadbeefaf1b59c2015-10-15 12:08:41 -0700228 if (offer->description()->GetContentByName("audio")) {
229 offer->description()->GetContentByName("audio")->rejected = !audio;
230 }
231 if (offer->description()->GetContentByName("video")) {
232 offer->description()->GetContentByName("video")->rejected = !video;
233 }
234
235 std::string sdp;
236 EXPECT_TRUE(offer->ToString(&sdp));
237 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
238 signaling_message_receiver_->ReceiveSdpMessage(
239 webrtc::SessionDescriptionInterface::kOffer, sdp);
240 }
241
242 // SignalingMessageReceiver callback.
243 void ReceiveSdpMessage(const std::string& type, std::string& msg) override {
244 FilterIncomingSdpMessage(&msg);
245 if (type == webrtc::SessionDescriptionInterface::kOffer) {
246 HandleIncomingOffer(msg);
247 } else {
248 HandleIncomingAnswer(msg);
249 }
250 }
251
252 // SignalingMessageReceiver callback.
253 void ReceiveIceMessage(const std::string& sdp_mid,
254 int sdp_mline_index,
255 const std::string& msg) override {
256 LOG(INFO) << id_ << "ReceiveIceMessage";
kwibergd1fe2812016-04-27 06:47:29 -0700257 std::unique_ptr<webrtc::IceCandidateInterface> candidate(
deadbeefaf1b59c2015-10-15 12:08:41 -0700258 webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, msg, nullptr));
259 EXPECT_TRUE(pc()->AddIceCandidate(candidate.get()));
260 }
261
262 // PeerConnectionObserver callbacks.
263 void OnSignalingChange(
264 webrtc::PeerConnectionInterface::SignalingState new_state) override {
265 EXPECT_EQ(pc()->signaling_state(), new_state);
266 }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700267 void OnAddStream(
268 rtc::scoped_refptr<MediaStreamInterface> media_stream) override {
deadbeeffaac4972015-11-12 15:33:07 -0800269 media_stream->RegisterObserver(this);
deadbeefaf1b59c2015-10-15 12:08:41 -0700270 for (size_t i = 0; i < media_stream->GetVideoTracks().size(); ++i) {
271 const std::string id = media_stream->GetVideoTracks()[i]->id();
272 ASSERT_TRUE(fake_video_renderers_.find(id) ==
273 fake_video_renderers_.end());
deadbeefc9be0072015-12-14 18:27:57 -0800274 fake_video_renderers_[id].reset(new webrtc::FakeVideoTrackRenderer(
275 media_stream->GetVideoTracks()[i]));
deadbeefaf1b59c2015-10-15 12:08:41 -0700276 }
277 }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700278 void OnRemoveStream(
279 rtc::scoped_refptr<MediaStreamInterface> media_stream) override {}
deadbeefaf1b59c2015-10-15 12:08:41 -0700280 void OnRenegotiationNeeded() override {}
281 void OnIceConnectionChange(
282 webrtc::PeerConnectionInterface::IceConnectionState new_state) override {
283 EXPECT_EQ(pc()->ice_connection_state(), new_state);
284 }
285 void OnIceGatheringChange(
286 webrtc::PeerConnectionInterface::IceGatheringState new_state) override {
287 EXPECT_EQ(pc()->ice_gathering_state(), new_state);
288 }
289 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
290 LOG(INFO) << id_ << "OnIceCandidate";
291
292 std::string ice_sdp;
293 EXPECT_TRUE(candidate->ToString(&ice_sdp));
294 if (signaling_message_receiver_ == nullptr) {
295 // Remote party may be deleted.
296 return;
297 }
298 signaling_message_receiver_->ReceiveIceMessage(
299 candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp);
300 }
301
deadbeeffaac4972015-11-12 15:33:07 -0800302 // MediaStreamInterface callback
303 void OnChanged() override {
304 // Track added or removed from MediaStream, so update our renderers.
305 rtc::scoped_refptr<StreamCollectionInterface> remote_streams =
306 pc()->remote_streams();
307 // Remove renderers for tracks that were removed.
308 for (auto it = fake_video_renderers_.begin();
309 it != fake_video_renderers_.end();) {
310 if (remote_streams->FindVideoTrack(it->first) == nullptr) {
deadbeefc9be0072015-12-14 18:27:57 -0800311 auto to_remove = it++;
312 removed_fake_video_renderers_.push_back(std::move(to_remove->second));
313 fake_video_renderers_.erase(to_remove);
deadbeeffaac4972015-11-12 15:33:07 -0800314 } else {
315 ++it;
316 }
317 }
318 // Create renderers for new video tracks.
319 for (size_t stream_index = 0; stream_index < remote_streams->count();
320 ++stream_index) {
321 MediaStreamInterface* remote_stream = remote_streams->at(stream_index);
322 for (size_t track_index = 0;
323 track_index < remote_stream->GetVideoTracks().size();
324 ++track_index) {
325 const std::string id =
326 remote_stream->GetVideoTracks()[track_index]->id();
327 if (fake_video_renderers_.find(id) != fake_video_renderers_.end()) {
328 continue;
329 }
deadbeefc9be0072015-12-14 18:27:57 -0800330 fake_video_renderers_[id].reset(new webrtc::FakeVideoTrackRenderer(
331 remote_stream->GetVideoTracks()[track_index]));
deadbeeffaac4972015-11-12 15:33:07 -0800332 }
333 }
334 }
335
deadbeefaf1b59c2015-10-15 12:08:41 -0700336 void SetVideoConstraints(const webrtc::FakeConstraints& video_constraint) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337 video_constraints_ = video_constraint;
338 }
339
340 void AddMediaStream(bool audio, bool video) {
deadbeefaf1b59c2015-10-15 12:08:41 -0700341 std::string stream_label =
342 kStreamLabelBase +
343 rtc::ToString<int>(static_cast<int>(pc()->local_streams()->count()));
deadbeeffaac4972015-11-12 15:33:07 -0800344 rtc::scoped_refptr<MediaStreamInterface> stream =
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000345 peer_connection_factory_->CreateLocalMediaStream(stream_label);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346
347 if (audio && can_receive_audio()) {
deadbeeffac06552015-11-25 11:26:01 -0800348 stream->AddTrack(CreateLocalAudioTrack(stream_label));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 }
350 if (video && can_receive_video()) {
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000351 stream->AddTrack(CreateLocalVideoTrack(stream_label));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 }
353
deadbeefaf1b59c2015-10-15 12:08:41 -0700354 EXPECT_TRUE(pc()->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 }
356
deadbeefaf1b59c2015-10-15 12:08:41 -0700357 size_t NumberOfLocalMediaStreams() { return pc()->local_streams()->count(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358
359 bool SessionActive() {
deadbeefaf1b59c2015-10-15 12:08:41 -0700360 return pc()->signaling_state() == webrtc::PeerConnectionInterface::kStable;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361 }
362
deadbeeffaac4972015-11-12 15:33:07 -0800363 // Automatically add a stream when receiving an offer, if we don't have one.
364 // Defaults to true.
365 void set_auto_add_stream(bool auto_add_stream) {
366 auto_add_stream_ = auto_add_stream;
367 }
368
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 void set_signaling_message_receiver(
deadbeefaf1b59c2015-10-15 12:08:41 -0700370 SignalingMessageReceiver* signaling_message_receiver) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371 signaling_message_receiver_ = signaling_message_receiver;
372 }
373
374 void EnableVideoDecoderFactory() {
375 video_decoder_factory_enabled_ = true;
376 fake_video_decoder_factory_->AddSupportedVideoCodecType(
377 webrtc::kVideoCodecVP8);
378 }
379
deadbeefaf1b59c2015-10-15 12:08:41 -0700380 void IceRestart() {
htaaac2dea2016-03-10 13:35:55 -0800381 offer_answer_constraints_.SetMandatoryIceRestart(true);
382 offer_answer_options_.ice_restart = true;
deadbeefaf1b59c2015-10-15 12:08:41 -0700383 SetExpectIceRestart(true);
384 }
385
386 void SetExpectIceRestart(bool expect_restart) {
387 expect_ice_restart_ = expect_restart;
388 }
389
390 bool ExpectIceRestart() const { return expect_ice_restart_; }
391
392 void SetReceiveAudioVideo(bool audio, bool video) {
393 SetReceiveAudio(audio);
394 SetReceiveVideo(video);
395 ASSERT_EQ(audio, can_receive_audio());
396 ASSERT_EQ(video, can_receive_video());
397 }
398
399 void SetReceiveAudio(bool audio) {
400 if (audio && can_receive_audio())
401 return;
htaaac2dea2016-03-10 13:35:55 -0800402 offer_answer_constraints_.SetMandatoryReceiveAudio(audio);
403 offer_answer_options_.offer_to_receive_audio = audio ? 1 : 0;
deadbeefaf1b59c2015-10-15 12:08:41 -0700404 }
405
406 void SetReceiveVideo(bool video) {
407 if (video && can_receive_video())
408 return;
htaaac2dea2016-03-10 13:35:55 -0800409 offer_answer_constraints_.SetMandatoryReceiveVideo(video);
410 offer_answer_options_.offer_to_receive_video = video ? 1 : 0;
deadbeefaf1b59c2015-10-15 12:08:41 -0700411 }
412
413 void RemoveMsidFromReceivedSdp(bool remove) { remove_msid_ = remove; }
414
415 void RemoveSdesCryptoFromReceivedSdp(bool remove) { remove_sdes_ = remove; }
416
417 void RemoveBundleFromReceivedSdp(bool remove) { remove_bundle_ = remove; }
418
perkjcaafdba2016-03-20 07:34:29 -0700419 void RemoveCvoFromReceivedSdp(bool remove) { remove_cvo_ = remove; }
420
deadbeefaf1b59c2015-10-15 12:08:41 -0700421 bool can_receive_audio() {
422 bool value;
htaaac2dea2016-03-10 13:35:55 -0800423 if (prefer_constraint_apis_) {
424 if (webrtc::FindConstraint(
425 &offer_answer_constraints_,
426 MediaConstraintsInterface::kOfferToReceiveAudio, &value,
427 nullptr)) {
428 return value;
429 }
430 return true;
deadbeefaf1b59c2015-10-15 12:08:41 -0700431 }
htaaac2dea2016-03-10 13:35:55 -0800432 return offer_answer_options_.offer_to_receive_audio > 0 ||
433 offer_answer_options_.offer_to_receive_audio ==
434 PeerConnectionInterface::RTCOfferAnswerOptions::kUndefined;
deadbeefaf1b59c2015-10-15 12:08:41 -0700435 }
436
437 bool can_receive_video() {
438 bool value;
htaaac2dea2016-03-10 13:35:55 -0800439 if (prefer_constraint_apis_) {
440 if (webrtc::FindConstraint(
441 &offer_answer_constraints_,
442 MediaConstraintsInterface::kOfferToReceiveVideo, &value,
443 nullptr)) {
444 return value;
445 }
446 return true;
deadbeefaf1b59c2015-10-15 12:08:41 -0700447 }
htaaac2dea2016-03-10 13:35:55 -0800448 return offer_answer_options_.offer_to_receive_video > 0 ||
449 offer_answer_options_.offer_to_receive_video ==
450 PeerConnectionInterface::RTCOfferAnswerOptions::kUndefined;
deadbeefaf1b59c2015-10-15 12:08:41 -0700451 }
452
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700453 void OnDataChannel(
454 rtc::scoped_refptr<DataChannelInterface> data_channel) override {
deadbeefaf1b59c2015-10-15 12:08:41 -0700455 LOG(INFO) << id_ << "OnDataChannel";
456 data_channel_ = data_channel;
457 data_observer_.reset(new MockDataChannelObserver(data_channel));
458 }
459
460 void CreateDataChannel() {
461 data_channel_ = pc()->CreateDataChannel(kDataChannelLabel, nullptr);
462 ASSERT_TRUE(data_channel_.get() != nullptr);
463 data_observer_.reset(new MockDataChannelObserver(data_channel_));
464 }
465
deadbeeffac06552015-11-25 11:26:01 -0800466 rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack(
467 const std::string& stream_label) {
468 FakeConstraints constraints;
469 // Disable highpass filter so that we can get all the test audio frames.
470 constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false);
471 rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
472 peer_connection_factory_->CreateAudioSource(&constraints);
473 // TODO(perkj): Test audio source when it is implemented. Currently audio
474 // always use the default input.
475 std::string label = stream_label + kAudioTrackLabelBase;
476 return peer_connection_factory_->CreateAudioTrack(label, source);
477 }
478
479 rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack(
480 const std::string& stream_label) {
481 // Set max frame rate to 10fps to reduce the risk of the tests to be flaky.
482 FakeConstraints source_constraints = video_constraints_;
483 source_constraints.SetMandatoryMaxFrameRate(10);
484
485 cricket::FakeVideoCapturer* fake_capturer =
486 new webrtc::FakePeriodicVideoCapturer();
perkjcaafdba2016-03-20 07:34:29 -0700487 fake_capturer->SetRotation(capture_rotation_);
deadbeeffac06552015-11-25 11:26:01 -0800488 video_capturers_.push_back(fake_capturer);
perkja3ede6c2016-03-08 01:27:48 +0100489 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
deadbeeffac06552015-11-25 11:26:01 -0800490 peer_connection_factory_->CreateVideoSource(fake_capturer,
491 &source_constraints);
492 std::string label = stream_label + kVideoTrackLabelBase;
perkjcaafdba2016-03-20 07:34:29 -0700493
494 rtc::scoped_refptr<webrtc::VideoTrackInterface> track(
495 peer_connection_factory_->CreateVideoTrack(label, source));
496 if (!local_video_renderer_) {
497 local_video_renderer_.reset(new webrtc::FakeVideoTrackRenderer(track));
498 }
499 return track;
deadbeeffac06552015-11-25 11:26:01 -0800500 }
501
deadbeefaf1b59c2015-10-15 12:08:41 -0700502 DataChannelInterface* data_channel() { return data_channel_; }
503 const MockDataChannelObserver* data_observer() const {
504 return data_observer_.get();
505 }
506
hta6b4f8392016-03-10 00:24:31 -0800507 webrtc::PeerConnectionInterface* pc() const { return peer_connection_.get(); }
deadbeefaf1b59c2015-10-15 12:08:41 -0700508
509 void StopVideoCapturers() {
perkjcaafdba2016-03-20 07:34:29 -0700510 for (auto* capturer : video_capturers_) {
511 capturer->Stop();
deadbeefaf1b59c2015-10-15 12:08:41 -0700512 }
513 }
514
perkjcaafdba2016-03-20 07:34:29 -0700515 void SetCaptureRotation(webrtc::VideoRotation rotation) {
516 ASSERT_TRUE(video_capturers_.empty());
517 capture_rotation_ = rotation;
518 }
519
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000520 bool AudioFramesReceivedCheck(int number_of_frames) const {
521 return number_of_frames <= fake_audio_capture_module_->frames_received();
522 }
523
deadbeefc9be0072015-12-14 18:27:57 -0800524 int audio_frames_received() const {
525 return fake_audio_capture_module_->frames_received();
526 }
527
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000528 bool VideoFramesReceivedCheck(int number_of_frames) {
529 if (video_decoder_factory_enabled_) {
530 const std::vector<FakeWebRtcVideoDecoder*>& decoders
531 = fake_video_decoder_factory_->decoders();
532 if (decoders.empty()) {
533 return number_of_frames <= 0;
534 }
hta6b4f8392016-03-10 00:24:31 -0800535 // Note - this checks that EACH decoder has the requisite number
536 // of frames. The video_frames_received() function sums them.
deadbeefc9be0072015-12-14 18:27:57 -0800537 for (FakeWebRtcVideoDecoder* decoder : decoders) {
538 if (number_of_frames > decoder->GetNumFramesReceived()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 return false;
540 }
541 }
542 return true;
543 } else {
544 if (fake_video_renderers_.empty()) {
545 return number_of_frames <= 0;
546 }
547
deadbeefc9be0072015-12-14 18:27:57 -0800548 for (const auto& pair : fake_video_renderers_) {
549 if (number_of_frames > pair.second->num_rendered_frames()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 return false;
551 }
552 }
553 return true;
554 }
555 }
deadbeefaf1b59c2015-10-15 12:08:41 -0700556
deadbeefc9be0072015-12-14 18:27:57 -0800557 int video_frames_received() const {
558 int total = 0;
559 if (video_decoder_factory_enabled_) {
560 const std::vector<FakeWebRtcVideoDecoder*>& decoders =
561 fake_video_decoder_factory_->decoders();
562 for (const FakeWebRtcVideoDecoder* decoder : decoders) {
563 total += decoder->GetNumFramesReceived();
564 }
565 } else {
566 for (const auto& pair : fake_video_renderers_) {
567 total += pair.second->num_rendered_frames();
568 }
569 for (const auto& renderer : removed_fake_video_renderers_) {
570 total += renderer->num_rendered_frames();
571 }
572 }
573 return total;
574 }
575
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576 // Verify the CreateDtmfSender interface
577 void VerifyDtmf() {
kwibergd1fe2812016-04-27 06:47:29 -0700578 std::unique_ptr<DummyDtmfObserver> observer(new DummyDtmfObserver());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000579 rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580
581 // We can't create a DTMF sender with an invalid audio track or a non local
582 // track.
deadbeefaf1b59c2015-10-15 12:08:41 -0700583 EXPECT_TRUE(peer_connection_->CreateDtmfSender(nullptr) == nullptr);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000584 rtc::scoped_refptr<webrtc::AudioTrackInterface> non_localtrack(
deadbeefaf1b59c2015-10-15 12:08:41 -0700585 peer_connection_factory_->CreateAudioTrack("dummy_track", nullptr));
586 EXPECT_TRUE(peer_connection_->CreateDtmfSender(non_localtrack) == nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000587
588 // We should be able to create a DTMF sender from a local track.
589 webrtc::AudioTrackInterface* localtrack =
590 peer_connection_->local_streams()->at(0)->GetAudioTracks()[0];
591 dtmf_sender = peer_connection_->CreateDtmfSender(localtrack);
deadbeefaf1b59c2015-10-15 12:08:41 -0700592 EXPECT_TRUE(dtmf_sender.get() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 dtmf_sender->RegisterObserver(observer.get());
594
595 // Test the DtmfSender object just created.
596 EXPECT_TRUE(dtmf_sender->CanInsertDtmf());
597 EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50));
598
599 // We don't need to verify that the DTMF tones are actually sent out because
600 // that is already covered by the tests of the lower level components.
601
602 EXPECT_TRUE_WAIT(observer->completed(), kMaxWaitMs);
603 std::vector<std::string> tones;
604 tones.push_back("1");
605 tones.push_back("a");
606 tones.push_back("");
607 observer->Verify(tones);
608
609 dtmf_sender->UnregisterObserver();
610 }
611
612 // Verifies that the SessionDescription have rejected the appropriate media
613 // content.
614 void VerifyRejectedMediaInSessionDescription() {
deadbeefaf1b59c2015-10-15 12:08:41 -0700615 ASSERT_TRUE(peer_connection_->remote_description() != nullptr);
616 ASSERT_TRUE(peer_connection_->local_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000617 const cricket::SessionDescription* remote_desc =
618 peer_connection_->remote_description()->description();
619 const cricket::SessionDescription* local_desc =
620 peer_connection_->local_description()->description();
621
622 const ContentInfo* remote_audio_content = GetFirstAudioContent(remote_desc);
623 if (remote_audio_content) {
624 const ContentInfo* audio_content =
625 GetFirstAudioContent(local_desc);
626 EXPECT_EQ(can_receive_audio(), !audio_content->rejected);
627 }
628
629 const ContentInfo* remote_video_content = GetFirstVideoContent(remote_desc);
630 if (remote_video_content) {
631 const ContentInfo* video_content =
632 GetFirstVideoContent(local_desc);
633 EXPECT_EQ(can_receive_video(), !video_content->rejected);
634 }
635 }
636
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000637 void VerifyLocalIceUfragAndPassword() {
deadbeefaf1b59c2015-10-15 12:08:41 -0700638 ASSERT_TRUE(peer_connection_->local_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000639 const cricket::SessionDescription* desc =
640 peer_connection_->local_description()->description();
641 const cricket::ContentInfos& contents = desc->contents();
642
643 for (size_t index = 0; index < contents.size(); ++index) {
644 if (contents[index].rejected)
645 continue;
646 const cricket::TransportDescription* transport_desc =
647 desc->GetTransportDescriptionByName(contents[index].name);
648
649 std::map<int, IceUfragPwdPair>::const_iterator ufragpair_it =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000650 ice_ufrag_pwd_.find(static_cast<int>(index));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000651 if (ufragpair_it == ice_ufrag_pwd_.end()) {
652 ASSERT_FALSE(ExpectIceRestart());
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000653 ice_ufrag_pwd_[static_cast<int>(index)] =
654 IceUfragPwdPair(transport_desc->ice_ufrag, transport_desc->ice_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655 } else if (ExpectIceRestart()) {
656 const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second;
657 EXPECT_NE(ufrag_pwd.first, transport_desc->ice_ufrag);
658 EXPECT_NE(ufrag_pwd.second, transport_desc->ice_pwd);
659 } else {
660 const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second;
661 EXPECT_EQ(ufrag_pwd.first, transport_desc->ice_ufrag);
662 EXPECT_EQ(ufrag_pwd.second, transport_desc->ice_pwd);
663 }
664 }
665 }
666
667 int GetAudioOutputLevelStats(webrtc::MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000668 rtc::scoped_refptr<MockStatsObserver>
669 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000670 EXPECT_TRUE(peer_connection_->GetStats(
671 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000672 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700673 EXPECT_NE(0, observer->timestamp());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000674 return observer->AudioOutputLevel();
675 }
676
677 int GetAudioInputLevelStats() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000678 rtc::scoped_refptr<MockStatsObserver>
679 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000680 EXPECT_TRUE(peer_connection_->GetStats(
deadbeefaf1b59c2015-10-15 12:08:41 -0700681 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000682 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700683 EXPECT_NE(0, observer->timestamp());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000684 return observer->AudioInputLevel();
685 }
686
687 int GetBytesReceivedStats(webrtc::MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000688 rtc::scoped_refptr<MockStatsObserver>
689 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000690 EXPECT_TRUE(peer_connection_->GetStats(
691 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700693 EXPECT_NE(0, observer->timestamp());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 return observer->BytesReceived();
695 }
696
697 int GetBytesSentStats(webrtc::MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000698 rtc::scoped_refptr<MockStatsObserver>
699 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000700 EXPECT_TRUE(peer_connection_->GetStats(
701 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700703 EXPECT_NE(0, observer->timestamp());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 return observer->BytesSent();
705 }
706
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000707 int GetAvailableReceivedBandwidthStats() {
708 rtc::scoped_refptr<MockStatsObserver>
709 observer(new rtc::RefCountedObject<MockStatsObserver>());
710 EXPECT_TRUE(peer_connection_->GetStats(
deadbeefaf1b59c2015-10-15 12:08:41 -0700711 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard));
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000712 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700713 EXPECT_NE(0, observer->timestamp());
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000714 int bw = observer->AvailableReceiveBandwidth();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000715 return bw;
716 }
717
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000718 std::string GetDtlsCipherStats() {
719 rtc::scoped_refptr<MockStatsObserver>
720 observer(new rtc::RefCountedObject<MockStatsObserver>());
721 EXPECT_TRUE(peer_connection_->GetStats(
deadbeefaf1b59c2015-10-15 12:08:41 -0700722 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard));
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000723 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700724 EXPECT_NE(0, observer->timestamp());
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000725 return observer->DtlsCipher();
726 }
727
728 std::string GetSrtpCipherStats() {
729 rtc::scoped_refptr<MockStatsObserver>
730 observer(new rtc::RefCountedObject<MockStatsObserver>());
731 EXPECT_TRUE(peer_connection_->GetStats(
deadbeefaf1b59c2015-10-15 12:08:41 -0700732 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard));
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000733 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700734 EXPECT_NE(0, observer->timestamp());
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000735 return observer->SrtpCipher();
736 }
737
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738 int rendered_width() {
739 EXPECT_FALSE(fake_video_renderers_.empty());
740 return fake_video_renderers_.empty() ? 1 :
741 fake_video_renderers_.begin()->second->width();
742 }
743
744 int rendered_height() {
745 EXPECT_FALSE(fake_video_renderers_.empty());
746 return fake_video_renderers_.empty() ? 1 :
747 fake_video_renderers_.begin()->second->height();
748 }
749
perkjcaafdba2016-03-20 07:34:29 -0700750 webrtc::VideoRotation rendered_rotation() {
751 EXPECT_FALSE(fake_video_renderers_.empty());
752 return fake_video_renderers_.empty()
753 ? webrtc::kVideoRotation_0
754 : fake_video_renderers_.begin()->second->rotation();
755 }
756
757 int local_rendered_width() {
758 return local_video_renderer_ ? local_video_renderer_->width() : 1;
759 }
760
761 int local_rendered_height() {
762 return local_video_renderer_ ? local_video_renderer_->height() : 1;
763 }
764
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765 size_t number_of_remote_streams() {
766 if (!pc())
767 return 0;
768 return pc()->remote_streams()->count();
769 }
770
hta6b4f8392016-03-10 00:24:31 -0800771 StreamCollectionInterface* remote_streams() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772 if (!pc()) {
773 ADD_FAILURE();
deadbeefaf1b59c2015-10-15 12:08:41 -0700774 return nullptr;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775 }
776 return pc()->remote_streams();
777 }
778
779 StreamCollectionInterface* local_streams() {
780 if (!pc()) {
781 ADD_FAILURE();
deadbeefaf1b59c2015-10-15 12:08:41 -0700782 return nullptr;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 }
784 return pc()->local_streams();
785 }
786
hta6b4f8392016-03-10 00:24:31 -0800787 bool HasLocalAudioTrack() { return StreamsHaveAudioTrack(local_streams()); }
788
789 bool HasLocalVideoTrack() { return StreamsHaveVideoTrack(local_streams()); }
790
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 webrtc::PeerConnectionInterface::SignalingState signaling_state() {
792 return pc()->signaling_state();
793 }
794
795 webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() {
796 return pc()->ice_connection_state();
797 }
798
799 webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() {
800 return pc()->ice_gathering_state();
801 }
802
zhihuang184a3fd2016-06-14 11:47:14 -0700803 std::vector<std::unique_ptr<MockRtpReceiverObserver>> const&
804 rtp_receiver_observers() {
805 return rtp_receiver_observers_;
806 }
807
808 void SetRtpReceiverObservers() {
809 rtp_receiver_observers_.clear();
810 for (auto receiver : pc()->GetReceivers()) {
811 std::unique_ptr<MockRtpReceiverObserver> observer(
812 new MockRtpReceiverObserver(receiver->media_type()));
813 receiver->SetObserver(observer.get());
814 rtp_receiver_observers_.push_back(std::move(observer));
815 }
816 }
817
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 private:
819 class DummyDtmfObserver : public DtmfSenderObserverInterface {
820 public:
821 DummyDtmfObserver() : completed_(false) {}
822
823 // Implements DtmfSenderObserverInterface.
deadbeefaf1b59c2015-10-15 12:08:41 -0700824 void OnToneChange(const std::string& tone) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 tones_.push_back(tone);
826 if (tone.empty()) {
827 completed_ = true;
828 }
829 }
830
831 void Verify(const std::vector<std::string>& tones) const {
832 ASSERT_TRUE(tones_.size() == tones.size());
833 EXPECT_TRUE(std::equal(tones.begin(), tones.end(), tones_.begin()));
834 }
835
836 bool completed() const { return completed_; }
837
838 private:
839 bool completed_;
840 std::vector<std::string> tones_;
841 };
842
deadbeefaf1b59c2015-10-15 12:08:41 -0700843 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {}
844
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800845 bool Init(
846 const MediaConstraintsInterface* constraints,
847 const PeerConnectionFactory::Options* options,
Henrik Boströmd79599d2016-06-01 13:58:50 +0200848 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
perkj8aba9972016-04-10 23:54:34 -0700849 bool prefer_constraint_apis,
danilchape9021a32016-05-17 01:52:02 -0700850 rtc::Thread* network_thread,
perkj8aba9972016-04-10 23:54:34 -0700851 rtc::Thread* worker_thread) {
deadbeefaf1b59c2015-10-15 12:08:41 -0700852 EXPECT_TRUE(!peer_connection_);
853 EXPECT_TRUE(!peer_connection_factory_);
htaaac2dea2016-03-10 13:35:55 -0800854 if (!prefer_constraint_apis) {
855 EXPECT_TRUE(!constraints);
856 }
857 prefer_constraint_apis_ = prefer_constraint_apis;
858
kwibergd1fe2812016-04-27 06:47:29 -0700859 std::unique_ptr<cricket::PortAllocator> port_allocator(
danilchape9021a32016-05-17 01:52:02 -0700860 new cricket::FakePortAllocator(network_thread, nullptr));
deadbeefaf1b59c2015-10-15 12:08:41 -0700861 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
862
863 if (fake_audio_capture_module_ == nullptr) {
864 return false;
865 }
866 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory();
867 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory();
danilchape9021a32016-05-17 01:52:02 -0700868 rtc::Thread* const signaling_thread = rtc::Thread::Current();
deadbeefaf1b59c2015-10-15 12:08:41 -0700869 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700870 network_thread, worker_thread, signaling_thread,
871 fake_audio_capture_module_, fake_video_encoder_factory_,
872 fake_video_decoder_factory_);
deadbeefaf1b59c2015-10-15 12:08:41 -0700873 if (!peer_connection_factory_) {
874 return false;
875 }
876 if (options) {
877 peer_connection_factory_->SetOptions(*options);
878 }
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800879 peer_connection_ = CreatePeerConnection(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200880 std::move(port_allocator), constraints, std::move(cert_generator));
deadbeefaf1b59c2015-10-15 12:08:41 -0700881 return peer_connection_.get() != nullptr;
882 }
883
deadbeefaf1b59c2015-10-15 12:08:41 -0700884 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(
kwibergd1fe2812016-04-27 06:47:29 -0700885 std::unique_ptr<cricket::PortAllocator> port_allocator,
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800886 const MediaConstraintsInterface* constraints,
Henrik Boströmd79599d2016-06-01 13:58:50 +0200887 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800888 // CreatePeerConnection with RTCConfiguration.
889 webrtc::PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 webrtc::PeerConnectionInterface::IceServer ice_server;
891 ice_server.uri = "stun:stun.l.google.com:19302";
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800892 config.servers.push_back(ice_server);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000893
Henrik Boströmd79599d2016-06-01 13:58:50 +0200894 return peer_connection_factory_->CreatePeerConnection(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800895 config, constraints, std::move(port_allocator),
Henrik Boströmd79599d2016-06-01 13:58:50 +0200896 std::move(cert_generator), this);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 }
898
899 void HandleIncomingOffer(const std::string& msg) {
deadbeefaf1b59c2015-10-15 12:08:41 -0700900 LOG(INFO) << id_ << "HandleIncomingOffer ";
deadbeeffaac4972015-11-12 15:33:07 -0800901 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 // If we are not sending any streams ourselves it is time to add some.
903 AddMediaStream(true, true);
904 }
kwibergd1fe2812016-04-27 06:47:29 -0700905 std::unique_ptr<SessionDescriptionInterface> desc(
deadbeefaf1b59c2015-10-15 12:08:41 -0700906 webrtc::CreateSessionDescription("offer", msg, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
zhihuang184a3fd2016-06-14 11:47:14 -0700908 // Set the RtpReceiverObserver after receivers are created.
909 SetRtpReceiverObservers();
kwibergd1fe2812016-04-27 06:47:29 -0700910 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700911 EXPECT_TRUE(DoCreateAnswer(&answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 std::string sdp;
913 EXPECT_TRUE(answer->ToString(&sdp));
914 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
deadbeefaf1b59c2015-10-15 12:08:41 -0700915 if (signaling_message_receiver_) {
916 signaling_message_receiver_->ReceiveSdpMessage(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 webrtc::SessionDescriptionInterface::kAnswer, sdp);
918 }
919 }
920
921 void HandleIncomingAnswer(const std::string& msg) {
deadbeefaf1b59c2015-10-15 12:08:41 -0700922 LOG(INFO) << id_ << "HandleIncomingAnswer";
kwibergd1fe2812016-04-27 06:47:29 -0700923 std::unique_ptr<SessionDescriptionInterface> desc(
deadbeefaf1b59c2015-10-15 12:08:41 -0700924 webrtc::CreateSessionDescription("answer", msg, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
zhihuang184a3fd2016-06-14 11:47:14 -0700926 // Set the RtpReceiverObserver after receivers are created.
927 SetRtpReceiverObservers();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 }
929
kwibergd1fe2812016-04-27 06:47:29 -0700930 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 bool offer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000932 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
933 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 MockCreateSessionDescriptionObserver>());
htaaac2dea2016-03-10 13:35:55 -0800935 if (prefer_constraint_apis_) {
936 if (offer) {
937 pc()->CreateOffer(observer, &offer_answer_constraints_);
938 } else {
939 pc()->CreateAnswer(observer, &offer_answer_constraints_);
940 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 } else {
htaaac2dea2016-03-10 13:35:55 -0800942 if (offer) {
943 pc()->CreateOffer(observer, offer_answer_options_);
944 } else {
945 pc()->CreateAnswer(observer, offer_answer_options_);
946 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 }
948 EXPECT_EQ_WAIT(true, observer->called(), kMaxWaitMs);
kwiberg2bbff992016-03-16 11:03:04 -0700949 desc->reset(observer->release_desc());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 if (observer->result() && ExpectIceRestart()) {
951 EXPECT_EQ(0u, (*desc)->candidates(0)->count());
952 }
953 return observer->result();
954 }
955
kwibergd1fe2812016-04-27 06:47:29 -0700956 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 return DoCreateOfferAnswer(desc, true);
958 }
959
kwibergd1fe2812016-04-27 06:47:29 -0700960 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000961 return DoCreateOfferAnswer(desc, false);
962 }
963
964 bool DoSetLocalDescription(SessionDescriptionInterface* desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000965 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
966 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 MockSetSessionDescriptionObserver>());
deadbeefaf1b59c2015-10-15 12:08:41 -0700968 LOG(INFO) << id_ << "SetLocalDescription ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 pc()->SetLocalDescription(observer, desc);
970 // Ignore the observer result. If we wait for the result with
971 // EXPECT_TRUE_WAIT, local ice candidates might be sent to the remote peer
972 // before the offer which is an error.
973 // The reason is that EXPECT_TRUE_WAIT uses
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000974 // rtc::Thread::Current()->ProcessMessages(1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 // ProcessMessages waits at least 1ms but processes all messages before
976 // returning. Since this test is synchronous and send messages to the remote
977 // peer whenever a callback is invoked, this can lead to messages being
978 // sent to the remote peer in the wrong order.
979 // TODO(perkj): Find a way to check the result without risking that the
980 // order of sent messages are changed. Ex- by posting all messages that are
981 // sent to the remote peer.
982 return true;
983 }
984
985 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000986 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
987 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 MockSetSessionDescriptionObserver>());
deadbeefaf1b59c2015-10-15 12:08:41 -0700989 LOG(INFO) << id_ << "SetRemoteDescription ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990 pc()->SetRemoteDescription(observer, desc);
991 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
992 return observer->result();
993 }
994
995 // This modifies all received SDP messages before they are processed.
996 void FilterIncomingSdpMessage(std::string* sdp) {
997 if (remove_msid_) {
998 const char kSdpSsrcAttribute[] = "a=ssrc:";
999 RemoveLinesFromSdp(kSdpSsrcAttribute, sdp);
1000 const char kSdpMsidSupportedAttribute[] = "a=msid-semantic:";
1001 RemoveLinesFromSdp(kSdpMsidSupportedAttribute, sdp);
1002 }
1003 if (remove_bundle_) {
1004 const char kSdpBundleAttribute[] = "a=group:BUNDLE";
1005 RemoveLinesFromSdp(kSdpBundleAttribute, sdp);
1006 }
1007 if (remove_sdes_) {
1008 const char kSdpSdesCryptoAttribute[] = "a=crypto";
1009 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp);
1010 }
perkjcaafdba2016-03-20 07:34:29 -07001011 if (remove_cvo_) {
1012 const char kSdpCvoExtenstion[] = "urn:3gpp:video-orientation";
1013 RemoveLinesFromSdp(kSdpCvoExtenstion, sdp);
1014 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015 }
1016
deadbeefaf1b59c2015-10-15 12:08:41 -07001017 std::string id_;
1018
deadbeefaf1b59c2015-10-15 12:08:41 -07001019 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
1020 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
1021 peer_connection_factory_;
1022
htaaac2dea2016-03-10 13:35:55 -08001023 bool prefer_constraint_apis_ = true;
deadbeeffaac4972015-11-12 15:33:07 -08001024 bool auto_add_stream_ = true;
1025
deadbeefaf1b59c2015-10-15 12:08:41 -07001026 typedef std::pair<std::string, std::string> IceUfragPwdPair;
1027 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_;
1028 bool expect_ice_restart_ = false;
1029
deadbeefc9be0072015-12-14 18:27:57 -08001030 // Needed to keep track of number of frames sent.
deadbeefaf1b59c2015-10-15 12:08:41 -07001031 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
1032 // Needed to keep track of number of frames received.
kwibergd1fe2812016-04-27 06:47:29 -07001033 std::map<std::string, std::unique_ptr<webrtc::FakeVideoTrackRenderer>>
deadbeefc9be0072015-12-14 18:27:57 -08001034 fake_video_renderers_;
1035 // Needed to ensure frames aren't received for removed tracks.
kwibergd1fe2812016-04-27 06:47:29 -07001036 std::vector<std::unique_ptr<webrtc::FakeVideoTrackRenderer>>
deadbeefc9be0072015-12-14 18:27:57 -08001037 removed_fake_video_renderers_;
deadbeefaf1b59c2015-10-15 12:08:41 -07001038 // Needed to keep track of number of frames received when external decoder
1039 // used.
1040 FakeWebRtcVideoDecoderFactory* fake_video_decoder_factory_ = nullptr;
1041 FakeWebRtcVideoEncoderFactory* fake_video_encoder_factory_ = nullptr;
1042 bool video_decoder_factory_enabled_ = false;
1043 webrtc::FakeConstraints video_constraints_;
1044
1045 // For remote peer communication.
1046 SignalingMessageReceiver* signaling_message_receiver_ = nullptr;
1047
1048 // Store references to the video capturers we've created, so that we can stop
1049 // them, if required.
perkjcaafdba2016-03-20 07:34:29 -07001050 std::vector<cricket::FakeVideoCapturer*> video_capturers_;
1051 webrtc::VideoRotation capture_rotation_ = webrtc::kVideoRotation_0;
1052 // |local_video_renderer_| attached to the first created local video track.
kwibergd1fe2812016-04-27 06:47:29 -07001053 std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_;
deadbeefaf1b59c2015-10-15 12:08:41 -07001054
htaaac2dea2016-03-10 13:35:55 -08001055 webrtc::FakeConstraints offer_answer_constraints_;
1056 PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_;
deadbeefaf1b59c2015-10-15 12:08:41 -07001057 bool remove_msid_ = false; // True if MSID should be removed in received SDP.
1058 bool remove_bundle_ =
1059 false; // True if bundle should be removed in received SDP.
1060 bool remove_sdes_ =
1061 false; // True if a=crypto should be removed in received SDP.
perkjcaafdba2016-03-20 07:34:29 -07001062 // |remove_cvo_| is true if extension urn:3gpp:video-orientation should be
1063 // removed in the received SDP.
1064 bool remove_cvo_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001066 rtc::scoped_refptr<DataChannelInterface> data_channel_;
kwibergd1fe2812016-04-27 06:47:29 -07001067 std::unique_ptr<MockDataChannelObserver> data_observer_;
zhihuang184a3fd2016-06-14 11:47:14 -07001068
1069 std::vector<std::unique_ptr<MockRtpReceiverObserver>> rtp_receiver_observers_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070};
1071
deadbeef7c73bdb2015-12-10 15:10:44 -08001072class P2PTestConductor : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073 public:
deadbeef7c73bdb2015-12-10 15:10:44 -08001074 P2PTestConductor()
deadbeefeff5b852016-05-27 14:18:01 -07001075 : pss_(new rtc::PhysicalSocketServer),
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +00001076 ss_(new rtc::VirtualSocketServer(pss_.get())),
deadbeefeff5b852016-05-27 14:18:01 -07001077 network_thread_(new rtc::Thread(ss_.get())),
1078 worker_thread_(rtc::Thread::Create()) {
danilchape9021a32016-05-17 01:52:02 -07001079 RTC_CHECK(network_thread_->Start());
1080 RTC_CHECK(worker_thread_->Start());
perkj8aba9972016-04-10 23:54:34 -07001081 }
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +00001082
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 bool SessionActive() {
1084 return initiating_client_->SessionActive() &&
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +00001085 receiving_client_->SessionActive();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001086 }
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +00001087
hta6b4f8392016-03-10 00:24:31 -08001088 // Return true if the number of frames provided have been received
1089 // on the video and audio tracks provided.
1090 bool FramesHaveArrived(int audio_frames_to_receive,
1091 int video_frames_to_receive) {
1092 bool all_good = true;
1093 if (initiating_client_->HasLocalAudioTrack() &&
1094 receiving_client_->can_receive_audio()) {
1095 all_good &=
1096 receiving_client_->AudioFramesReceivedCheck(audio_frames_to_receive);
1097 }
1098 if (initiating_client_->HasLocalVideoTrack() &&
1099 receiving_client_->can_receive_video()) {
1100 all_good &=
1101 receiving_client_->VideoFramesReceivedCheck(video_frames_to_receive);
1102 }
1103 if (receiving_client_->HasLocalAudioTrack() &&
1104 initiating_client_->can_receive_audio()) {
1105 all_good &=
1106 initiating_client_->AudioFramesReceivedCheck(audio_frames_to_receive);
1107 }
1108 if (receiving_client_->HasLocalVideoTrack() &&
1109 initiating_client_->can_receive_video()) {
1110 all_good &=
1111 initiating_client_->VideoFramesReceivedCheck(video_frames_to_receive);
1112 }
1113 return all_good;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001114 }
hta6b4f8392016-03-10 00:24:31 -08001115
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001116 void VerifyDtmf() {
1117 initiating_client_->VerifyDtmf();
1118 receiving_client_->VerifyDtmf();
1119 }
1120
1121 void TestUpdateOfferWithRejectedContent() {
deadbeefc9be0072015-12-14 18:27:57 -08001122 // Renegotiate, rejecting the video m-line.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001123 initiating_client_->Negotiate(true, false);
deadbeefc9be0072015-12-14 18:27:57 -08001124 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
1125
1126 int pc1_audio_received = initiating_client_->audio_frames_received();
1127 int pc1_video_received = initiating_client_->video_frames_received();
1128 int pc2_audio_received = receiving_client_->audio_frames_received();
1129 int pc2_video_received = receiving_client_->video_frames_received();
1130
1131 // Wait for some additional audio frames to be received.
1132 EXPECT_TRUE_WAIT(initiating_client_->AudioFramesReceivedCheck(
1133 pc1_audio_received + kEndAudioFrameCount) &&
1134 receiving_client_->AudioFramesReceivedCheck(
1135 pc2_audio_received + kEndAudioFrameCount),
1136 kMaxWaitForFramesMs);
1137
1138 // During this time, we shouldn't have received any additional video frames
1139 // for the rejected video tracks.
1140 EXPECT_EQ(pc1_video_received, initiating_client_->video_frames_received());
1141 EXPECT_EQ(pc2_video_received, receiving_client_->video_frames_received());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142 }
1143
1144 void VerifyRenderedSize(int width, int height) {
perkjcaafdba2016-03-20 07:34:29 -07001145 VerifyRenderedSize(width, height, webrtc::kVideoRotation_0);
1146 }
1147
1148 void VerifyRenderedSize(int width,
1149 int height,
1150 webrtc::VideoRotation rotation) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001151 EXPECT_EQ(width, receiving_client()->rendered_width());
1152 EXPECT_EQ(height, receiving_client()->rendered_height());
perkjcaafdba2016-03-20 07:34:29 -07001153 EXPECT_EQ(rotation, receiving_client()->rendered_rotation());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001154 EXPECT_EQ(width, initializing_client()->rendered_width());
1155 EXPECT_EQ(height, initializing_client()->rendered_height());
perkjcaafdba2016-03-20 07:34:29 -07001156 EXPECT_EQ(rotation, initializing_client()->rendered_rotation());
1157
1158 // Verify size of the local preview.
1159 EXPECT_EQ(width, initializing_client()->local_rendered_width());
1160 EXPECT_EQ(height, initializing_client()->local_rendered_height());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001161 }
1162
1163 void VerifySessionDescriptions() {
1164 initiating_client_->VerifyRejectedMediaInSessionDescription();
1165 receiving_client_->VerifyRejectedMediaInSessionDescription();
1166 initiating_client_->VerifyLocalIceUfragAndPassword();
1167 receiving_client_->VerifyLocalIceUfragAndPassword();
1168 }
1169
deadbeef7c73bdb2015-12-10 15:10:44 -08001170 ~P2PTestConductor() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001171 if (initiating_client_) {
deadbeefaf1b59c2015-10-15 12:08:41 -07001172 initiating_client_->set_signaling_message_receiver(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001173 }
1174 if (receiving_client_) {
deadbeefaf1b59c2015-10-15 12:08:41 -07001175 receiving_client_->set_signaling_message_receiver(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001176 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001177 }
1178
deadbeefaf1b59c2015-10-15 12:08:41 -07001179 bool CreateTestClients() { return CreateTestClients(nullptr, nullptr); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001180
1181 bool CreateTestClients(MediaConstraintsInterface* init_constraints,
1182 MediaConstraintsInterface* recv_constraints) {
deadbeefaf1b59c2015-10-15 12:08:41 -07001183 return CreateTestClients(init_constraints, nullptr, recv_constraints,
1184 nullptr);
Joachim Bauch04e5b492015-05-29 09:40:39 +02001185 }
1186
htaaac2dea2016-03-10 13:35:55 -08001187 bool CreateTestClientsThatPreferNoConstraints() {
1188 initiating_client_.reset(
perkj8aba9972016-04-10 23:54:34 -07001189 PeerConnectionTestClient::CreateClientPreferNoConstraints(
danilchape9021a32016-05-17 01:52:02 -07001190 "Caller: ", nullptr, network_thread_.get(), worker_thread_.get()));
htaaac2dea2016-03-10 13:35:55 -08001191 receiving_client_.reset(
perkj8aba9972016-04-10 23:54:34 -07001192 PeerConnectionTestClient::CreateClientPreferNoConstraints(
danilchape9021a32016-05-17 01:52:02 -07001193 "Callee: ", nullptr, network_thread_.get(), worker_thread_.get()));
htaaac2dea2016-03-10 13:35:55 -08001194 if (!initiating_client_ || !receiving_client_) {
1195 return false;
1196 }
1197 // Remember the choice for possible later resets of the clients.
1198 prefer_constraint_apis_ = false;
1199 SetSignalingReceivers();
1200 return true;
1201 }
1202
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001203 void SetSignalingReceivers() {
1204 initiating_client_->set_signaling_message_receiver(receiving_client_.get());
1205 receiving_client_->set_signaling_message_receiver(initiating_client_.get());
1206 }
1207
Joachim Bauch04e5b492015-05-29 09:40:39 +02001208 bool CreateTestClients(MediaConstraintsInterface* init_constraints,
1209 PeerConnectionFactory::Options* init_options,
1210 MediaConstraintsInterface* recv_constraints,
1211 PeerConnectionFactory::Options* recv_options) {
deadbeefaf1b59c2015-10-15 12:08:41 -07001212 initiating_client_.reset(PeerConnectionTestClient::CreateClient(
danilchape9021a32016-05-17 01:52:02 -07001213 "Caller: ", init_constraints, init_options, network_thread_.get(),
1214 worker_thread_.get()));
deadbeefaf1b59c2015-10-15 12:08:41 -07001215 receiving_client_.reset(PeerConnectionTestClient::CreateClient(
danilchape9021a32016-05-17 01:52:02 -07001216 "Callee: ", recv_constraints, recv_options, network_thread_.get(),
1217 worker_thread_.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001218 if (!initiating_client_ || !receiving_client_) {
1219 return false;
1220 }
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001221 SetSignalingReceivers();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001222 return true;
1223 }
1224
1225 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints,
1226 const webrtc::FakeConstraints& recv_constraints) {
1227 initiating_client_->SetVideoConstraints(init_constraints);
1228 receiving_client_->SetVideoConstraints(recv_constraints);
1229 }
1230
perkjcaafdba2016-03-20 07:34:29 -07001231 void SetCaptureRotation(webrtc::VideoRotation rotation) {
1232 initiating_client_->SetCaptureRotation(rotation);
1233 receiving_client_->SetCaptureRotation(rotation);
1234 }
1235
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001236 void EnableVideoDecoderFactory() {
1237 initiating_client_->EnableVideoDecoderFactory();
1238 receiving_client_->EnableVideoDecoderFactory();
1239 }
1240
1241 // This test sets up a call between two parties. Both parties send static
1242 // frames to each other. Once the test is finished the number of sent frames
1243 // is compared to the number of received frames.
Taylor Brandstetter0a1bc532016-04-19 18:03:26 -07001244 void LocalP2PTest() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001245 if (initiating_client_->NumberOfLocalMediaStreams() == 0) {
1246 initiating_client_->AddMediaStream(true, true);
1247 }
1248 initiating_client_->Negotiate();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001249 // Assert true is used here since next tests are guaranteed to fail and
1250 // would eat up 5 seconds.
1251 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
1252 VerifySessionDescriptions();
1253
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001254 int audio_frame_count = kEndAudioFrameCount;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255 int video_frame_count = kEndVideoFrameCount;
hta6b4f8392016-03-10 00:24:31 -08001256 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly.
1257
1258 if ((!initiating_client_->can_receive_audio() &&
1259 !initiating_client_->can_receive_video()) ||
1260 (!receiving_client_->can_receive_audio() &&
1261 !receiving_client_->can_receive_video())) {
1262 // Neither audio nor video will flow, so connections won't be
1263 // established. There's nothing more to check.
1264 // TODO(hta): Check connection if there's a data channel.
1265 return;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001266 }
1267
hta6b4f8392016-03-10 00:24:31 -08001268 // Audio or video is expected to flow, so both clients should reach the
1269 // Connected state, and the offerer (ICE controller) should proceed to
1270 // Completed.
1271 // Note: These tests have been observed to fail under heavy load at
1272 // shorter timeouts, so they may be flaky.
Taylor Brandstetter0a1bc532016-04-19 18:03:26 -07001273 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
1274 initiating_client_->ice_connection_state(),
1275 kMaxWaitForFramesMs);
hta6b4f8392016-03-10 00:24:31 -08001276 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
1277 receiving_client_->ice_connection_state(),
1278 kMaxWaitForFramesMs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001279
hta6b4f8392016-03-10 00:24:31 -08001280 // The ICE gathering state should end up in kIceGatheringComplete,
1281 // but there's a bug that prevents this at the moment, and the state
1282 // machine is being updated by the WEBRTC WG.
1283 // TODO(hta): Update this check when spec revisions finish.
1284 EXPECT_NE(webrtc::PeerConnectionInterface::kIceGatheringNew,
1285 initiating_client_->ice_gathering_state());
1286 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
1287 receiving_client_->ice_gathering_state(),
1288 kMaxWaitForFramesMs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289
hta6b4f8392016-03-10 00:24:31 -08001290 // Check that the expected number of frames have arrived.
1291 EXPECT_TRUE_WAIT(FramesHaveArrived(audio_frame_count, video_frame_count),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292 kMaxWaitForFramesMs);
1293 }
1294
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001295 void SetupAndVerifyDtlsCall() {
1296 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1297 FakeConstraints setup_constraints;
1298 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1299 true);
1300 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1301 LocalP2PTest();
1302 VerifyRenderedSize(640, 480);
1303 }
1304
1305 PeerConnectionTestClient* CreateDtlsClientWithAlternateKey() {
1306 FakeConstraints setup_constraints;
1307 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1308 true);
1309
Henrik Boströmd79599d2016-06-01 13:58:50 +02001310 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
1311 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
1312 new FakeRTCCertificateGenerator() : nullptr);
1313 cert_generator->use_alternate_key();
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001314
1315 // Make sure the new client is using a different certificate.
1316 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore(
kwiberg0eb15ed2015-12-17 03:04:15 -08001317 "New Peer: ", &setup_constraints, nullptr,
Henrik Boströmd79599d2016-06-01 13:58:50 +02001318 std::move(cert_generator), prefer_constraint_apis_,
danilchape9021a32016-05-17 01:52:02 -07001319 network_thread_.get(), worker_thread_.get());
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001320 }
1321
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001322 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) {
1323 // Messages may get lost on the unreliable DataChannel, so we send multiple
1324 // times to avoid test flakiness.
1325 static const size_t kSendAttempts = 5;
1326
1327 for (size_t i = 0; i < kSendAttempts; ++i) {
1328 dc->Send(DataBuffer(data));
1329 }
1330 }
1331
deadbeefaf1b59c2015-10-15 12:08:41 -07001332 PeerConnectionTestClient* initializing_client() {
1333 return initiating_client_.get();
1334 }
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001335
1336 // Set the |initiating_client_| to the |client| passed in and return the
1337 // original |initiating_client_|.
1338 PeerConnectionTestClient* set_initializing_client(
1339 PeerConnectionTestClient* client) {
1340 PeerConnectionTestClient* old = initiating_client_.release();
1341 initiating_client_.reset(client);
1342 return old;
1343 }
1344
deadbeefaf1b59c2015-10-15 12:08:41 -07001345 PeerConnectionTestClient* receiving_client() {
1346 return receiving_client_.get();
1347 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001348
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001349 // Set the |receiving_client_| to the |client| passed in and return the
1350 // original |receiving_client_|.
1351 PeerConnectionTestClient* set_receiving_client(
1352 PeerConnectionTestClient* client) {
1353 PeerConnectionTestClient* old = receiving_client_.release();
1354 receiving_client_.reset(client);
1355 return old;
1356 }
1357
zhihuang184a3fd2016-06-14 11:47:14 -07001358 bool AllObserversReceived(
1359 const std::vector<std::unique_ptr<MockRtpReceiverObserver>>& observers) {
1360 for (auto& observer : observers) {
1361 if (!observer->first_packet_received()) {
1362 return false;
1363 }
1364 }
1365 return true;
1366 }
1367
jbauchcb560652016-08-04 05:20:32 -07001368 void TestGcmNegotiation(bool local_gcm_enabled, bool remote_gcm_enabled,
1369 int expected_cipher_suite) {
1370 PeerConnectionFactory::Options init_options;
1371 init_options.crypto_options.enable_gcm_crypto_suites = local_gcm_enabled;
1372 PeerConnectionFactory::Options recv_options;
1373 recv_options.crypto_options.enable_gcm_crypto_suites = remote_gcm_enabled;
1374 ASSERT_TRUE(
1375 CreateTestClients(nullptr, &init_options, nullptr, &recv_options));
1376 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1377 init_observer =
1378 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1379 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1380 LocalP2PTest();
1381
1382 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite),
1383 initializing_client()->GetSrtpCipherStats(),
1384 kMaxWaitMs);
1385 EXPECT_EQ(1,
1386 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1387 expected_cipher_suite));
1388 }
1389
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001390 private:
deadbeefeff5b852016-05-27 14:18:01 -07001391 // |ss_| is used by |network_thread_| so it must be destroyed later.
kwibergd1fe2812016-04-27 06:47:29 -07001392 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1393 std::unique_ptr<rtc::VirtualSocketServer> ss_;
deadbeefeff5b852016-05-27 14:18:01 -07001394 // |network_thread_| and |worker_thread_| are used by both
1395 // |initiating_client_| and |receiving_client_| so they must be destroyed
1396 // later.
1397 std::unique_ptr<rtc::Thread> network_thread_;
1398 std::unique_ptr<rtc::Thread> worker_thread_;
kwibergd1fe2812016-04-27 06:47:29 -07001399 std::unique_ptr<PeerConnectionTestClient> initiating_client_;
1400 std::unique_ptr<PeerConnectionTestClient> receiving_client_;
htaaac2dea2016-03-10 13:35:55 -08001401 bool prefer_constraint_apis_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001402};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403
kjellander@webrtc.orgd1cfa712013-10-16 16:51:52 +00001404// Disable for TSan v2, see
1405// https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
1406#if !defined(THREAD_SANITIZER)
1407
zhihuang184a3fd2016-06-14 11:47:14 -07001408TEST_F(P2PTestConductor, TestRtpReceiverObserverCallbackFunction) {
1409 ASSERT_TRUE(CreateTestClients());
1410 LocalP2PTest();
1411 EXPECT_TRUE_WAIT(
1412 AllObserversReceived(initializing_client()->rtp_receiver_observers()),
1413 kMaxWaitForFramesMs);
1414 EXPECT_TRUE_WAIT(
1415 AllObserversReceived(receiving_client()->rtp_receiver_observers()),
1416 kMaxWaitForFramesMs);
1417}
1418
1419// The observers are expected to fire the signal even if they are set after the
1420// first packet is received.
1421TEST_F(P2PTestConductor, TestSetRtpReceiverObserverAfterFirstPacketIsReceived) {
1422 ASSERT_TRUE(CreateTestClients());
1423 LocalP2PTest();
1424 // Reset the RtpReceiverObservers.
1425 initializing_client()->SetRtpReceiverObservers();
1426 receiving_client()->SetRtpReceiverObservers();
1427 EXPECT_TRUE_WAIT(
1428 AllObserversReceived(initializing_client()->rtp_receiver_observers()),
1429 kMaxWaitForFramesMs);
1430 EXPECT_TRUE_WAIT(
1431 AllObserversReceived(receiving_client()->rtp_receiver_observers()),
1432 kMaxWaitForFramesMs);
1433}
1434
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001435// This test sets up a Jsep call between two parties and test Dtmf.
stefan@webrtc.orgda790082013-09-17 13:11:38 +00001436// TODO(holmer): Disabled due to sometimes crashing on buildbots.
1437// See issue webrtc/2378.
deadbeef7c73bdb2015-12-10 15:10:44 -08001438TEST_F(P2PTestConductor, DISABLED_LocalP2PTestDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 ASSERT_TRUE(CreateTestClients());
1440 LocalP2PTest();
1441 VerifyDtmf();
1442}
1443
1444// This test sets up a Jsep call between two parties and test that we can get a
1445// video aspect ratio of 16:9.
deadbeef7c73bdb2015-12-10 15:10:44 -08001446TEST_F(P2PTestConductor, LocalP2PTest16To9) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447 ASSERT_TRUE(CreateTestClients());
1448 FakeConstraints constraint;
1449 double requested_ratio = 640.0/360;
1450 constraint.SetMandatoryMinAspectRatio(requested_ratio);
1451 SetVideoConstraints(constraint, constraint);
1452 LocalP2PTest();
1453
1454 ASSERT_LE(0, initializing_client()->rendered_height());
1455 double initiating_video_ratio =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001456 static_cast<double>(initializing_client()->rendered_width()) /
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001457 initializing_client()->rendered_height();
1458 EXPECT_LE(requested_ratio, initiating_video_ratio);
1459
1460 ASSERT_LE(0, receiving_client()->rendered_height());
1461 double receiving_video_ratio =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001462 static_cast<double>(receiving_client()->rendered_width()) /
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001463 receiving_client()->rendered_height();
1464 EXPECT_LE(requested_ratio, receiving_video_ratio);
1465}
1466
1467// This test sets up a Jsep call between two parties and test that the
1468// received video has a resolution of 1280*720.
1469// TODO(mallinath): Enable when
1470// http://code.google.com/p/webrtc/issues/detail?id=981 is fixed.
deadbeef7c73bdb2015-12-10 15:10:44 -08001471TEST_F(P2PTestConductor, DISABLED_LocalP2PTest1280By720) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472 ASSERT_TRUE(CreateTestClients());
1473 FakeConstraints constraint;
1474 constraint.SetMandatoryMinWidth(1280);
1475 constraint.SetMandatoryMinHeight(720);
1476 SetVideoConstraints(constraint, constraint);
1477 LocalP2PTest();
1478 VerifyRenderedSize(1280, 720);
1479}
1480
1481// This test sets up a call between two endpoints that are configured to use
1482// DTLS key agreement. As a result, DTLS is negotiated and used for transport.
deadbeef7c73bdb2015-12-10 15:10:44 -08001483TEST_F(P2PTestConductor, LocalP2PTestDtls) {
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001484 SetupAndVerifyDtlsCall();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001485}
1486
hta6b4f8392016-03-10 00:24:31 -08001487// This test sets up an one-way call, with media only from initiator to
1488// responder.
1489TEST_F(P2PTestConductor, OneWayMediaCall) {
1490 ASSERT_TRUE(CreateTestClients());
1491 receiving_client()->set_auto_add_stream(false);
1492 LocalP2PTest();
1493}
1494
htaaac2dea2016-03-10 13:35:55 -08001495TEST_F(P2PTestConductor, OneWayMediaCallWithoutConstraints) {
1496 ASSERT_TRUE(CreateTestClientsThatPreferNoConstraints());
1497 receiving_client()->set_auto_add_stream(false);
1498 LocalP2PTest();
1499}
1500
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001501// This test sets up a audio call initially and then upgrades to audio/video,
1502// using DTLS.
deadbeef7c73bdb2015-12-10 15:10:44 -08001503TEST_F(P2PTestConductor, LocalP2PTestDtlsRenegotiate) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001504 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001505 FakeConstraints setup_constraints;
1506 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1507 true);
1508 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1509 receiving_client()->SetReceiveAudioVideo(true, false);
1510 LocalP2PTest();
1511 receiving_client()->SetReceiveAudioVideo(true, true);
1512 receiving_client()->Negotiate();
1513}
1514
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001515// This test sets up a call transfer to a new caller with a different DTLS
1516// fingerprint.
deadbeef7c73bdb2015-12-10 15:10:44 -08001517TEST_F(P2PTestConductor, LocalP2PTestDtlsTransferCallee) {
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001518 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1519 SetupAndVerifyDtlsCall();
1520
1521 // Keeping the original peer around which will still send packets to the
1522 // receiving client. These SRTP packets will be dropped.
kwibergd1fe2812016-04-27 06:47:29 -07001523 std::unique_ptr<PeerConnectionTestClient> original_peer(
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001524 set_initializing_client(CreateDtlsClientWithAlternateKey()));
1525 original_peer->pc()->Close();
1526
1527 SetSignalingReceivers();
1528 receiving_client()->SetExpectIceRestart(true);
1529 LocalP2PTest();
1530 VerifyRenderedSize(640, 480);
1531}
1532
guoweis46383312015-12-17 16:45:59 -08001533// This test sets up a non-bundle call and apply bundle during ICE restart. When
1534// bundle is in effect in the restart, the channel can successfully reset its
1535// DTLS-SRTP context.
1536TEST_F(P2PTestConductor, LocalP2PTestDtlsBundleInIceRestart) {
1537 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1538 FakeConstraints setup_constraints;
1539 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1540 true);
1541 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1542 receiving_client()->RemoveBundleFromReceivedSdp(true);
1543 LocalP2PTest();
1544 VerifyRenderedSize(640, 480);
1545
1546 initializing_client()->IceRestart();
1547 receiving_client()->SetExpectIceRestart(true);
1548 receiving_client()->RemoveBundleFromReceivedSdp(false);
1549 LocalP2PTest();
1550 VerifyRenderedSize(640, 480);
1551}
1552
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001553// This test sets up a call transfer to a new callee with a different DTLS
1554// fingerprint.
deadbeef7c73bdb2015-12-10 15:10:44 -08001555TEST_F(P2PTestConductor, LocalP2PTestDtlsTransferCaller) {
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001556 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1557 SetupAndVerifyDtlsCall();
1558
1559 // Keeping the original peer around which will still send packets to the
1560 // receiving client. These SRTP packets will be dropped.
kwibergd1fe2812016-04-27 06:47:29 -07001561 std::unique_ptr<PeerConnectionTestClient> original_peer(
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001562 set_receiving_client(CreateDtlsClientWithAlternateKey()));
1563 original_peer->pc()->Close();
1564
1565 SetSignalingReceivers();
1566 initializing_client()->IceRestart();
Taylor Brandstetter0a1bc532016-04-19 18:03:26 -07001567 LocalP2PTest();
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001568 VerifyRenderedSize(640, 480);
1569}
1570
perkjcaafdba2016-03-20 07:34:29 -07001571TEST_F(P2PTestConductor, LocalP2PTestCVO) {
1572 ASSERT_TRUE(CreateTestClients());
1573 SetCaptureRotation(webrtc::kVideoRotation_90);
1574 LocalP2PTest();
1575 VerifyRenderedSize(640, 480, webrtc::kVideoRotation_90);
1576}
1577
1578TEST_F(P2PTestConductor, LocalP2PTestReceiverDoesntSupportCVO) {
1579 ASSERT_TRUE(CreateTestClients());
1580 SetCaptureRotation(webrtc::kVideoRotation_90);
1581 receiving_client()->RemoveCvoFromReceivedSdp(true);
1582 LocalP2PTest();
1583 VerifyRenderedSize(480, 640, webrtc::kVideoRotation_0);
1584}
1585
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586// This test sets up a call between two endpoints that are configured to use
1587// DTLS key agreement. The offerer don't support SDES. As a result, DTLS is
1588// negotiated and used for transport.
deadbeef7c73bdb2015-12-10 15:10:44 -08001589TEST_F(P2PTestConductor, LocalP2PTestOfferDtlsButNotSdes) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001590 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591 FakeConstraints setup_constraints;
1592 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1593 true);
1594 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1595 receiving_client()->RemoveSdesCryptoFromReceivedSdp(true);
1596 LocalP2PTest();
1597 VerifyRenderedSize(640, 480);
1598}
1599
1600// This test sets up a Jsep call between two parties, and the callee only
1601// accept to receive video.
deadbeef7c73bdb2015-12-10 15:10:44 -08001602TEST_F(P2PTestConductor, LocalP2PTestAnswerVideo) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 ASSERT_TRUE(CreateTestClients());
1604 receiving_client()->SetReceiveAudioVideo(false, true);
1605 LocalP2PTest();
1606}
1607
1608// This test sets up a Jsep call between two parties, and the callee only
1609// accept to receive audio.
deadbeef7c73bdb2015-12-10 15:10:44 -08001610TEST_F(P2PTestConductor, LocalP2PTestAnswerAudio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 ASSERT_TRUE(CreateTestClients());
1612 receiving_client()->SetReceiveAudioVideo(true, false);
1613 LocalP2PTest();
1614}
1615
1616// This test sets up a Jsep call between two parties, and the callee reject both
1617// audio and video.
deadbeef7c73bdb2015-12-10 15:10:44 -08001618TEST_F(P2PTestConductor, LocalP2PTestAnswerNone) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 ASSERT_TRUE(CreateTestClients());
1620 receiving_client()->SetReceiveAudioVideo(false, false);
1621 LocalP2PTest();
1622}
1623
1624// This test sets up an audio and video call between two parties. After the call
1625// runs for a while (10 frames), the caller sends an update offer with video
1626// being rejected. Once the re-negotiation is done, the video flow should stop
1627// and the audio flow should continue.
deadbeefc9be0072015-12-14 18:27:57 -08001628TEST_F(P2PTestConductor, UpdateOfferWithRejectedContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 ASSERT_TRUE(CreateTestClients());
1630 LocalP2PTest();
1631 TestUpdateOfferWithRejectedContent();
1632}
1633
1634// This test sets up a Jsep call between two parties. The MSID is removed from
1635// the SDP strings from the caller.
deadbeefc9be0072015-12-14 18:27:57 -08001636TEST_F(P2PTestConductor, LocalP2PTestWithoutMsid) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637 ASSERT_TRUE(CreateTestClients());
1638 receiving_client()->RemoveMsidFromReceivedSdp(true);
1639 // TODO(perkj): Currently there is a bug that cause audio to stop playing if
1640 // audio and video is muxed when MSID is disabled. Remove
1641 // SetRemoveBundleFromSdp once
1642 // https://code.google.com/p/webrtc/issues/detail?id=1193 is fixed.
1643 receiving_client()->RemoveBundleFromReceivedSdp(true);
1644 LocalP2PTest();
1645}
1646
1647// This test sets up a Jsep call between two parties and the initiating peer
1648// sends two steams.
1649// TODO(perkj): Disabled due to
1650// https://code.google.com/p/webrtc/issues/detail?id=1454
deadbeef7c73bdb2015-12-10 15:10:44 -08001651TEST_F(P2PTestConductor, DISABLED_LocalP2PTestTwoStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 ASSERT_TRUE(CreateTestClients());
1653 // Set optional video constraint to max 320pixels to decrease CPU usage.
1654 FakeConstraints constraint;
1655 constraint.SetOptionalMaxWidth(320);
1656 SetVideoConstraints(constraint, constraint);
1657 initializing_client()->AddMediaStream(true, true);
1658 initializing_client()->AddMediaStream(false, true);
1659 ASSERT_EQ(2u, initializing_client()->NumberOfLocalMediaStreams());
1660 LocalP2PTest();
1661 EXPECT_EQ(2u, receiving_client()->number_of_remote_streams());
1662}
1663
1664// Test that we can receive the audio output level from a remote audio track.
deadbeef7c73bdb2015-12-10 15:10:44 -08001665TEST_F(P2PTestConductor, GetAudioOutputLevelStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666 ASSERT_TRUE(CreateTestClients());
1667 LocalP2PTest();
1668
1669 StreamCollectionInterface* remote_streams =
1670 initializing_client()->remote_streams();
1671 ASSERT_GT(remote_streams->count(), 0u);
1672 ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u);
1673 MediaStreamTrackInterface* remote_audio_track =
1674 remote_streams->at(0)->GetAudioTracks()[0];
1675
1676 // Get the audio output level stats. Note that the level is not available
1677 // until a RTCP packet has been received.
1678 EXPECT_TRUE_WAIT(
1679 initializing_client()->GetAudioOutputLevelStats(remote_audio_track) > 0,
1680 kMaxWaitForStatsMs);
1681}
1682
1683// Test that an audio input level is reported.
deadbeef7c73bdb2015-12-10 15:10:44 -08001684TEST_F(P2PTestConductor, GetAudioInputLevelStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001685 ASSERT_TRUE(CreateTestClients());
1686 LocalP2PTest();
1687
1688 // Get the audio input level stats. The level should be available very
1689 // soon after the test starts.
1690 EXPECT_TRUE_WAIT(initializing_client()->GetAudioInputLevelStats() > 0,
1691 kMaxWaitForStatsMs);
1692}
1693
1694// Test that we can get incoming byte counts from both audio and video tracks.
deadbeef7c73bdb2015-12-10 15:10:44 -08001695TEST_F(P2PTestConductor, GetBytesReceivedStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 ASSERT_TRUE(CreateTestClients());
1697 LocalP2PTest();
1698
1699 StreamCollectionInterface* remote_streams =
1700 initializing_client()->remote_streams();
1701 ASSERT_GT(remote_streams->count(), 0u);
1702 ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u);
1703 MediaStreamTrackInterface* remote_audio_track =
1704 remote_streams->at(0)->GetAudioTracks()[0];
1705 EXPECT_TRUE_WAIT(
1706 initializing_client()->GetBytesReceivedStats(remote_audio_track) > 0,
1707 kMaxWaitForStatsMs);
1708
1709 MediaStreamTrackInterface* remote_video_track =
1710 remote_streams->at(0)->GetVideoTracks()[0];
1711 EXPECT_TRUE_WAIT(
1712 initializing_client()->GetBytesReceivedStats(remote_video_track) > 0,
1713 kMaxWaitForStatsMs);
1714}
1715
1716// Test that we can get outgoing byte counts from both audio and video tracks.
deadbeef7c73bdb2015-12-10 15:10:44 -08001717TEST_F(P2PTestConductor, GetBytesSentStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 ASSERT_TRUE(CreateTestClients());
1719 LocalP2PTest();
1720
1721 StreamCollectionInterface* local_streams =
1722 initializing_client()->local_streams();
1723 ASSERT_GT(local_streams->count(), 0u);
1724 ASSERT_GT(local_streams->at(0)->GetAudioTracks().size(), 0u);
1725 MediaStreamTrackInterface* local_audio_track =
1726 local_streams->at(0)->GetAudioTracks()[0];
1727 EXPECT_TRUE_WAIT(
1728 initializing_client()->GetBytesSentStats(local_audio_track) > 0,
1729 kMaxWaitForStatsMs);
1730
1731 MediaStreamTrackInterface* local_video_track =
1732 local_streams->at(0)->GetVideoTracks()[0];
1733 EXPECT_TRUE_WAIT(
1734 initializing_client()->GetBytesSentStats(local_video_track) > 0,
1735 kMaxWaitForStatsMs);
1736}
1737
Joachim Bauch04e5b492015-05-29 09:40:39 +02001738// Test that DTLS 1.0 is used if both sides only support DTLS 1.0.
torbjorng43166b82016-03-11 00:06:47 -08001739TEST_F(P2PTestConductor, GetDtls12None) {
Joachim Bauch04e5b492015-05-29 09:40:39 +02001740 PeerConnectionFactory::Options init_options;
1741 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1742 PeerConnectionFactory::Options recv_options;
1743 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
deadbeefaf1b59c2015-10-15 12:08:41 -07001744 ASSERT_TRUE(
1745 CreateTestClients(nullptr, &init_options, nullptr, &recv_options));
jbauchac8869e2015-07-03 01:36:14 -07001746 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1747 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1748 initializing_client()->pc()->RegisterUMAObserver(init_observer);
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +00001749 LocalP2PTest();
1750
torbjorng43166b82016-03-11 00:06:47 -08001751 EXPECT_TRUE_WAIT(
1752 rtc::SSLStreamAdapter::IsAcceptableCipher(
1753 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1754 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001755 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001756 initializing_client()->GetSrtpCipherStats(),
1757 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001758 EXPECT_EQ(1,
1759 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1760 kDefaultSrtpCryptoSuite));
Joachim Bauch04e5b492015-05-29 09:40:39 +02001761}
1762
1763// Test that DTLS 1.2 is used if both ends support it.
torbjorng79a5a832016-01-15 07:16:51 -08001764TEST_F(P2PTestConductor, GetDtls12Both) {
Joachim Bauch04e5b492015-05-29 09:40:39 +02001765 PeerConnectionFactory::Options init_options;
1766 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1767 PeerConnectionFactory::Options recv_options;
1768 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
deadbeefaf1b59c2015-10-15 12:08:41 -07001769 ASSERT_TRUE(
1770 CreateTestClients(nullptr, &init_options, nullptr, &recv_options));
jbauchac8869e2015-07-03 01:36:14 -07001771 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1772 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1773 initializing_client()->pc()->RegisterUMAObserver(init_observer);
Joachim Bauch04e5b492015-05-29 09:40:39 +02001774 LocalP2PTest();
1775
torbjorng43166b82016-03-11 00:06:47 -08001776 EXPECT_TRUE_WAIT(
1777 rtc::SSLStreamAdapter::IsAcceptableCipher(
1778 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1779 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001780 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001781 initializing_client()->GetSrtpCipherStats(),
1782 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001783 EXPECT_EQ(1,
1784 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1785 kDefaultSrtpCryptoSuite));
Joachim Bauch04e5b492015-05-29 09:40:39 +02001786}
1787
1788// Test that DTLS 1.0 is used if the initator supports DTLS 1.2 and the
1789// received supports 1.0.
torbjorng43166b82016-03-11 00:06:47 -08001790TEST_F(P2PTestConductor, GetDtls12Init) {
Joachim Bauch04e5b492015-05-29 09:40:39 +02001791 PeerConnectionFactory::Options init_options;
1792 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1793 PeerConnectionFactory::Options recv_options;
1794 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
deadbeefaf1b59c2015-10-15 12:08:41 -07001795 ASSERT_TRUE(
1796 CreateTestClients(nullptr, &init_options, nullptr, &recv_options));
jbauchac8869e2015-07-03 01:36:14 -07001797 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1798 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1799 initializing_client()->pc()->RegisterUMAObserver(init_observer);
Joachim Bauch04e5b492015-05-29 09:40:39 +02001800 LocalP2PTest();
1801
torbjorng43166b82016-03-11 00:06:47 -08001802 EXPECT_TRUE_WAIT(
1803 rtc::SSLStreamAdapter::IsAcceptableCipher(
1804 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1805 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001806 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001807 initializing_client()->GetSrtpCipherStats(),
1808 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001809 EXPECT_EQ(1,
1810 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1811 kDefaultSrtpCryptoSuite));
Joachim Bauch04e5b492015-05-29 09:40:39 +02001812}
1813
1814// Test that DTLS 1.0 is used if the initator supports DTLS 1.0 and the
1815// received supports 1.2.
torbjorng43166b82016-03-11 00:06:47 -08001816TEST_F(P2PTestConductor, GetDtls12Recv) {
Joachim Bauch04e5b492015-05-29 09:40:39 +02001817 PeerConnectionFactory::Options init_options;
1818 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1819 PeerConnectionFactory::Options recv_options;
1820 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
deadbeefaf1b59c2015-10-15 12:08:41 -07001821 ASSERT_TRUE(
1822 CreateTestClients(nullptr, &init_options, nullptr, &recv_options));
jbauchac8869e2015-07-03 01:36:14 -07001823 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1824 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1825 initializing_client()->pc()->RegisterUMAObserver(init_observer);
Joachim Bauch04e5b492015-05-29 09:40:39 +02001826 LocalP2PTest();
1827
torbjorng43166b82016-03-11 00:06:47 -08001828 EXPECT_TRUE_WAIT(
1829 rtc::SSLStreamAdapter::IsAcceptableCipher(
1830 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1831 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001832 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001833 initializing_client()->GetSrtpCipherStats(),
1834 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001835 EXPECT_EQ(1,
1836 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1837 kDefaultSrtpCryptoSuite));
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +00001838}
1839
jbauchcb560652016-08-04 05:20:32 -07001840// Test that a non-GCM cipher is used if both sides only support non-GCM.
1841TEST_F(P2PTestConductor, GetGcmNone) {
1842 TestGcmNegotiation(false, false, kDefaultSrtpCryptoSuite);
1843}
1844
1845// Test that a GCM cipher is used if both ends support it.
1846TEST_F(P2PTestConductor, GetGcmBoth) {
1847 TestGcmNegotiation(true, true, kDefaultSrtpCryptoSuiteGcm);
1848}
1849
1850// Test that GCM isn't used if only the initiator supports it.
1851TEST_F(P2PTestConductor, GetGcmInit) {
1852 TestGcmNegotiation(true, false, kDefaultSrtpCryptoSuite);
1853}
1854
1855// Test that GCM isn't used if only the receiver supports it.
1856TEST_F(P2PTestConductor, GetGcmRecv) {
1857 TestGcmNegotiation(false, true, kDefaultSrtpCryptoSuite);
1858}
1859
deadbeefb5cb19b2015-11-23 16:39:12 -08001860// This test sets up a call between two parties with audio, video and an RTP
1861// data channel.
deadbeef7c73bdb2015-12-10 15:10:44 -08001862TEST_F(P2PTestConductor, LocalP2PTestRtpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863 FakeConstraints setup_constraints;
1864 setup_constraints.SetAllowRtpDataChannels();
1865 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1866 initializing_client()->CreateDataChannel();
1867 LocalP2PTest();
deadbeefaf1b59c2015-10-15 12:08:41 -07001868 ASSERT_TRUE(initializing_client()->data_channel() != nullptr);
1869 ASSERT_TRUE(receiving_client()->data_channel() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001870 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
1871 kMaxWaitMs);
1872 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(),
1873 kMaxWaitMs);
1874
1875 std::string data = "hello world";
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001876
1877 SendRtpData(initializing_client()->data_channel(), data);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001878 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(),
1879 kMaxWaitMs);
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001880
1881 SendRtpData(receiving_client()->data_channel(), data);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(),
1883 kMaxWaitMs);
1884
1885 receiving_client()->data_channel()->Close();
1886 // Send new offer and answer.
1887 receiving_client()->Negotiate();
1888 EXPECT_FALSE(initializing_client()->data_observer()->IsOpen());
1889 EXPECT_FALSE(receiving_client()->data_observer()->IsOpen());
1890}
1891
deadbeefb5cb19b2015-11-23 16:39:12 -08001892// This test sets up a call between two parties with audio, video and an SCTP
1893// data channel.
deadbeef7c73bdb2015-12-10 15:10:44 -08001894TEST_F(P2PTestConductor, LocalP2PTestSctpDataChannel) {
deadbeefb5cb19b2015-11-23 16:39:12 -08001895 ASSERT_TRUE(CreateTestClients());
1896 initializing_client()->CreateDataChannel();
1897 LocalP2PTest();
1898 ASSERT_TRUE(initializing_client()->data_channel() != nullptr);
1899 EXPECT_TRUE_WAIT(receiving_client()->data_channel() != nullptr, kMaxWaitMs);
1900 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
1901 kMaxWaitMs);
1902 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), kMaxWaitMs);
1903
1904 std::string data = "hello world";
1905
1906 initializing_client()->data_channel()->Send(DataBuffer(data));
1907 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(),
1908 kMaxWaitMs);
1909
1910 receiving_client()->data_channel()->Send(DataBuffer(data));
1911 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(),
1912 kMaxWaitMs);
1913
1914 receiving_client()->data_channel()->Close();
deadbeef15887932015-12-14 19:32:34 -08001915 EXPECT_TRUE_WAIT(!initializing_client()->data_observer()->IsOpen(),
1916 kMaxWaitMs);
1917 EXPECT_TRUE_WAIT(!receiving_client()->data_observer()->IsOpen(), kMaxWaitMs);
deadbeefb5cb19b2015-11-23 16:39:12 -08001918}
1919
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001920// This test sets up a call between two parties and creates a data channel.
1921// The test tests that received data is buffered unless an observer has been
1922// registered.
1923// Rtp data channels can receive data before the underlying
1924// transport has detected that a channel is writable and thus data can be
1925// received before the data channel state changes to open. That is hard to test
1926// but the same buffering is used in that case.
deadbeef7c73bdb2015-12-10 15:10:44 -08001927TEST_F(P2PTestConductor, RegisterDataChannelObserver) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928 FakeConstraints setup_constraints;
1929 setup_constraints.SetAllowRtpDataChannels();
1930 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1931 initializing_client()->CreateDataChannel();
1932 initializing_client()->Negotiate();
1933
deadbeefaf1b59c2015-10-15 12:08:41 -07001934 ASSERT_TRUE(initializing_client()->data_channel() != nullptr);
1935 ASSERT_TRUE(receiving_client()->data_channel() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001936 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
1937 kMaxWaitMs);
1938 EXPECT_EQ_WAIT(DataChannelInterface::kOpen,
1939 receiving_client()->data_channel()->state(), kMaxWaitMs);
1940
1941 // Unregister the existing observer.
1942 receiving_client()->data_channel()->UnregisterObserver();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001943
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001944 std::string data = "hello world";
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001945 SendRtpData(initializing_client()->data_channel(), data);
1946
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001947 // Wait a while to allow the sent data to arrive before an observer is
1948 // registered..
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001949 rtc::Thread::Current()->ProcessMessages(100);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950
1951 MockDataChannelObserver new_observer(receiving_client()->data_channel());
1952 EXPECT_EQ_WAIT(data, new_observer.last_message(), kMaxWaitMs);
1953}
1954
1955// This test sets up a call between two parties with audio, video and but only
1956// the initiating client support data.
deadbeef7c73bdb2015-12-10 15:10:44 -08001957TEST_F(P2PTestConductor, LocalP2PTestReceiverDoesntSupportData) {
buildbot@webrtc.org61c1b8e2014-04-09 06:06:38 +00001958 FakeConstraints setup_constraints_1;
1959 setup_constraints_1.SetAllowRtpDataChannels();
1960 // Must disable DTLS to make negotiation succeed.
1961 setup_constraints_1.SetMandatory(
1962 MediaConstraintsInterface::kEnableDtlsSrtp, false);
1963 FakeConstraints setup_constraints_2;
1964 setup_constraints_2.SetMandatory(
1965 MediaConstraintsInterface::kEnableDtlsSrtp, false);
1966 ASSERT_TRUE(CreateTestClients(&setup_constraints_1, &setup_constraints_2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967 initializing_client()->CreateDataChannel();
1968 LocalP2PTest();
deadbeefaf1b59c2015-10-15 12:08:41 -07001969 EXPECT_TRUE(initializing_client()->data_channel() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970 EXPECT_FALSE(receiving_client()->data_channel());
1971 EXPECT_FALSE(initializing_client()->data_observer()->IsOpen());
1972}
1973
1974// This test sets up a call between two parties with audio, video. When audio
1975// and video is setup and flowing and data channel is negotiated.
deadbeef7c73bdb2015-12-10 15:10:44 -08001976TEST_F(P2PTestConductor, AddDataChannelAfterRenegotiation) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 FakeConstraints setup_constraints;
1978 setup_constraints.SetAllowRtpDataChannels();
1979 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1980 LocalP2PTest();
1981 initializing_client()->CreateDataChannel();
1982 // Send new offer and answer.
1983 initializing_client()->Negotiate();
deadbeefaf1b59c2015-10-15 12:08:41 -07001984 ASSERT_TRUE(initializing_client()->data_channel() != nullptr);
1985 ASSERT_TRUE(receiving_client()->data_channel() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
1987 kMaxWaitMs);
1988 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(),
1989 kMaxWaitMs);
1990}
1991
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001992// This test sets up a Jsep call with SCTP DataChannel and verifies the
1993// negotiation is completed without error.
1994#ifdef HAVE_SCTP
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07001995TEST_F(P2PTestConductor, CreateOfferWithSctpDataChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001996 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001997 FakeConstraints constraints;
1998 constraints.SetMandatory(
1999 MediaConstraintsInterface::kEnableDtlsSrtp, true);
2000 ASSERT_TRUE(CreateTestClients(&constraints, &constraints));
2001 initializing_client()->CreateDataChannel();
2002 initializing_client()->Negotiate(false, false);
2003}
2004#endif
2005
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006// This test sets up a call between two parties with audio, and video.
2007// During the call, the initializing side restart ice and the test verifies that
2008// new ice candidates are generated and audio and video still can flow.
deadbeef7c73bdb2015-12-10 15:10:44 -08002009TEST_F(P2PTestConductor, IceRestart) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010 ASSERT_TRUE(CreateTestClients());
2011
2012 // Negotiate and wait for ice completion and make sure audio and video plays.
2013 LocalP2PTest();
2014
2015 // Create a SDP string of the first audio candidate for both clients.
2016 const webrtc::IceCandidateCollection* audio_candidates_initiator =
2017 initializing_client()->pc()->local_description()->candidates(0);
2018 const webrtc::IceCandidateCollection* audio_candidates_receiver =
2019 receiving_client()->pc()->local_description()->candidates(0);
2020 ASSERT_GT(audio_candidates_initiator->count(), 0u);
2021 ASSERT_GT(audio_candidates_receiver->count(), 0u);
2022 std::string initiator_candidate;
2023 EXPECT_TRUE(
2024 audio_candidates_initiator->at(0)->ToString(&initiator_candidate));
2025 std::string receiver_candidate;
2026 EXPECT_TRUE(audio_candidates_receiver->at(0)->ToString(&receiver_candidate));
2027
2028 // Restart ice on the initializing client.
2029 receiving_client()->SetExpectIceRestart(true);
2030 initializing_client()->IceRestart();
2031
2032 // Negotiate and wait for ice completion again and make sure audio and video
2033 // plays.
2034 LocalP2PTest();
2035
2036 // Create a SDP string of the first audio candidate for both clients again.
2037 const webrtc::IceCandidateCollection* audio_candidates_initiator_restart =
2038 initializing_client()->pc()->local_description()->candidates(0);
2039 const webrtc::IceCandidateCollection* audio_candidates_reciever_restart =
2040 receiving_client()->pc()->local_description()->candidates(0);
2041 ASSERT_GT(audio_candidates_initiator_restart->count(), 0u);
2042 ASSERT_GT(audio_candidates_reciever_restart->count(), 0u);
2043 std::string initiator_candidate_restart;
2044 EXPECT_TRUE(audio_candidates_initiator_restart->at(0)->ToString(
2045 &initiator_candidate_restart));
2046 std::string receiver_candidate_restart;
2047 EXPECT_TRUE(audio_candidates_reciever_restart->at(0)->ToString(
2048 &receiver_candidate_restart));
2049
2050 // Verify that the first candidates in the local session descriptions has
2051 // changed.
2052 EXPECT_NE(initiator_candidate, initiator_candidate_restart);
2053 EXPECT_NE(receiver_candidate, receiver_candidate_restart);
2054}
2055
deadbeeffaac4972015-11-12 15:33:07 -08002056// This test sets up a call between two parties with audio, and video.
2057// It then renegotiates setting the video m-line to "port 0", then later
2058// renegotiates again, enabling video.
deadbeef7c73bdb2015-12-10 15:10:44 -08002059TEST_F(P2PTestConductor, LocalP2PTestVideoDisableEnable) {
deadbeeffaac4972015-11-12 15:33:07 -08002060 ASSERT_TRUE(CreateTestClients());
2061
2062 // Do initial negotiation. Will result in video and audio sendonly m-lines.
2063 receiving_client()->set_auto_add_stream(false);
2064 initializing_client()->AddMediaStream(true, true);
2065 initializing_client()->Negotiate();
2066
2067 // Negotiate again, disabling the video m-line (receiving client will
2068 // set port to 0 due to mandatory "OfferToReceiveVideo: false" constraint).
2069 receiving_client()->SetReceiveVideo(false);
2070 initializing_client()->Negotiate();
2071
2072 // Enable video and do negotiation again, making sure video is received
2073 // end-to-end.
2074 receiving_client()->SetReceiveVideo(true);
2075 receiving_client()->AddMediaStream(true, true);
2076 LocalP2PTest();
2077}
2078
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079// This test sets up a Jsep call between two parties with external
2080// VideoDecoderFactory.
stefan@webrtc.orgda790082013-09-17 13:11:38 +00002081// TODO(holmer): Disabled due to sometimes crashing on buildbots.
2082// See issue webrtc/2378.
deadbeef7c73bdb2015-12-10 15:10:44 -08002083TEST_F(P2PTestConductor, DISABLED_LocalP2PTestWithVideoDecoderFactory) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084 ASSERT_TRUE(CreateTestClients());
2085 EnableVideoDecoderFactory();
2086 LocalP2PTest();
2087}
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00002088
deadbeeffac06552015-11-25 11:26:01 -08002089// This tests that if we negotiate after calling CreateSender but before we
2090// have a track, then set a track later, frames from the newly-set track are
2091// received end-to-end.
deadbeef7c73bdb2015-12-10 15:10:44 -08002092TEST_F(P2PTestConductor, EarlyWarmupTest) {
deadbeeffac06552015-11-25 11:26:01 -08002093 ASSERT_TRUE(CreateTestClients());
deadbeefbd7d8f72015-12-18 16:58:44 -08002094 auto audio_sender =
2095 initializing_client()->pc()->CreateSender("audio", "stream_id");
2096 auto video_sender =
2097 initializing_client()->pc()->CreateSender("video", "stream_id");
deadbeeffac06552015-11-25 11:26:01 -08002098 initializing_client()->Negotiate();
2099 // Wait for ICE connection to complete, without any tracks.
2100 // Note that the receiving client WILL (in HandleIncomingOffer) create
2101 // tracks, so it's only the initiator here that's doing early warmup.
2102 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
2103 VerifySessionDescriptions();
2104 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
2105 initializing_client()->ice_connection_state(),
2106 kMaxWaitForFramesMs);
2107 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
2108 receiving_client()->ice_connection_state(),
2109 kMaxWaitForFramesMs);
2110 // Now set the tracks, and expect frames to immediately start flowing.
2111 EXPECT_TRUE(
2112 audio_sender->SetTrack(initializing_client()->CreateLocalAudioTrack("")));
2113 EXPECT_TRUE(
2114 video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack("")));
hta6b4f8392016-03-10 00:24:31 -08002115 EXPECT_TRUE_WAIT(FramesHaveArrived(kEndAudioFrameCount, kEndVideoFrameCount),
deadbeeffac06552015-11-25 11:26:01 -08002116 kMaxWaitForFramesMs);
2117}
2118
nissed98cf1f2016-04-22 07:27:36 -07002119TEST_F(P2PTestConductor, ForwardVideoOnlyStream) {
2120 ASSERT_TRUE(CreateTestClients());
2121 // One-way stream
2122 receiving_client()->set_auto_add_stream(false);
2123 // Video only, audio forwarding not expected to work.
2124 initializing_client()->AddMediaStream(false, true);
2125 initializing_client()->Negotiate();
2126
2127 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
2128 VerifySessionDescriptions();
2129
2130 ASSERT_TRUE(initializing_client()->can_receive_video());
2131 ASSERT_TRUE(receiving_client()->can_receive_video());
2132
2133 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
2134 initializing_client()->ice_connection_state(),
2135 kMaxWaitForFramesMs);
2136 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
2137 receiving_client()->ice_connection_state(),
2138 kMaxWaitForFramesMs);
2139
2140 ASSERT_TRUE(receiving_client()->remote_streams()->count() == 1);
2141
2142 // Echo the stream back.
2143 receiving_client()->pc()->AddStream(
2144 receiving_client()->remote_streams()->at(0));
2145 receiving_client()->Negotiate();
2146
2147 EXPECT_TRUE_WAIT(
2148 initializing_client()->VideoFramesReceivedCheck(kEndVideoFrameCount),
2149 kMaxWaitForFramesMs);
2150}
2151
deadbeef0a6c4ca2015-10-06 11:38:28 -07002152class IceServerParsingTest : public testing::Test {
2153 public:
2154 // Convenience for parsing a single URL.
2155 bool ParseUrl(const std::string& url) {
2156 return ParseUrl(url, std::string(), std::string());
2157 }
2158
2159 bool ParseUrl(const std::string& url,
2160 const std::string& username,
2161 const std::string& password) {
2162 PeerConnectionInterface::IceServers servers;
2163 PeerConnectionInterface::IceServer server;
2164 server.urls.push_back(url);
2165 server.username = username;
2166 server.password = password;
2167 servers.push_back(server);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002168 return webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_);
deadbeef0a6c4ca2015-10-06 11:38:28 -07002169 }
2170
2171 protected:
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002172 cricket::ServerAddresses stun_servers_;
2173 std::vector<cricket::RelayServerConfig> turn_servers_;
deadbeef0a6c4ca2015-10-06 11:38:28 -07002174};
2175
2176// Make sure all STUN/TURN prefixes are parsed correctly.
2177TEST_F(IceServerParsingTest, ParseStunPrefixes) {
2178 EXPECT_TRUE(ParseUrl("stun:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002179 EXPECT_EQ(1U, stun_servers_.size());
2180 EXPECT_EQ(0U, turn_servers_.size());
2181 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002182
2183 EXPECT_TRUE(ParseUrl("stuns:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002184 EXPECT_EQ(1U, stun_servers_.size());
2185 EXPECT_EQ(0U, turn_servers_.size());
2186 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002187
2188 EXPECT_TRUE(ParseUrl("turn:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002189 EXPECT_EQ(0U, stun_servers_.size());
2190 EXPECT_EQ(1U, turn_servers_.size());
2191 EXPECT_FALSE(turn_servers_[0].ports[0].secure);
2192 turn_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002193
2194 EXPECT_TRUE(ParseUrl("turns:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002195 EXPECT_EQ(0U, stun_servers_.size());
2196 EXPECT_EQ(1U, turn_servers_.size());
2197 EXPECT_TRUE(turn_servers_[0].ports[0].secure);
2198 turn_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002199
2200 // invalid prefixes
2201 EXPECT_FALSE(ParseUrl("stunn:hostname"));
2202 EXPECT_FALSE(ParseUrl(":hostname"));
2203 EXPECT_FALSE(ParseUrl(":"));
2204 EXPECT_FALSE(ParseUrl(""));
2205}
2206
2207TEST_F(IceServerParsingTest, VerifyDefaults) {
2208 // TURNS defaults
2209 EXPECT_TRUE(ParseUrl("turns:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002210 EXPECT_EQ(1U, turn_servers_.size());
2211 EXPECT_EQ(5349, turn_servers_[0].ports[0].address.port());
2212 EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto);
2213 turn_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002214
2215 // TURN defaults
2216 EXPECT_TRUE(ParseUrl("turn:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002217 EXPECT_EQ(1U, turn_servers_.size());
2218 EXPECT_EQ(3478, turn_servers_[0].ports[0].address.port());
2219 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto);
2220 turn_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002221
2222 // STUN defaults
2223 EXPECT_TRUE(ParseUrl("stun:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002224 EXPECT_EQ(1U, stun_servers_.size());
2225 EXPECT_EQ(3478, stun_servers_.begin()->port());
2226 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002227}
2228
2229// Check that the 6 combinations of IPv4/IPv6/hostname and with/without port
2230// can be parsed correctly.
2231TEST_F(IceServerParsingTest, ParseHostnameAndPort) {
2232 EXPECT_TRUE(ParseUrl("stun:1.2.3.4:1234"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002233 EXPECT_EQ(1U, stun_servers_.size());
2234 EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname());
2235 EXPECT_EQ(1234, stun_servers_.begin()->port());
2236 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002237
2238 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]:4321"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002239 EXPECT_EQ(1U, stun_servers_.size());
2240 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname());
2241 EXPECT_EQ(4321, stun_servers_.begin()->port());
2242 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002243
2244 EXPECT_TRUE(ParseUrl("stun:hostname:9999"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002245 EXPECT_EQ(1U, stun_servers_.size());
2246 EXPECT_EQ("hostname", stun_servers_.begin()->hostname());
2247 EXPECT_EQ(9999, stun_servers_.begin()->port());
2248 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002249
2250 EXPECT_TRUE(ParseUrl("stun:1.2.3.4"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002251 EXPECT_EQ(1U, stun_servers_.size());
2252 EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname());
2253 EXPECT_EQ(3478, stun_servers_.begin()->port());
2254 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002255
2256 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002257 EXPECT_EQ(1U, stun_servers_.size());
2258 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname());
2259 EXPECT_EQ(3478, stun_servers_.begin()->port());
2260 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002261
2262 EXPECT_TRUE(ParseUrl("stun:hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002263 EXPECT_EQ(1U, stun_servers_.size());
2264 EXPECT_EQ("hostname", stun_servers_.begin()->hostname());
2265 EXPECT_EQ(3478, stun_servers_.begin()->port());
2266 stun_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002267
2268 // Try some invalid hostname:port strings.
2269 EXPECT_FALSE(ParseUrl("stun:hostname:99a99"));
2270 EXPECT_FALSE(ParseUrl("stun:hostname:-1"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002271 EXPECT_FALSE(ParseUrl("stun:hostname:port:more"));
2272 EXPECT_FALSE(ParseUrl("stun:hostname:port more"));
deadbeef0a6c4ca2015-10-06 11:38:28 -07002273 EXPECT_FALSE(ParseUrl("stun:hostname:"));
2274 EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000"));
2275 EXPECT_FALSE(ParseUrl("stun::5555"));
2276 EXPECT_FALSE(ParseUrl("stun:"));
2277}
2278
2279// Test parsing the "?transport=xxx" part of the URL.
2280TEST_F(IceServerParsingTest, ParseTransport) {
2281 EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002282 EXPECT_EQ(1U, turn_servers_.size());
2283 EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto);
2284 turn_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002285
2286 EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002287 EXPECT_EQ(1U, turn_servers_.size());
2288 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto);
2289 turn_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002290
2291 EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid"));
2292}
2293
2294// Test parsing ICE username contained in URL.
2295TEST_F(IceServerParsingTest, ParseUsername) {
2296 EXPECT_TRUE(ParseUrl("turn:user@hostname"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002297 EXPECT_EQ(1U, turn_servers_.size());
2298 EXPECT_EQ("user", turn_servers_[0].credentials.username);
2299 turn_servers_.clear();
deadbeef0a6c4ca2015-10-06 11:38:28 -07002300
2301 EXPECT_FALSE(ParseUrl("turn:@hostname"));
2302 EXPECT_FALSE(ParseUrl("turn:username@"));
2303 EXPECT_FALSE(ParseUrl("turn:@"));
2304 EXPECT_FALSE(ParseUrl("turn:user@name@hostname"));
2305}
2306
2307// Test that username and password from IceServer is copied into the resulting
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002308// RelayServerConfig.
deadbeef0a6c4ca2015-10-06 11:38:28 -07002309TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) {
2310 EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password"));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002311 EXPECT_EQ(1U, turn_servers_.size());
2312 EXPECT_EQ("username", turn_servers_[0].credentials.username);
2313 EXPECT_EQ("password", turn_servers_[0].credentials.password);
deadbeef0a6c4ca2015-10-06 11:38:28 -07002314}
2315
2316// Ensure that if a server has multiple URLs, each one is parsed.
2317TEST_F(IceServerParsingTest, ParseMultipleUrls) {
2318 PeerConnectionInterface::IceServers servers;
2319 PeerConnectionInterface::IceServer server;
2320 server.urls.push_back("stun:hostname");
2321 server.urls.push_back("turn:hostname");
2322 servers.push_back(server);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002323 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
2324 EXPECT_EQ(1U, stun_servers_.size());
2325 EXPECT_EQ(1U, turn_servers_.size());
deadbeef0a6c4ca2015-10-06 11:38:28 -07002326}
2327
Taylor Brandstetter893505d2016-01-07 15:12:48 -08002328// Ensure that TURN servers are given unique priorities,
2329// so that their resulting candidates have unique priorities.
2330TEST_F(IceServerParsingTest, TurnServerPrioritiesUnique) {
2331 PeerConnectionInterface::IceServers servers;
2332 PeerConnectionInterface::IceServer server;
2333 server.urls.push_back("turn:hostname");
2334 server.urls.push_back("turn:hostname2");
2335 servers.push_back(server);
2336 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
2337 EXPECT_EQ(2U, turn_servers_.size());
2338 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority);
2339}
2340
kjellander@webrtc.orgd1cfa712013-10-16 16:51:52 +00002341#endif // if !defined(THREAD_SANITIZER)
hta6b4f8392016-03-10 00:24:31 -08002342
2343} // namespace