blob: a12786980e9940c4461ca9dabfc35ca611547c2e [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <stdio.h>
29
30#include <algorithm>
31#include <list>
32#include <map>
kwiberg0eb15ed2015-12-17 03:04:15 -080033#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034#include <vector>
35
36#include "talk/app/webrtc/dtmfsender.h"
jbauchac8869e2015-07-03 01:36:14 -070037#include "talk/app/webrtc/fakemetricsobserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038#include "talk/app/webrtc/fakeportallocatorfactory.h"
39#include "talk/app/webrtc/localaudiosource.h"
40#include "talk/app/webrtc/mediastreaminterface.h"
deadbeef0a6c4ca2015-10-06 11:38:28 -070041#include "talk/app/webrtc/peerconnection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042#include "talk/app/webrtc/peerconnectionfactory.h"
43#include "talk/app/webrtc/peerconnectioninterface.h"
44#include "talk/app/webrtc/test/fakeaudiocapturemodule.h"
45#include "talk/app/webrtc/test/fakeconstraints.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020046#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047#include "talk/app/webrtc/test/fakeperiodicvideocapturer.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000048#include "talk/app/webrtc/test/fakevideotrackrenderer.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049#include "talk/app/webrtc/test/mockpeerconnectionobservers.h"
50#include "talk/app/webrtc/videosourceinterface.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000051#include "talk/media/webrtc/fakewebrtcvideoengine.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000052#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000053#include "webrtc/base/gunit.h"
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +000054#include "webrtc/base/physicalsocketserver.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000055#include "webrtc/base/scoped_ptr.h"
56#include "webrtc/base/ssladapter.h"
57#include "webrtc/base/sslstreamadapter.h"
58#include "webrtc/base/thread.h"
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +000059#include "webrtc/base/virtualsocketserver.h"
60#include "webrtc/p2p/base/constants.h"
61#include "webrtc/p2p/base/sessiondescription.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062
63#define MAYBE_SKIP_TEST(feature) \
64 if (!(feature())) { \
65 LOG(LS_INFO) << "Feature disabled... skipping"; \
66 return; \
67 }
68
69using cricket::ContentInfo;
70using cricket::FakeWebRtcVideoDecoder;
71using cricket::FakeWebRtcVideoDecoderFactory;
72using cricket::FakeWebRtcVideoEncoder;
73using cricket::FakeWebRtcVideoEncoderFactory;
74using cricket::MediaContentDescription;
75using webrtc::DataBuffer;
76using webrtc::DataChannelInterface;
77using webrtc::DtmfSender;
78using webrtc::DtmfSenderInterface;
79using webrtc::DtmfSenderObserverInterface;
80using webrtc::FakeConstraints;
81using webrtc::MediaConstraintsInterface;
deadbeeffaac4972015-11-12 15:33:07 -080082using webrtc::MediaStreamInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083using webrtc::MediaStreamTrackInterface;
84using webrtc::MockCreateSessionDescriptionObserver;
85using webrtc::MockDataChannelObserver;
86using webrtc::MockSetSessionDescriptionObserver;
87using webrtc::MockStatsObserver;
deadbeeffaac4972015-11-12 15:33:07 -080088using webrtc::ObserverInterface;
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +000089using webrtc::PeerConnectionInterface;
Joachim Bauch04e5b492015-05-29 09:40:39 +020090using webrtc::PeerConnectionFactory;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091using webrtc::SessionDescriptionInterface;
92using webrtc::StreamCollectionInterface;
93
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000094static const int kMaxWaitMs = 10000;
pbos@webrtc.org044bdac2014-06-03 09:40:01 +000095// Disable for TSan v2, see
96// https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
97// This declaration is also #ifdef'd as it causes uninitialized-variable
98// warnings.
99#if !defined(THREAD_SANITIZER)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100static const int kMaxWaitForStatsMs = 3000;
pbos@webrtc.org044bdac2014-06-03 09:40:01 +0000101#endif
deadbeeffac06552015-11-25 11:26:01 -0800102static const int kMaxWaitForActivationMs = 5000;
buildbot@webrtc.org3e01e0b2014-05-13 17:54:10 +0000103static const int kMaxWaitForFramesMs = 10000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104static const int kEndAudioFrameCount = 3;
105static const int kEndVideoFrameCount = 3;
106
107static const char kStreamLabelBase[] = "stream_label";
108static const char kVideoTrackLabelBase[] = "video_track";
109static const char kAudioTrackLabelBase[] = "audio_track";
110static const char kDataChannelLabel[] = "data_channel";
111
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000112// Disable for TSan v2, see
113// https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
114// This declaration is also #ifdef'd as it causes unused-variable errors.
115#if !defined(THREAD_SANITIZER)
116// SRTP cipher name negotiated by the tests. This must be updated if the
117// default changes.
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800118static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32;
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000119#endif
120
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121static void RemoveLinesFromSdp(const std::string& line_start,
122 std::string* sdp) {
123 const char kSdpLineEnd[] = "\r\n";
124 size_t ssrc_pos = 0;
125 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) !=
126 std::string::npos) {
127 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos);
128 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd));
129 }
130}
131
132class SignalingMessageReceiver {
133 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000134 virtual void ReceiveSdpMessage(const std::string& type,
135 std::string& msg) = 0;
136 virtual void ReceiveIceMessage(const std::string& sdp_mid,
137 int sdp_mline_index,
138 const std::string& msg) = 0;
139
140 protected:
deadbeefaf1b59c2015-10-15 12:08:41 -0700141 SignalingMessageReceiver() {}
142 virtual ~SignalingMessageReceiver() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143};
144
deadbeefaf1b59c2015-10-15 12:08:41 -0700145class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
deadbeeffaac4972015-11-12 15:33:07 -0800146 public SignalingMessageReceiver,
147 public ObserverInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148 public:
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800149 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore(
Guo-wei Shieh9c38c2d2015-12-05 09:46:07 -0800150 const std::string& id,
151 const MediaConstraintsInterface* constraints,
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800152 const PeerConnectionFactory::Options* options,
153 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
Guo-wei Shieh86aaa4b2015-12-05 09:55:44 -0800154 PeerConnectionTestClient* client(new PeerConnectionTestClient(id));
kwiberg0eb15ed2015-12-17 03:04:15 -0800155 if (!client->Init(constraints, options, std::move(dtls_identity_store))) {
Guo-wei Shieh86aaa4b2015-12-05 09:55:44 -0800156 delete client;
157 return nullptr;
158 }
159 return client;
Guo-wei Shieh9c38c2d2015-12-05 09:46:07 -0800160 }
161
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800162 static PeerConnectionTestClient* CreateClient(
163 const std::string& id,
164 const MediaConstraintsInterface* constraints,
165 const PeerConnectionFactory::Options* options) {
166 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
167 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore()
168 : nullptr);
169
170 return CreateClientWithDtlsIdentityStore(id, constraints, options,
kwiberg0eb15ed2015-12-17 03:04:15 -0800171 std::move(dtls_identity_store));
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800172 }
173
deadbeefaf1b59c2015-10-15 12:08:41 -0700174 ~PeerConnectionTestClient() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175 }
176
deadbeefaf1b59c2015-10-15 12:08:41 -0700177 void Negotiate() { Negotiate(true, true); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178
deadbeefaf1b59c2015-10-15 12:08:41 -0700179 void Negotiate(bool audio, bool video) {
180 rtc::scoped_ptr<SessionDescriptionInterface> offer;
181 ASSERT_TRUE(DoCreateOffer(offer.use()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182
deadbeefaf1b59c2015-10-15 12:08:41 -0700183 if (offer->description()->GetContentByName("audio")) {
184 offer->description()->GetContentByName("audio")->rejected = !audio;
185 }
186 if (offer->description()->GetContentByName("video")) {
187 offer->description()->GetContentByName("video")->rejected = !video;
188 }
189
190 std::string sdp;
191 EXPECT_TRUE(offer->ToString(&sdp));
192 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
193 signaling_message_receiver_->ReceiveSdpMessage(
194 webrtc::SessionDescriptionInterface::kOffer, sdp);
195 }
196
197 // SignalingMessageReceiver callback.
198 void ReceiveSdpMessage(const std::string& type, std::string& msg) override {
199 FilterIncomingSdpMessage(&msg);
200 if (type == webrtc::SessionDescriptionInterface::kOffer) {
201 HandleIncomingOffer(msg);
202 } else {
203 HandleIncomingAnswer(msg);
204 }
205 }
206
207 // SignalingMessageReceiver callback.
208 void ReceiveIceMessage(const std::string& sdp_mid,
209 int sdp_mline_index,
210 const std::string& msg) override {
211 LOG(INFO) << id_ << "ReceiveIceMessage";
212 rtc::scoped_ptr<webrtc::IceCandidateInterface> candidate(
213 webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, msg, nullptr));
214 EXPECT_TRUE(pc()->AddIceCandidate(candidate.get()));
215 }
216
217 // PeerConnectionObserver callbacks.
218 void OnSignalingChange(
219 webrtc::PeerConnectionInterface::SignalingState new_state) override {
220 EXPECT_EQ(pc()->signaling_state(), new_state);
221 }
deadbeeffaac4972015-11-12 15:33:07 -0800222 void OnAddStream(MediaStreamInterface* media_stream) override {
223 media_stream->RegisterObserver(this);
deadbeefaf1b59c2015-10-15 12:08:41 -0700224 for (size_t i = 0; i < media_stream->GetVideoTracks().size(); ++i) {
225 const std::string id = media_stream->GetVideoTracks()[i]->id();
226 ASSERT_TRUE(fake_video_renderers_.find(id) ==
227 fake_video_renderers_.end());
deadbeefc9be0072015-12-14 18:27:57 -0800228 fake_video_renderers_[id].reset(new webrtc::FakeVideoTrackRenderer(
229 media_stream->GetVideoTracks()[i]));
deadbeefaf1b59c2015-10-15 12:08:41 -0700230 }
231 }
deadbeeffaac4972015-11-12 15:33:07 -0800232 void OnRemoveStream(MediaStreamInterface* media_stream) override {}
deadbeefaf1b59c2015-10-15 12:08:41 -0700233 void OnRenegotiationNeeded() override {}
234 void OnIceConnectionChange(
235 webrtc::PeerConnectionInterface::IceConnectionState new_state) override {
236 EXPECT_EQ(pc()->ice_connection_state(), new_state);
237 }
238 void OnIceGatheringChange(
239 webrtc::PeerConnectionInterface::IceGatheringState new_state) override {
240 EXPECT_EQ(pc()->ice_gathering_state(), new_state);
241 }
242 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
243 LOG(INFO) << id_ << "OnIceCandidate";
244
245 std::string ice_sdp;
246 EXPECT_TRUE(candidate->ToString(&ice_sdp));
247 if (signaling_message_receiver_ == nullptr) {
248 // Remote party may be deleted.
249 return;
250 }
251 signaling_message_receiver_->ReceiveIceMessage(
252 candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp);
253 }
254
deadbeeffaac4972015-11-12 15:33:07 -0800255 // MediaStreamInterface callback
256 void OnChanged() override {
257 // Track added or removed from MediaStream, so update our renderers.
258 rtc::scoped_refptr<StreamCollectionInterface> remote_streams =
259 pc()->remote_streams();
260 // Remove renderers for tracks that were removed.
261 for (auto it = fake_video_renderers_.begin();
262 it != fake_video_renderers_.end();) {
263 if (remote_streams->FindVideoTrack(it->first) == nullptr) {
deadbeefc9be0072015-12-14 18:27:57 -0800264 auto to_remove = it++;
265 removed_fake_video_renderers_.push_back(std::move(to_remove->second));
266 fake_video_renderers_.erase(to_remove);
deadbeeffaac4972015-11-12 15:33:07 -0800267 } else {
268 ++it;
269 }
270 }
271 // Create renderers for new video tracks.
272 for (size_t stream_index = 0; stream_index < remote_streams->count();
273 ++stream_index) {
274 MediaStreamInterface* remote_stream = remote_streams->at(stream_index);
275 for (size_t track_index = 0;
276 track_index < remote_stream->GetVideoTracks().size();
277 ++track_index) {
278 const std::string id =
279 remote_stream->GetVideoTracks()[track_index]->id();
280 if (fake_video_renderers_.find(id) != fake_video_renderers_.end()) {
281 continue;
282 }
deadbeefc9be0072015-12-14 18:27:57 -0800283 fake_video_renderers_[id].reset(new webrtc::FakeVideoTrackRenderer(
284 remote_stream->GetVideoTracks()[track_index]));
deadbeeffaac4972015-11-12 15:33:07 -0800285 }
286 }
287 }
288
deadbeefaf1b59c2015-10-15 12:08:41 -0700289 void SetVideoConstraints(const webrtc::FakeConstraints& video_constraint) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290 video_constraints_ = video_constraint;
291 }
292
293 void AddMediaStream(bool audio, bool video) {
deadbeefaf1b59c2015-10-15 12:08:41 -0700294 std::string stream_label =
295 kStreamLabelBase +
296 rtc::ToString<int>(static_cast<int>(pc()->local_streams()->count()));
deadbeeffaac4972015-11-12 15:33:07 -0800297 rtc::scoped_refptr<MediaStreamInterface> stream =
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000298 peer_connection_factory_->CreateLocalMediaStream(stream_label);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299
300 if (audio && can_receive_audio()) {
deadbeeffac06552015-11-25 11:26:01 -0800301 stream->AddTrack(CreateLocalAudioTrack(stream_label));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 }
303 if (video && can_receive_video()) {
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000304 stream->AddTrack(CreateLocalVideoTrack(stream_label));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 }
306
deadbeefaf1b59c2015-10-15 12:08:41 -0700307 EXPECT_TRUE(pc()->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 }
309
deadbeefaf1b59c2015-10-15 12:08:41 -0700310 size_t NumberOfLocalMediaStreams() { return pc()->local_streams()->count(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311
312 bool SessionActive() {
deadbeefaf1b59c2015-10-15 12:08:41 -0700313 return pc()->signaling_state() == webrtc::PeerConnectionInterface::kStable;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314 }
315
deadbeeffaac4972015-11-12 15:33:07 -0800316 // Automatically add a stream when receiving an offer, if we don't have one.
317 // Defaults to true.
318 void set_auto_add_stream(bool auto_add_stream) {
319 auto_add_stream_ = auto_add_stream;
320 }
321
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 void set_signaling_message_receiver(
deadbeefaf1b59c2015-10-15 12:08:41 -0700323 SignalingMessageReceiver* signaling_message_receiver) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 signaling_message_receiver_ = signaling_message_receiver;
325 }
326
327 void EnableVideoDecoderFactory() {
328 video_decoder_factory_enabled_ = true;
329 fake_video_decoder_factory_->AddSupportedVideoCodecType(
330 webrtc::kVideoCodecVP8);
331 }
332
deadbeefaf1b59c2015-10-15 12:08:41 -0700333 void IceRestart() {
334 session_description_constraints_.SetMandatoryIceRestart(true);
335 SetExpectIceRestart(true);
336 }
337
338 void SetExpectIceRestart(bool expect_restart) {
339 expect_ice_restart_ = expect_restart;
340 }
341
342 bool ExpectIceRestart() const { return expect_ice_restart_; }
343
344 void SetReceiveAudioVideo(bool audio, bool video) {
345 SetReceiveAudio(audio);
346 SetReceiveVideo(video);
347 ASSERT_EQ(audio, can_receive_audio());
348 ASSERT_EQ(video, can_receive_video());
349 }
350
351 void SetReceiveAudio(bool audio) {
352 if (audio && can_receive_audio())
353 return;
354 session_description_constraints_.SetMandatoryReceiveAudio(audio);
355 }
356
357 void SetReceiveVideo(bool video) {
358 if (video && can_receive_video())
359 return;
360 session_description_constraints_.SetMandatoryReceiveVideo(video);
361 }
362
363 void RemoveMsidFromReceivedSdp(bool remove) { remove_msid_ = remove; }
364
365 void RemoveSdesCryptoFromReceivedSdp(bool remove) { remove_sdes_ = remove; }
366
367 void RemoveBundleFromReceivedSdp(bool remove) { remove_bundle_ = remove; }
368
369 bool can_receive_audio() {
370 bool value;
371 if (webrtc::FindConstraint(&session_description_constraints_,
372 MediaConstraintsInterface::kOfferToReceiveAudio,
373 &value, nullptr)) {
374 return value;
375 }
376 return true;
377 }
378
379 bool can_receive_video() {
380 bool value;
381 if (webrtc::FindConstraint(&session_description_constraints_,
382 MediaConstraintsInterface::kOfferToReceiveVideo,
383 &value, nullptr)) {
384 return value;
385 }
386 return true;
387 }
388
389 void OnIceComplete() override { LOG(INFO) << id_ << "OnIceComplete"; }
390
391 void OnDataChannel(DataChannelInterface* data_channel) override {
392 LOG(INFO) << id_ << "OnDataChannel";
393 data_channel_ = data_channel;
394 data_observer_.reset(new MockDataChannelObserver(data_channel));
395 }
396
397 void CreateDataChannel() {
398 data_channel_ = pc()->CreateDataChannel(kDataChannelLabel, nullptr);
399 ASSERT_TRUE(data_channel_.get() != nullptr);
400 data_observer_.reset(new MockDataChannelObserver(data_channel_));
401 }
402
deadbeeffac06552015-11-25 11:26:01 -0800403 rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack(
404 const std::string& stream_label) {
405 FakeConstraints constraints;
406 // Disable highpass filter so that we can get all the test audio frames.
407 constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false);
408 rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
409 peer_connection_factory_->CreateAudioSource(&constraints);
410 // TODO(perkj): Test audio source when it is implemented. Currently audio
411 // always use the default input.
412 std::string label = stream_label + kAudioTrackLabelBase;
413 return peer_connection_factory_->CreateAudioTrack(label, source);
414 }
415
416 rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack(
417 const std::string& stream_label) {
418 // Set max frame rate to 10fps to reduce the risk of the tests to be flaky.
419 FakeConstraints source_constraints = video_constraints_;
420 source_constraints.SetMandatoryMaxFrameRate(10);
421
422 cricket::FakeVideoCapturer* fake_capturer =
423 new webrtc::FakePeriodicVideoCapturer();
424 video_capturers_.push_back(fake_capturer);
425 rtc::scoped_refptr<webrtc::VideoSourceInterface> source =
426 peer_connection_factory_->CreateVideoSource(fake_capturer,
427 &source_constraints);
428 std::string label = stream_label + kVideoTrackLabelBase;
429 return peer_connection_factory_->CreateVideoTrack(label, source);
430 }
431
deadbeefaf1b59c2015-10-15 12:08:41 -0700432 DataChannelInterface* data_channel() { return data_channel_; }
433 const MockDataChannelObserver* data_observer() const {
434 return data_observer_.get();
435 }
436
437 webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); }
438
439 void StopVideoCapturers() {
440 for (std::vector<cricket::VideoCapturer*>::iterator it =
441 video_capturers_.begin();
442 it != video_capturers_.end(); ++it) {
443 (*it)->Stop();
444 }
445 }
446
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447 bool AudioFramesReceivedCheck(int number_of_frames) const {
448 return number_of_frames <= fake_audio_capture_module_->frames_received();
449 }
450
deadbeefc9be0072015-12-14 18:27:57 -0800451 int audio_frames_received() const {
452 return fake_audio_capture_module_->frames_received();
453 }
454
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455 bool VideoFramesReceivedCheck(int number_of_frames) {
456 if (video_decoder_factory_enabled_) {
457 const std::vector<FakeWebRtcVideoDecoder*>& decoders
458 = fake_video_decoder_factory_->decoders();
459 if (decoders.empty()) {
460 return number_of_frames <= 0;
461 }
462
deadbeefc9be0072015-12-14 18:27:57 -0800463 for (FakeWebRtcVideoDecoder* decoder : decoders) {
464 if (number_of_frames > decoder->GetNumFramesReceived()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465 return false;
466 }
467 }
468 return true;
469 } else {
470 if (fake_video_renderers_.empty()) {
471 return number_of_frames <= 0;
472 }
473
deadbeefc9be0072015-12-14 18:27:57 -0800474 for (const auto& pair : fake_video_renderers_) {
475 if (number_of_frames > pair.second->num_rendered_frames()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000476 return false;
477 }
478 }
479 return true;
480 }
481 }
deadbeefaf1b59c2015-10-15 12:08:41 -0700482
deadbeefc9be0072015-12-14 18:27:57 -0800483 int video_frames_received() const {
484 int total = 0;
485 if (video_decoder_factory_enabled_) {
486 const std::vector<FakeWebRtcVideoDecoder*>& decoders =
487 fake_video_decoder_factory_->decoders();
488 for (const FakeWebRtcVideoDecoder* decoder : decoders) {
489 total += decoder->GetNumFramesReceived();
490 }
491 } else {
492 for (const auto& pair : fake_video_renderers_) {
493 total += pair.second->num_rendered_frames();
494 }
495 for (const auto& renderer : removed_fake_video_renderers_) {
496 total += renderer->num_rendered_frames();
497 }
498 }
499 return total;
500 }
501
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 // Verify the CreateDtmfSender interface
503 void VerifyDtmf() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000504 rtc::scoped_ptr<DummyDtmfObserver> observer(new DummyDtmfObserver());
505 rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000506
507 // We can't create a DTMF sender with an invalid audio track or a non local
508 // track.
deadbeefaf1b59c2015-10-15 12:08:41 -0700509 EXPECT_TRUE(peer_connection_->CreateDtmfSender(nullptr) == nullptr);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000510 rtc::scoped_refptr<webrtc::AudioTrackInterface> non_localtrack(
deadbeefaf1b59c2015-10-15 12:08:41 -0700511 peer_connection_factory_->CreateAudioTrack("dummy_track", nullptr));
512 EXPECT_TRUE(peer_connection_->CreateDtmfSender(non_localtrack) == nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000513
514 // We should be able to create a DTMF sender from a local track.
515 webrtc::AudioTrackInterface* localtrack =
516 peer_connection_->local_streams()->at(0)->GetAudioTracks()[0];
517 dtmf_sender = peer_connection_->CreateDtmfSender(localtrack);
deadbeefaf1b59c2015-10-15 12:08:41 -0700518 EXPECT_TRUE(dtmf_sender.get() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 dtmf_sender->RegisterObserver(observer.get());
520
521 // Test the DtmfSender object just created.
522 EXPECT_TRUE(dtmf_sender->CanInsertDtmf());
523 EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50));
524
525 // We don't need to verify that the DTMF tones are actually sent out because
526 // that is already covered by the tests of the lower level components.
527
528 EXPECT_TRUE_WAIT(observer->completed(), kMaxWaitMs);
529 std::vector<std::string> tones;
530 tones.push_back("1");
531 tones.push_back("a");
532 tones.push_back("");
533 observer->Verify(tones);
534
535 dtmf_sender->UnregisterObserver();
536 }
537
538 // Verifies that the SessionDescription have rejected the appropriate media
539 // content.
540 void VerifyRejectedMediaInSessionDescription() {
deadbeefaf1b59c2015-10-15 12:08:41 -0700541 ASSERT_TRUE(peer_connection_->remote_description() != nullptr);
542 ASSERT_TRUE(peer_connection_->local_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000543 const cricket::SessionDescription* remote_desc =
544 peer_connection_->remote_description()->description();
545 const cricket::SessionDescription* local_desc =
546 peer_connection_->local_description()->description();
547
548 const ContentInfo* remote_audio_content = GetFirstAudioContent(remote_desc);
549 if (remote_audio_content) {
550 const ContentInfo* audio_content =
551 GetFirstAudioContent(local_desc);
552 EXPECT_EQ(can_receive_audio(), !audio_content->rejected);
553 }
554
555 const ContentInfo* remote_video_content = GetFirstVideoContent(remote_desc);
556 if (remote_video_content) {
557 const ContentInfo* video_content =
558 GetFirstVideoContent(local_desc);
559 EXPECT_EQ(can_receive_video(), !video_content->rejected);
560 }
561 }
562
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000563 void VerifyLocalIceUfragAndPassword() {
deadbeefaf1b59c2015-10-15 12:08:41 -0700564 ASSERT_TRUE(peer_connection_->local_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 const cricket::SessionDescription* desc =
566 peer_connection_->local_description()->description();
567 const cricket::ContentInfos& contents = desc->contents();
568
569 for (size_t index = 0; index < contents.size(); ++index) {
570 if (contents[index].rejected)
571 continue;
572 const cricket::TransportDescription* transport_desc =
573 desc->GetTransportDescriptionByName(contents[index].name);
574
575 std::map<int, IceUfragPwdPair>::const_iterator ufragpair_it =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000576 ice_ufrag_pwd_.find(static_cast<int>(index));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000577 if (ufragpair_it == ice_ufrag_pwd_.end()) {
578 ASSERT_FALSE(ExpectIceRestart());
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000579 ice_ufrag_pwd_[static_cast<int>(index)] =
580 IceUfragPwdPair(transport_desc->ice_ufrag, transport_desc->ice_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581 } else if (ExpectIceRestart()) {
582 const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second;
583 EXPECT_NE(ufrag_pwd.first, transport_desc->ice_ufrag);
584 EXPECT_NE(ufrag_pwd.second, transport_desc->ice_pwd);
585 } else {
586 const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second;
587 EXPECT_EQ(ufrag_pwd.first, transport_desc->ice_ufrag);
588 EXPECT_EQ(ufrag_pwd.second, transport_desc->ice_pwd);
589 }
590 }
591 }
592
593 int GetAudioOutputLevelStats(webrtc::MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000594 rtc::scoped_refptr<MockStatsObserver>
595 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000596 EXPECT_TRUE(peer_connection_->GetStats(
597 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000598 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700599 EXPECT_NE(0, observer->timestamp());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000600 return observer->AudioOutputLevel();
601 }
602
603 int GetAudioInputLevelStats() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000604 rtc::scoped_refptr<MockStatsObserver>
605 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000606 EXPECT_TRUE(peer_connection_->GetStats(
deadbeefaf1b59c2015-10-15 12:08:41 -0700607 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000608 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700609 EXPECT_NE(0, observer->timestamp());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610 return observer->AudioInputLevel();
611 }
612
613 int GetBytesReceivedStats(webrtc::MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000614 rtc::scoped_refptr<MockStatsObserver>
615 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000616 EXPECT_TRUE(peer_connection_->GetStats(
617 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700619 EXPECT_NE(0, observer->timestamp());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000620 return observer->BytesReceived();
621 }
622
623 int GetBytesSentStats(webrtc::MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000624 rtc::scoped_refptr<MockStatsObserver>
625 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000626 EXPECT_TRUE(peer_connection_->GetStats(
627 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000628 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700629 EXPECT_NE(0, observer->timestamp());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630 return observer->BytesSent();
631 }
632
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000633 int GetAvailableReceivedBandwidthStats() {
634 rtc::scoped_refptr<MockStatsObserver>
635 observer(new rtc::RefCountedObject<MockStatsObserver>());
636 EXPECT_TRUE(peer_connection_->GetStats(
deadbeefaf1b59c2015-10-15 12:08:41 -0700637 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard));
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000638 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700639 EXPECT_NE(0, observer->timestamp());
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000640 int bw = observer->AvailableReceiveBandwidth();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000641 return bw;
642 }
643
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000644 std::string GetDtlsCipherStats() {
645 rtc::scoped_refptr<MockStatsObserver>
646 observer(new rtc::RefCountedObject<MockStatsObserver>());
647 EXPECT_TRUE(peer_connection_->GetStats(
deadbeefaf1b59c2015-10-15 12:08:41 -0700648 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard));
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000649 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700650 EXPECT_NE(0, observer->timestamp());
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000651 return observer->DtlsCipher();
652 }
653
654 std::string GetSrtpCipherStats() {
655 rtc::scoped_refptr<MockStatsObserver>
656 observer(new rtc::RefCountedObject<MockStatsObserver>());
657 EXPECT_TRUE(peer_connection_->GetStats(
deadbeefaf1b59c2015-10-15 12:08:41 -0700658 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard));
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000659 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
jbauchbe24c942015-06-22 15:06:43 -0700660 EXPECT_NE(0, observer->timestamp());
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000661 return observer->SrtpCipher();
662 }
663
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664 int rendered_width() {
665 EXPECT_FALSE(fake_video_renderers_.empty());
666 return fake_video_renderers_.empty() ? 1 :
667 fake_video_renderers_.begin()->second->width();
668 }
669
670 int rendered_height() {
671 EXPECT_FALSE(fake_video_renderers_.empty());
672 return fake_video_renderers_.empty() ? 1 :
673 fake_video_renderers_.begin()->second->height();
674 }
675
676 size_t number_of_remote_streams() {
677 if (!pc())
678 return 0;
679 return pc()->remote_streams()->count();
680 }
681
682 StreamCollectionInterface* remote_streams() {
683 if (!pc()) {
684 ADD_FAILURE();
deadbeefaf1b59c2015-10-15 12:08:41 -0700685 return nullptr;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 }
687 return pc()->remote_streams();
688 }
689
690 StreamCollectionInterface* local_streams() {
691 if (!pc()) {
692 ADD_FAILURE();
deadbeefaf1b59c2015-10-15 12:08:41 -0700693 return nullptr;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 }
695 return pc()->local_streams();
696 }
697
698 webrtc::PeerConnectionInterface::SignalingState signaling_state() {
699 return pc()->signaling_state();
700 }
701
702 webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() {
703 return pc()->ice_connection_state();
704 }
705
706 webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() {
707 return pc()->ice_gathering_state();
708 }
709
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 private:
711 class DummyDtmfObserver : public DtmfSenderObserverInterface {
712 public:
713 DummyDtmfObserver() : completed_(false) {}
714
715 // Implements DtmfSenderObserverInterface.
deadbeefaf1b59c2015-10-15 12:08:41 -0700716 void OnToneChange(const std::string& tone) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 tones_.push_back(tone);
718 if (tone.empty()) {
719 completed_ = true;
720 }
721 }
722
723 void Verify(const std::vector<std::string>& tones) const {
724 ASSERT_TRUE(tones_.size() == tones.size());
725 EXPECT_TRUE(std::equal(tones.begin(), tones.end(), tones_.begin()));
726 }
727
728 bool completed() const { return completed_; }
729
730 private:
731 bool completed_;
732 std::vector<std::string> tones_;
733 };
734
deadbeefaf1b59c2015-10-15 12:08:41 -0700735 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {}
736
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800737 bool Init(
738 const MediaConstraintsInterface* constraints,
739 const PeerConnectionFactory::Options* options,
740 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
deadbeefaf1b59c2015-10-15 12:08:41 -0700741 EXPECT_TRUE(!peer_connection_);
742 EXPECT_TRUE(!peer_connection_factory_);
743 allocator_factory_ = webrtc::FakePortAllocatorFactory::Create();
744 if (!allocator_factory_) {
745 return false;
746 }
747 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
748
749 if (fake_audio_capture_module_ == nullptr) {
750 return false;
751 }
752 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory();
753 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory();
754 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
755 rtc::Thread::Current(), rtc::Thread::Current(),
756 fake_audio_capture_module_, fake_video_encoder_factory_,
757 fake_video_decoder_factory_);
758 if (!peer_connection_factory_) {
759 return false;
760 }
761 if (options) {
762 peer_connection_factory_->SetOptions(*options);
763 }
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800764 peer_connection_ = CreatePeerConnection(
kwiberg0eb15ed2015-12-17 03:04:15 -0800765 allocator_factory_.get(), constraints, std::move(dtls_identity_store));
deadbeefaf1b59c2015-10-15 12:08:41 -0700766 return peer_connection_.get() != nullptr;
767 }
768
deadbeefaf1b59c2015-10-15 12:08:41 -0700769 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(
770 webrtc::PortAllocatorFactoryInterface* factory,
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800771 const MediaConstraintsInterface* constraints,
772 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773 // CreatePeerConnection with IceServers.
774 webrtc::PeerConnectionInterface::IceServers ice_servers;
775 webrtc::PeerConnectionInterface::IceServer ice_server;
776 ice_server.uri = "stun:stun.l.google.com:19302";
777 ice_servers.push_back(ice_server);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000778
deadbeefaf1b59c2015-10-15 12:08:41 -0700779 return peer_connection_factory_->CreatePeerConnection(
kwiberg0eb15ed2015-12-17 03:04:15 -0800780 ice_servers, constraints, factory, std::move(dtls_identity_store),
781 this);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782 }
783
784 void HandleIncomingOffer(const std::string& msg) {
deadbeefaf1b59c2015-10-15 12:08:41 -0700785 LOG(INFO) << id_ << "HandleIncomingOffer ";
deadbeeffaac4972015-11-12 15:33:07 -0800786 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 // If we are not sending any streams ourselves it is time to add some.
788 AddMediaStream(true, true);
789 }
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000790 rtc::scoped_ptr<SessionDescriptionInterface> desc(
deadbeefaf1b59c2015-10-15 12:08:41 -0700791 webrtc::CreateSessionDescription("offer", msg, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000793 rtc::scoped_ptr<SessionDescriptionInterface> answer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 EXPECT_TRUE(DoCreateAnswer(answer.use()));
795 std::string sdp;
796 EXPECT_TRUE(answer->ToString(&sdp));
797 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
deadbeefaf1b59c2015-10-15 12:08:41 -0700798 if (signaling_message_receiver_) {
799 signaling_message_receiver_->ReceiveSdpMessage(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 webrtc::SessionDescriptionInterface::kAnswer, sdp);
801 }
802 }
803
804 void HandleIncomingAnswer(const std::string& msg) {
deadbeefaf1b59c2015-10-15 12:08:41 -0700805 LOG(INFO) << id_ << "HandleIncomingAnswer";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000806 rtc::scoped_ptr<SessionDescriptionInterface> desc(
deadbeefaf1b59c2015-10-15 12:08:41 -0700807 webrtc::CreateSessionDescription("answer", msg, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
809 }
810
811 bool DoCreateOfferAnswer(SessionDescriptionInterface** desc,
812 bool offer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000813 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
814 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 MockCreateSessionDescriptionObserver>());
816 if (offer) {
817 pc()->CreateOffer(observer, &session_description_constraints_);
818 } else {
819 pc()->CreateAnswer(observer, &session_description_constraints_);
820 }
821 EXPECT_EQ_WAIT(true, observer->called(), kMaxWaitMs);
822 *desc = observer->release_desc();
823 if (observer->result() && ExpectIceRestart()) {
824 EXPECT_EQ(0u, (*desc)->candidates(0)->count());
825 }
826 return observer->result();
827 }
828
829 bool DoCreateOffer(SessionDescriptionInterface** desc) {
830 return DoCreateOfferAnswer(desc, true);
831 }
832
833 bool DoCreateAnswer(SessionDescriptionInterface** desc) {
834 return DoCreateOfferAnswer(desc, false);
835 }
836
837 bool DoSetLocalDescription(SessionDescriptionInterface* desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000838 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
839 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 MockSetSessionDescriptionObserver>());
deadbeefaf1b59c2015-10-15 12:08:41 -0700841 LOG(INFO) << id_ << "SetLocalDescription ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 pc()->SetLocalDescription(observer, desc);
843 // Ignore the observer result. If we wait for the result with
844 // EXPECT_TRUE_WAIT, local ice candidates might be sent to the remote peer
845 // before the offer which is an error.
846 // The reason is that EXPECT_TRUE_WAIT uses
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000847 // rtc::Thread::Current()->ProcessMessages(1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 // ProcessMessages waits at least 1ms but processes all messages before
849 // returning. Since this test is synchronous and send messages to the remote
850 // peer whenever a callback is invoked, this can lead to messages being
851 // sent to the remote peer in the wrong order.
852 // TODO(perkj): Find a way to check the result without risking that the
853 // order of sent messages are changed. Ex- by posting all messages that are
854 // sent to the remote peer.
855 return true;
856 }
857
858 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000859 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
860 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 MockSetSessionDescriptionObserver>());
deadbeefaf1b59c2015-10-15 12:08:41 -0700862 LOG(INFO) << id_ << "SetRemoteDescription ";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 pc()->SetRemoteDescription(observer, desc);
864 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
865 return observer->result();
866 }
867
868 // This modifies all received SDP messages before they are processed.
869 void FilterIncomingSdpMessage(std::string* sdp) {
870 if (remove_msid_) {
871 const char kSdpSsrcAttribute[] = "a=ssrc:";
872 RemoveLinesFromSdp(kSdpSsrcAttribute, sdp);
873 const char kSdpMsidSupportedAttribute[] = "a=msid-semantic:";
874 RemoveLinesFromSdp(kSdpMsidSupportedAttribute, sdp);
875 }
876 if (remove_bundle_) {
877 const char kSdpBundleAttribute[] = "a=group:BUNDLE";
878 RemoveLinesFromSdp(kSdpBundleAttribute, sdp);
879 }
880 if (remove_sdes_) {
881 const char kSdpSdesCryptoAttribute[] = "a=crypto";
882 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp);
883 }
884 }
885
deadbeefaf1b59c2015-10-15 12:08:41 -0700886 std::string id_;
887
888 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> allocator_factory_;
889 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
890 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
891 peer_connection_factory_;
892
deadbeeffaac4972015-11-12 15:33:07 -0800893 bool auto_add_stream_ = true;
894
deadbeefaf1b59c2015-10-15 12:08:41 -0700895 typedef std::pair<std::string, std::string> IceUfragPwdPair;
896 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_;
897 bool expect_ice_restart_ = false;
898
deadbeefc9be0072015-12-14 18:27:57 -0800899 // Needed to keep track of number of frames sent.
deadbeefaf1b59c2015-10-15 12:08:41 -0700900 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
901 // Needed to keep track of number of frames received.
deadbeefc9be0072015-12-14 18:27:57 -0800902 std::map<std::string, rtc::scoped_ptr<webrtc::FakeVideoTrackRenderer>>
903 fake_video_renderers_;
904 // Needed to ensure frames aren't received for removed tracks.
905 std::vector<rtc::scoped_ptr<webrtc::FakeVideoTrackRenderer>>
906 removed_fake_video_renderers_;
deadbeefaf1b59c2015-10-15 12:08:41 -0700907 // Needed to keep track of number of frames received when external decoder
908 // used.
909 FakeWebRtcVideoDecoderFactory* fake_video_decoder_factory_ = nullptr;
910 FakeWebRtcVideoEncoderFactory* fake_video_encoder_factory_ = nullptr;
911 bool video_decoder_factory_enabled_ = false;
912 webrtc::FakeConstraints video_constraints_;
913
914 // For remote peer communication.
915 SignalingMessageReceiver* signaling_message_receiver_ = nullptr;
916
917 // Store references to the video capturers we've created, so that we can stop
918 // them, if required.
919 std::vector<cricket::VideoCapturer*> video_capturers_;
920
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 webrtc::FakeConstraints session_description_constraints_;
deadbeefaf1b59c2015-10-15 12:08:41 -0700922 bool remove_msid_ = false; // True if MSID should be removed in received SDP.
923 bool remove_bundle_ =
924 false; // True if bundle should be removed in received SDP.
925 bool remove_sdes_ =
926 false; // True if a=crypto should be removed in received SDP.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000928 rtc::scoped_refptr<DataChannelInterface> data_channel_;
929 rtc::scoped_ptr<MockDataChannelObserver> data_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930};
931
deadbeef7c73bdb2015-12-10 15:10:44 -0800932class P2PTestConductor : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 public:
deadbeef7c73bdb2015-12-10 15:10:44 -0800934 P2PTestConductor()
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +0000935 : pss_(new rtc::PhysicalSocketServer),
936 ss_(new rtc::VirtualSocketServer(pss_.get())),
937 ss_scope_(ss_.get()) {}
938
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939 bool SessionActive() {
940 return initiating_client_->SessionActive() &&
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +0000941 receiving_client_->SessionActive();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 }
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +0000943
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 // Return true if the number of frames provided have been received or it is
945 // known that that will never occur (e.g. no frames will be sent or
946 // captured).
947 bool FramesNotPending(int audio_frames_to_receive,
948 int video_frames_to_receive) {
949 return VideoFramesReceivedCheck(video_frames_to_receive) &&
950 AudioFramesReceivedCheck(audio_frames_to_receive);
951 }
952 bool AudioFramesReceivedCheck(int frames_received) {
953 return initiating_client_->AudioFramesReceivedCheck(frames_received) &&
954 receiving_client_->AudioFramesReceivedCheck(frames_received);
955 }
956 bool VideoFramesReceivedCheck(int frames_received) {
957 return initiating_client_->VideoFramesReceivedCheck(frames_received) &&
958 receiving_client_->VideoFramesReceivedCheck(frames_received);
959 }
960 void VerifyDtmf() {
961 initiating_client_->VerifyDtmf();
962 receiving_client_->VerifyDtmf();
963 }
964
965 void TestUpdateOfferWithRejectedContent() {
deadbeefc9be0072015-12-14 18:27:57 -0800966 // Renegotiate, rejecting the video m-line.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 initiating_client_->Negotiate(true, false);
deadbeefc9be0072015-12-14 18:27:57 -0800968 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
969
970 int pc1_audio_received = initiating_client_->audio_frames_received();
971 int pc1_video_received = initiating_client_->video_frames_received();
972 int pc2_audio_received = receiving_client_->audio_frames_received();
973 int pc2_video_received = receiving_client_->video_frames_received();
974
975 // Wait for some additional audio frames to be received.
976 EXPECT_TRUE_WAIT(initiating_client_->AudioFramesReceivedCheck(
977 pc1_audio_received + kEndAudioFrameCount) &&
978 receiving_client_->AudioFramesReceivedCheck(
979 pc2_audio_received + kEndAudioFrameCount),
980 kMaxWaitForFramesMs);
981
982 // During this time, we shouldn't have received any additional video frames
983 // for the rejected video tracks.
984 EXPECT_EQ(pc1_video_received, initiating_client_->video_frames_received());
985 EXPECT_EQ(pc2_video_received, receiving_client_->video_frames_received());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 }
987
988 void VerifyRenderedSize(int width, int height) {
989 EXPECT_EQ(width, receiving_client()->rendered_width());
990 EXPECT_EQ(height, receiving_client()->rendered_height());
991 EXPECT_EQ(width, initializing_client()->rendered_width());
992 EXPECT_EQ(height, initializing_client()->rendered_height());
993 }
994
995 void VerifySessionDescriptions() {
996 initiating_client_->VerifyRejectedMediaInSessionDescription();
997 receiving_client_->VerifyRejectedMediaInSessionDescription();
998 initiating_client_->VerifyLocalIceUfragAndPassword();
999 receiving_client_->VerifyLocalIceUfragAndPassword();
1000 }
1001
deadbeef7c73bdb2015-12-10 15:10:44 -08001002 ~P2PTestConductor() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003 if (initiating_client_) {
deadbeefaf1b59c2015-10-15 12:08:41 -07001004 initiating_client_->set_signaling_message_receiver(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 }
1006 if (receiving_client_) {
deadbeefaf1b59c2015-10-15 12:08:41 -07001007 receiving_client_->set_signaling_message_receiver(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 }
1010
deadbeefaf1b59c2015-10-15 12:08:41 -07001011 bool CreateTestClients() { return CreateTestClients(nullptr, nullptr); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001012
1013 bool CreateTestClients(MediaConstraintsInterface* init_constraints,
1014 MediaConstraintsInterface* recv_constraints) {
deadbeefaf1b59c2015-10-15 12:08:41 -07001015 return CreateTestClients(init_constraints, nullptr, recv_constraints,
1016 nullptr);
Joachim Bauch04e5b492015-05-29 09:40:39 +02001017 }
1018
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001019 void SetSignalingReceivers() {
1020 initiating_client_->set_signaling_message_receiver(receiving_client_.get());
1021 receiving_client_->set_signaling_message_receiver(initiating_client_.get());
1022 }
1023
Joachim Bauch04e5b492015-05-29 09:40:39 +02001024 bool CreateTestClients(MediaConstraintsInterface* init_constraints,
1025 PeerConnectionFactory::Options* init_options,
1026 MediaConstraintsInterface* recv_constraints,
1027 PeerConnectionFactory::Options* recv_options) {
deadbeefaf1b59c2015-10-15 12:08:41 -07001028 initiating_client_.reset(PeerConnectionTestClient::CreateClient(
1029 "Caller: ", init_constraints, init_options));
1030 receiving_client_.reset(PeerConnectionTestClient::CreateClient(
1031 "Callee: ", recv_constraints, recv_options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 if (!initiating_client_ || !receiving_client_) {
1033 return false;
1034 }
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001035 SetSignalingReceivers();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001036 return true;
1037 }
1038
1039 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints,
1040 const webrtc::FakeConstraints& recv_constraints) {
1041 initiating_client_->SetVideoConstraints(init_constraints);
1042 receiving_client_->SetVideoConstraints(recv_constraints);
1043 }
1044
1045 void EnableVideoDecoderFactory() {
1046 initiating_client_->EnableVideoDecoderFactory();
1047 receiving_client_->EnableVideoDecoderFactory();
1048 }
1049
1050 // This test sets up a call between two parties. Both parties send static
1051 // frames to each other. Once the test is finished the number of sent frames
1052 // is compared to the number of received frames.
1053 void LocalP2PTest() {
1054 if (initiating_client_->NumberOfLocalMediaStreams() == 0) {
1055 initiating_client_->AddMediaStream(true, true);
1056 }
1057 initiating_client_->Negotiate();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058 // Assert true is used here since next tests are guaranteed to fail and
1059 // would eat up 5 seconds.
1060 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
1061 VerifySessionDescriptions();
1062
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 int audio_frame_count = kEndAudioFrameCount;
1064 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly.
1065 if (!initiating_client_->can_receive_audio() ||
1066 !receiving_client_->can_receive_audio()) {
1067 audio_frame_count = -1;
1068 }
1069 int video_frame_count = kEndVideoFrameCount;
1070 if (!initiating_client_->can_receive_video() ||
1071 !receiving_client_->can_receive_video()) {
1072 video_frame_count = -1;
1073 }
1074
1075 if (audio_frame_count != -1 || video_frame_count != -1) {
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001076 // Audio or video is expected to flow, so both clients should reach the
1077 // Connected state, and the offerer (ICE controller) should proceed to
1078 // Completed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001079 // Note: These tests have been observed to fail under heavy load at
1080 // shorter timeouts, so they may be flaky.
1081 EXPECT_EQ_WAIT(
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001082 webrtc::PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 initiating_client_->ice_connection_state(),
1084 kMaxWaitForFramesMs);
1085 EXPECT_EQ_WAIT(
1086 webrtc::PeerConnectionInterface::kIceConnectionConnected,
1087 receiving_client_->ice_connection_state(),
1088 kMaxWaitForFramesMs);
1089 }
1090
1091 if (initiating_client_->can_receive_audio() ||
1092 initiating_client_->can_receive_video()) {
1093 // The initiating client can receive media, so it must produce candidates
1094 // that will serve as destinations for that media.
1095 // TODO(bemasc): Understand why the state is not already Complete here, as
1096 // seems to be the case for the receiving client. This may indicate a bug
1097 // in the ICE gathering system.
1098 EXPECT_NE(webrtc::PeerConnectionInterface::kIceGatheringNew,
1099 initiating_client_->ice_gathering_state());
1100 }
1101 if (receiving_client_->can_receive_audio() ||
1102 receiving_client_->can_receive_video()) {
1103 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
1104 receiving_client_->ice_gathering_state(),
1105 kMaxWaitForFramesMs);
1106 }
1107
1108 EXPECT_TRUE_WAIT(FramesNotPending(audio_frame_count, video_frame_count),
1109 kMaxWaitForFramesMs);
1110 }
1111
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001112 void SetupAndVerifyDtlsCall() {
1113 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1114 FakeConstraints setup_constraints;
1115 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1116 true);
1117 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1118 LocalP2PTest();
1119 VerifyRenderedSize(640, 480);
1120 }
1121
1122 PeerConnectionTestClient* CreateDtlsClientWithAlternateKey() {
1123 FakeConstraints setup_constraints;
1124 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1125 true);
1126
1127 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
1128 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore()
1129 : nullptr);
1130 dtls_identity_store->use_alternate_key();
1131
1132 // Make sure the new client is using a different certificate.
1133 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore(
kwiberg0eb15ed2015-12-17 03:04:15 -08001134 "New Peer: ", &setup_constraints, nullptr,
1135 std::move(dtls_identity_store));
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001136 }
1137
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001138 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) {
1139 // Messages may get lost on the unreliable DataChannel, so we send multiple
1140 // times to avoid test flakiness.
1141 static const size_t kSendAttempts = 5;
1142
1143 for (size_t i = 0; i < kSendAttempts; ++i) {
1144 dc->Send(DataBuffer(data));
1145 }
1146 }
1147
deadbeefaf1b59c2015-10-15 12:08:41 -07001148 PeerConnectionTestClient* initializing_client() {
1149 return initiating_client_.get();
1150 }
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001151
1152 // Set the |initiating_client_| to the |client| passed in and return the
1153 // original |initiating_client_|.
1154 PeerConnectionTestClient* set_initializing_client(
1155 PeerConnectionTestClient* client) {
1156 PeerConnectionTestClient* old = initiating_client_.release();
1157 initiating_client_.reset(client);
1158 return old;
1159 }
1160
deadbeefaf1b59c2015-10-15 12:08:41 -07001161 PeerConnectionTestClient* receiving_client() {
1162 return receiving_client_.get();
1163 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001164
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001165 // Set the |receiving_client_| to the |client| passed in and return the
1166 // original |receiving_client_|.
1167 PeerConnectionTestClient* set_receiving_client(
1168 PeerConnectionTestClient* client) {
1169 PeerConnectionTestClient* old = receiving_client_.release();
1170 receiving_client_.reset(client);
1171 return old;
1172 }
1173
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001174 private:
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +00001175 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1176 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_;
1177 rtc::SocketServerScope ss_scope_;
deadbeefaf1b59c2015-10-15 12:08:41 -07001178 rtc::scoped_ptr<PeerConnectionTestClient> initiating_client_;
1179 rtc::scoped_ptr<PeerConnectionTestClient> receiving_client_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001180};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001181
kjellander@webrtc.orgd1cfa712013-10-16 16:51:52 +00001182// Disable for TSan v2, see
1183// https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
1184#if !defined(THREAD_SANITIZER)
1185
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001186// This test sets up a Jsep call between two parties and test Dtmf.
stefan@webrtc.orgda790082013-09-17 13:11:38 +00001187// TODO(holmer): Disabled due to sometimes crashing on buildbots.
1188// See issue webrtc/2378.
deadbeef7c73bdb2015-12-10 15:10:44 -08001189TEST_F(P2PTestConductor, DISABLED_LocalP2PTestDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001190 ASSERT_TRUE(CreateTestClients());
1191 LocalP2PTest();
1192 VerifyDtmf();
1193}
1194
1195// This test sets up a Jsep call between two parties and test that we can get a
1196// video aspect ratio of 16:9.
deadbeef7c73bdb2015-12-10 15:10:44 -08001197TEST_F(P2PTestConductor, LocalP2PTest16To9) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001198 ASSERT_TRUE(CreateTestClients());
1199 FakeConstraints constraint;
1200 double requested_ratio = 640.0/360;
1201 constraint.SetMandatoryMinAspectRatio(requested_ratio);
1202 SetVideoConstraints(constraint, constraint);
1203 LocalP2PTest();
1204
1205 ASSERT_LE(0, initializing_client()->rendered_height());
1206 double initiating_video_ratio =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001207 static_cast<double>(initializing_client()->rendered_width()) /
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001208 initializing_client()->rendered_height();
1209 EXPECT_LE(requested_ratio, initiating_video_ratio);
1210
1211 ASSERT_LE(0, receiving_client()->rendered_height());
1212 double receiving_video_ratio =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001213 static_cast<double>(receiving_client()->rendered_width()) /
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001214 receiving_client()->rendered_height();
1215 EXPECT_LE(requested_ratio, receiving_video_ratio);
1216}
1217
1218// This test sets up a Jsep call between two parties and test that the
1219// received video has a resolution of 1280*720.
1220// TODO(mallinath): Enable when
1221// http://code.google.com/p/webrtc/issues/detail?id=981 is fixed.
deadbeef7c73bdb2015-12-10 15:10:44 -08001222TEST_F(P2PTestConductor, DISABLED_LocalP2PTest1280By720) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001223 ASSERT_TRUE(CreateTestClients());
1224 FakeConstraints constraint;
1225 constraint.SetMandatoryMinWidth(1280);
1226 constraint.SetMandatoryMinHeight(720);
1227 SetVideoConstraints(constraint, constraint);
1228 LocalP2PTest();
1229 VerifyRenderedSize(1280, 720);
1230}
1231
1232// This test sets up a call between two endpoints that are configured to use
1233// DTLS key agreement. As a result, DTLS is negotiated and used for transport.
deadbeef7c73bdb2015-12-10 15:10:44 -08001234TEST_F(P2PTestConductor, LocalP2PTestDtls) {
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001235 SetupAndVerifyDtlsCall();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001236}
1237
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001238// This test sets up a audio call initially and then upgrades to audio/video,
1239// using DTLS.
deadbeef7c73bdb2015-12-10 15:10:44 -08001240TEST_F(P2PTestConductor, LocalP2PTestDtlsRenegotiate) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001241 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001242 FakeConstraints setup_constraints;
1243 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1244 true);
1245 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1246 receiving_client()->SetReceiveAudioVideo(true, false);
1247 LocalP2PTest();
1248 receiving_client()->SetReceiveAudioVideo(true, true);
1249 receiving_client()->Negotiate();
1250}
1251
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001252// This test sets up a call transfer to a new caller with a different DTLS
1253// fingerprint.
deadbeef7c73bdb2015-12-10 15:10:44 -08001254TEST_F(P2PTestConductor, LocalP2PTestDtlsTransferCallee) {
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001255 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1256 SetupAndVerifyDtlsCall();
1257
1258 // Keeping the original peer around which will still send packets to the
1259 // receiving client. These SRTP packets will be dropped.
1260 rtc::scoped_ptr<PeerConnectionTestClient> original_peer(
1261 set_initializing_client(CreateDtlsClientWithAlternateKey()));
1262 original_peer->pc()->Close();
1263
1264 SetSignalingReceivers();
1265 receiving_client()->SetExpectIceRestart(true);
1266 LocalP2PTest();
1267 VerifyRenderedSize(640, 480);
1268}
1269
guoweis46383312015-12-17 16:45:59 -08001270// This test sets up a non-bundle call and apply bundle during ICE restart. When
1271// bundle is in effect in the restart, the channel can successfully reset its
1272// DTLS-SRTP context.
1273TEST_F(P2PTestConductor, LocalP2PTestDtlsBundleInIceRestart) {
1274 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1275 FakeConstraints setup_constraints;
1276 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1277 true);
1278 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1279 receiving_client()->RemoveBundleFromReceivedSdp(true);
1280 LocalP2PTest();
1281 VerifyRenderedSize(640, 480);
1282
1283 initializing_client()->IceRestart();
1284 receiving_client()->SetExpectIceRestart(true);
1285 receiving_client()->RemoveBundleFromReceivedSdp(false);
1286 LocalP2PTest();
1287 VerifyRenderedSize(640, 480);
1288}
1289
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001290// This test sets up a call transfer to a new callee with a different DTLS
1291// fingerprint.
deadbeef7c73bdb2015-12-10 15:10:44 -08001292TEST_F(P2PTestConductor, LocalP2PTestDtlsTransferCaller) {
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -08001293 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1294 SetupAndVerifyDtlsCall();
1295
1296 // Keeping the original peer around which will still send packets to the
1297 // receiving client. These SRTP packets will be dropped.
1298 rtc::scoped_ptr<PeerConnectionTestClient> original_peer(
1299 set_receiving_client(CreateDtlsClientWithAlternateKey()));
1300 original_peer->pc()->Close();
1301
1302 SetSignalingReceivers();
1303 initializing_client()->IceRestart();
1304 LocalP2PTest();
1305 VerifyRenderedSize(640, 480);
1306}
1307
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308// This test sets up a call between two endpoints that are configured to use
1309// DTLS key agreement. The offerer don't support SDES. As a result, DTLS is
1310// negotiated and used for transport.
deadbeef7c73bdb2015-12-10 15:10:44 -08001311TEST_F(P2PTestConductor, LocalP2PTestOfferDtlsButNotSdes) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001312 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001313 FakeConstraints setup_constraints;
1314 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1315 true);
1316 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1317 receiving_client()->RemoveSdesCryptoFromReceivedSdp(true);
1318 LocalP2PTest();
1319 VerifyRenderedSize(640, 480);
1320}
1321
1322// This test sets up a Jsep call between two parties, and the callee only
1323// accept to receive video.
deadbeef7c73bdb2015-12-10 15:10:44 -08001324TEST_F(P2PTestConductor, LocalP2PTestAnswerVideo) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001325 ASSERT_TRUE(CreateTestClients());
1326 receiving_client()->SetReceiveAudioVideo(false, true);
1327 LocalP2PTest();
1328}
1329
1330// This test sets up a Jsep call between two parties, and the callee only
1331// accept to receive audio.
deadbeef7c73bdb2015-12-10 15:10:44 -08001332TEST_F(P2PTestConductor, LocalP2PTestAnswerAudio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001333 ASSERT_TRUE(CreateTestClients());
1334 receiving_client()->SetReceiveAudioVideo(true, false);
1335 LocalP2PTest();
1336}
1337
1338// This test sets up a Jsep call between two parties, and the callee reject both
1339// audio and video.
deadbeef7c73bdb2015-12-10 15:10:44 -08001340TEST_F(P2PTestConductor, LocalP2PTestAnswerNone) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001341 ASSERT_TRUE(CreateTestClients());
1342 receiving_client()->SetReceiveAudioVideo(false, false);
1343 LocalP2PTest();
1344}
1345
1346// This test sets up an audio and video call between two parties. After the call
1347// runs for a while (10 frames), the caller sends an update offer with video
1348// being rejected. Once the re-negotiation is done, the video flow should stop
1349// and the audio flow should continue.
deadbeefc9be0072015-12-14 18:27:57 -08001350TEST_F(P2PTestConductor, UpdateOfferWithRejectedContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001351 ASSERT_TRUE(CreateTestClients());
1352 LocalP2PTest();
1353 TestUpdateOfferWithRejectedContent();
1354}
1355
1356// This test sets up a Jsep call between two parties. The MSID is removed from
1357// the SDP strings from the caller.
deadbeefc9be0072015-12-14 18:27:57 -08001358TEST_F(P2PTestConductor, LocalP2PTestWithoutMsid) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001359 ASSERT_TRUE(CreateTestClients());
1360 receiving_client()->RemoveMsidFromReceivedSdp(true);
1361 // TODO(perkj): Currently there is a bug that cause audio to stop playing if
1362 // audio and video is muxed when MSID is disabled. Remove
1363 // SetRemoveBundleFromSdp once
1364 // https://code.google.com/p/webrtc/issues/detail?id=1193 is fixed.
1365 receiving_client()->RemoveBundleFromReceivedSdp(true);
1366 LocalP2PTest();
1367}
1368
1369// This test sets up a Jsep call between two parties and the initiating peer
1370// sends two steams.
1371// TODO(perkj): Disabled due to
1372// https://code.google.com/p/webrtc/issues/detail?id=1454
deadbeef7c73bdb2015-12-10 15:10:44 -08001373TEST_F(P2PTestConductor, DISABLED_LocalP2PTestTwoStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001374 ASSERT_TRUE(CreateTestClients());
1375 // Set optional video constraint to max 320pixels to decrease CPU usage.
1376 FakeConstraints constraint;
1377 constraint.SetOptionalMaxWidth(320);
1378 SetVideoConstraints(constraint, constraint);
1379 initializing_client()->AddMediaStream(true, true);
1380 initializing_client()->AddMediaStream(false, true);
1381 ASSERT_EQ(2u, initializing_client()->NumberOfLocalMediaStreams());
1382 LocalP2PTest();
1383 EXPECT_EQ(2u, receiving_client()->number_of_remote_streams());
1384}
1385
1386// Test that we can receive the audio output level from a remote audio track.
deadbeef7c73bdb2015-12-10 15:10:44 -08001387TEST_F(P2PTestConductor, GetAudioOutputLevelStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001388 ASSERT_TRUE(CreateTestClients());
1389 LocalP2PTest();
1390
1391 StreamCollectionInterface* remote_streams =
1392 initializing_client()->remote_streams();
1393 ASSERT_GT(remote_streams->count(), 0u);
1394 ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u);
1395 MediaStreamTrackInterface* remote_audio_track =
1396 remote_streams->at(0)->GetAudioTracks()[0];
1397
1398 // Get the audio output level stats. Note that the level is not available
1399 // until a RTCP packet has been received.
1400 EXPECT_TRUE_WAIT(
1401 initializing_client()->GetAudioOutputLevelStats(remote_audio_track) > 0,
1402 kMaxWaitForStatsMs);
1403}
1404
1405// Test that an audio input level is reported.
deadbeef7c73bdb2015-12-10 15:10:44 -08001406TEST_F(P2PTestConductor, GetAudioInputLevelStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407 ASSERT_TRUE(CreateTestClients());
1408 LocalP2PTest();
1409
1410 // Get the audio input level stats. The level should be available very
1411 // soon after the test starts.
1412 EXPECT_TRUE_WAIT(initializing_client()->GetAudioInputLevelStats() > 0,
1413 kMaxWaitForStatsMs);
1414}
1415
1416// Test that we can get incoming byte counts from both audio and video tracks.
deadbeef7c73bdb2015-12-10 15:10:44 -08001417TEST_F(P2PTestConductor, GetBytesReceivedStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001418 ASSERT_TRUE(CreateTestClients());
1419 LocalP2PTest();
1420
1421 StreamCollectionInterface* remote_streams =
1422 initializing_client()->remote_streams();
1423 ASSERT_GT(remote_streams->count(), 0u);
1424 ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u);
1425 MediaStreamTrackInterface* remote_audio_track =
1426 remote_streams->at(0)->GetAudioTracks()[0];
1427 EXPECT_TRUE_WAIT(
1428 initializing_client()->GetBytesReceivedStats(remote_audio_track) > 0,
1429 kMaxWaitForStatsMs);
1430
1431 MediaStreamTrackInterface* remote_video_track =
1432 remote_streams->at(0)->GetVideoTracks()[0];
1433 EXPECT_TRUE_WAIT(
1434 initializing_client()->GetBytesReceivedStats(remote_video_track) > 0,
1435 kMaxWaitForStatsMs);
1436}
1437
1438// Test that we can get outgoing byte counts from both audio and video tracks.
deadbeef7c73bdb2015-12-10 15:10:44 -08001439TEST_F(P2PTestConductor, GetBytesSentStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001440 ASSERT_TRUE(CreateTestClients());
1441 LocalP2PTest();
1442
1443 StreamCollectionInterface* local_streams =
1444 initializing_client()->local_streams();
1445 ASSERT_GT(local_streams->count(), 0u);
1446 ASSERT_GT(local_streams->at(0)->GetAudioTracks().size(), 0u);
1447 MediaStreamTrackInterface* local_audio_track =
1448 local_streams->at(0)->GetAudioTracks()[0];
1449 EXPECT_TRUE_WAIT(
1450 initializing_client()->GetBytesSentStats(local_audio_track) > 0,
1451 kMaxWaitForStatsMs);
1452
1453 MediaStreamTrackInterface* local_video_track =
1454 local_streams->at(0)->GetVideoTracks()[0];
1455 EXPECT_TRUE_WAIT(
1456 initializing_client()->GetBytesSentStats(local_video_track) > 0,
1457 kMaxWaitForStatsMs);
1458}
1459
Joachim Bauch04e5b492015-05-29 09:40:39 +02001460// Test that DTLS 1.0 is used if both sides only support DTLS 1.0.
deadbeef7c73bdb2015-12-10 15:10:44 -08001461TEST_F(P2PTestConductor, GetDtls12None) {
Joachim Bauch04e5b492015-05-29 09:40:39 +02001462 PeerConnectionFactory::Options init_options;
1463 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1464 PeerConnectionFactory::Options recv_options;
1465 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
deadbeefaf1b59c2015-10-15 12:08:41 -07001466 ASSERT_TRUE(
1467 CreateTestClients(nullptr, &init_options, nullptr, &recv_options));
jbauchac8869e2015-07-03 01:36:14 -07001468 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1469 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1470 initializing_client()->pc()->RegisterUMAObserver(init_observer);
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +00001471 LocalP2PTest();
1472
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001473 EXPECT_EQ_WAIT(rtc::SSLStreamAdapter::SslCipherSuiteToName(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001474 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest(
1475 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT)),
1476 initializing_client()->GetDtlsCipherStats(),
1477 kMaxWaitForStatsMs);
1478 EXPECT_EQ(1, init_observer->GetEnumCounter(
1479 webrtc::kEnumCounterAudioSslCipher,
1480 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest(
1481 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT)));
Joachim Bauch04e5b492015-05-29 09:40:39 +02001482
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001483 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001484 initializing_client()->GetSrtpCipherStats(),
1485 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001486 EXPECT_EQ(1,
1487 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1488 kDefaultSrtpCryptoSuite));
Joachim Bauch04e5b492015-05-29 09:40:39 +02001489}
1490
1491// Test that DTLS 1.2 is used if both ends support it.
deadbeef7c73bdb2015-12-10 15:10:44 -08001492TEST_F(P2PTestConductor, GetDtls12Both) {
Joachim Bauch04e5b492015-05-29 09:40:39 +02001493 PeerConnectionFactory::Options init_options;
1494 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1495 PeerConnectionFactory::Options recv_options;
1496 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
deadbeefaf1b59c2015-10-15 12:08:41 -07001497 ASSERT_TRUE(
1498 CreateTestClients(nullptr, &init_options, nullptr, &recv_options));
jbauchac8869e2015-07-03 01:36:14 -07001499 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1500 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1501 initializing_client()->pc()->RegisterUMAObserver(init_observer);
Joachim Bauch04e5b492015-05-29 09:40:39 +02001502 LocalP2PTest();
1503
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001504 EXPECT_EQ_WAIT(rtc::SSLStreamAdapter::SslCipherSuiteToName(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001505 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest(
1506 rtc::SSL_PROTOCOL_DTLS_12, rtc::KT_DEFAULT)),
1507 initializing_client()->GetDtlsCipherStats(),
1508 kMaxWaitForStatsMs);
1509 EXPECT_EQ(1, init_observer->GetEnumCounter(
1510 webrtc::kEnumCounterAudioSslCipher,
1511 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest(
1512 rtc::SSL_PROTOCOL_DTLS_12, rtc::KT_DEFAULT)));
Joachim Bauch04e5b492015-05-29 09:40:39 +02001513
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001514 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001515 initializing_client()->GetSrtpCipherStats(),
1516 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001517 EXPECT_EQ(1,
1518 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1519 kDefaultSrtpCryptoSuite));
Joachim Bauch04e5b492015-05-29 09:40:39 +02001520}
1521
1522// Test that DTLS 1.0 is used if the initator supports DTLS 1.2 and the
1523// received supports 1.0.
deadbeef7c73bdb2015-12-10 15:10:44 -08001524TEST_F(P2PTestConductor, GetDtls12Init) {
Joachim Bauch04e5b492015-05-29 09:40:39 +02001525 PeerConnectionFactory::Options init_options;
1526 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1527 PeerConnectionFactory::Options recv_options;
1528 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
deadbeefaf1b59c2015-10-15 12:08:41 -07001529 ASSERT_TRUE(
1530 CreateTestClients(nullptr, &init_options, nullptr, &recv_options));
jbauchac8869e2015-07-03 01:36:14 -07001531 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1532 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1533 initializing_client()->pc()->RegisterUMAObserver(init_observer);
Joachim Bauch04e5b492015-05-29 09:40:39 +02001534 LocalP2PTest();
1535
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001536 EXPECT_EQ_WAIT(rtc::SSLStreamAdapter::SslCipherSuiteToName(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001537 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest(
1538 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT)),
1539 initializing_client()->GetDtlsCipherStats(),
1540 kMaxWaitForStatsMs);
1541 EXPECT_EQ(1, init_observer->GetEnumCounter(
1542 webrtc::kEnumCounterAudioSslCipher,
1543 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest(
1544 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT)));
Joachim Bauch04e5b492015-05-29 09:40:39 +02001545
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001546 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001547 initializing_client()->GetSrtpCipherStats(),
1548 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001549 EXPECT_EQ(1,
1550 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1551 kDefaultSrtpCryptoSuite));
Joachim Bauch04e5b492015-05-29 09:40:39 +02001552}
1553
1554// Test that DTLS 1.0 is used if the initator supports DTLS 1.0 and the
1555// received supports 1.2.
deadbeef7c73bdb2015-12-10 15:10:44 -08001556TEST_F(P2PTestConductor, GetDtls12Recv) {
Joachim Bauch04e5b492015-05-29 09:40:39 +02001557 PeerConnectionFactory::Options init_options;
1558 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1559 PeerConnectionFactory::Options recv_options;
1560 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
deadbeefaf1b59c2015-10-15 12:08:41 -07001561 ASSERT_TRUE(
1562 CreateTestClients(nullptr, &init_options, nullptr, &recv_options));
jbauchac8869e2015-07-03 01:36:14 -07001563 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1564 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1565 initializing_client()->pc()->RegisterUMAObserver(init_observer);
Joachim Bauch04e5b492015-05-29 09:40:39 +02001566 LocalP2PTest();
1567
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001568 EXPECT_EQ_WAIT(rtc::SSLStreamAdapter::SslCipherSuiteToName(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001569 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest(
1570 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT)),
1571 initializing_client()->GetDtlsCipherStats(),
1572 kMaxWaitForStatsMs);
1573 EXPECT_EQ(1, init_observer->GetEnumCounter(
1574 webrtc::kEnumCounterAudioSslCipher,
1575 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest(
1576 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT)));
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +00001577
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001578 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001579 initializing_client()->GetSrtpCipherStats(),
1580 kMaxWaitForStatsMs);
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -08001581 EXPECT_EQ(1,
1582 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1583 kDefaultSrtpCryptoSuite));
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +00001584}
1585
deadbeefb5cb19b2015-11-23 16:39:12 -08001586// This test sets up a call between two parties with audio, video and an RTP
1587// data channel.
deadbeef7c73bdb2015-12-10 15:10:44 -08001588TEST_F(P2PTestConductor, LocalP2PTestRtpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 FakeConstraints setup_constraints;
1590 setup_constraints.SetAllowRtpDataChannels();
1591 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1592 initializing_client()->CreateDataChannel();
1593 LocalP2PTest();
deadbeefaf1b59c2015-10-15 12:08:41 -07001594 ASSERT_TRUE(initializing_client()->data_channel() != nullptr);
1595 ASSERT_TRUE(receiving_client()->data_channel() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
1597 kMaxWaitMs);
1598 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(),
1599 kMaxWaitMs);
1600
1601 std::string data = "hello world";
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001602
1603 SendRtpData(initializing_client()->data_channel(), data);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(),
1605 kMaxWaitMs);
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001606
1607 SendRtpData(receiving_client()->data_channel(), data);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(),
1609 kMaxWaitMs);
1610
1611 receiving_client()->data_channel()->Close();
1612 // Send new offer and answer.
1613 receiving_client()->Negotiate();
1614 EXPECT_FALSE(initializing_client()->data_observer()->IsOpen());
1615 EXPECT_FALSE(receiving_client()->data_observer()->IsOpen());
1616}
1617
deadbeefb5cb19b2015-11-23 16:39:12 -08001618// This test sets up a call between two parties with audio, video and an SCTP
1619// data channel.
deadbeef7c73bdb2015-12-10 15:10:44 -08001620TEST_F(P2PTestConductor, LocalP2PTestSctpDataChannel) {
deadbeefb5cb19b2015-11-23 16:39:12 -08001621 ASSERT_TRUE(CreateTestClients());
1622 initializing_client()->CreateDataChannel();
1623 LocalP2PTest();
1624 ASSERT_TRUE(initializing_client()->data_channel() != nullptr);
1625 EXPECT_TRUE_WAIT(receiving_client()->data_channel() != nullptr, kMaxWaitMs);
1626 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
1627 kMaxWaitMs);
1628 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), kMaxWaitMs);
1629
1630 std::string data = "hello world";
1631
1632 initializing_client()->data_channel()->Send(DataBuffer(data));
1633 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(),
1634 kMaxWaitMs);
1635
1636 receiving_client()->data_channel()->Send(DataBuffer(data));
1637 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(),
1638 kMaxWaitMs);
1639
1640 receiving_client()->data_channel()->Close();
deadbeef15887932015-12-14 19:32:34 -08001641 EXPECT_TRUE_WAIT(!initializing_client()->data_observer()->IsOpen(),
1642 kMaxWaitMs);
1643 EXPECT_TRUE_WAIT(!receiving_client()->data_observer()->IsOpen(), kMaxWaitMs);
deadbeefb5cb19b2015-11-23 16:39:12 -08001644}
1645
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001646// This test sets up a call between two parties and creates a data channel.
1647// The test tests that received data is buffered unless an observer has been
1648// registered.
1649// Rtp data channels can receive data before the underlying
1650// transport has detected that a channel is writable and thus data can be
1651// received before the data channel state changes to open. That is hard to test
1652// but the same buffering is used in that case.
deadbeef7c73bdb2015-12-10 15:10:44 -08001653TEST_F(P2PTestConductor, RegisterDataChannelObserver) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 FakeConstraints setup_constraints;
1655 setup_constraints.SetAllowRtpDataChannels();
1656 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1657 initializing_client()->CreateDataChannel();
1658 initializing_client()->Negotiate();
1659
deadbeefaf1b59c2015-10-15 12:08:41 -07001660 ASSERT_TRUE(initializing_client()->data_channel() != nullptr);
1661 ASSERT_TRUE(receiving_client()->data_channel() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001662 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
1663 kMaxWaitMs);
1664 EXPECT_EQ_WAIT(DataChannelInterface::kOpen,
1665 receiving_client()->data_channel()->state(), kMaxWaitMs);
1666
1667 // Unregister the existing observer.
1668 receiving_client()->data_channel()->UnregisterObserver();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001669
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670 std::string data = "hello world";
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001671 SendRtpData(initializing_client()->data_channel(), data);
1672
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001673 // Wait a while to allow the sent data to arrive before an observer is
1674 // registered..
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001675 rtc::Thread::Current()->ProcessMessages(100);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676
1677 MockDataChannelObserver new_observer(receiving_client()->data_channel());
1678 EXPECT_EQ_WAIT(data, new_observer.last_message(), kMaxWaitMs);
1679}
1680
1681// This test sets up a call between two parties with audio, video and but only
1682// the initiating client support data.
deadbeef7c73bdb2015-12-10 15:10:44 -08001683TEST_F(P2PTestConductor, LocalP2PTestReceiverDoesntSupportData) {
buildbot@webrtc.org61c1b8e2014-04-09 06:06:38 +00001684 FakeConstraints setup_constraints_1;
1685 setup_constraints_1.SetAllowRtpDataChannels();
1686 // Must disable DTLS to make negotiation succeed.
1687 setup_constraints_1.SetMandatory(
1688 MediaConstraintsInterface::kEnableDtlsSrtp, false);
1689 FakeConstraints setup_constraints_2;
1690 setup_constraints_2.SetMandatory(
1691 MediaConstraintsInterface::kEnableDtlsSrtp, false);
1692 ASSERT_TRUE(CreateTestClients(&setup_constraints_1, &setup_constraints_2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 initializing_client()->CreateDataChannel();
1694 LocalP2PTest();
deadbeefaf1b59c2015-10-15 12:08:41 -07001695 EXPECT_TRUE(initializing_client()->data_channel() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 EXPECT_FALSE(receiving_client()->data_channel());
1697 EXPECT_FALSE(initializing_client()->data_observer()->IsOpen());
1698}
1699
1700// This test sets up a call between two parties with audio, video. When audio
1701// and video is setup and flowing and data channel is negotiated.
deadbeef7c73bdb2015-12-10 15:10:44 -08001702TEST_F(P2PTestConductor, AddDataChannelAfterRenegotiation) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 FakeConstraints setup_constraints;
1704 setup_constraints.SetAllowRtpDataChannels();
1705 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1706 LocalP2PTest();
1707 initializing_client()->CreateDataChannel();
1708 // Send new offer and answer.
1709 initializing_client()->Negotiate();
deadbeefaf1b59c2015-10-15 12:08:41 -07001710 ASSERT_TRUE(initializing_client()->data_channel() != nullptr);
1711 ASSERT_TRUE(receiving_client()->data_channel() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
1713 kMaxWaitMs);
1714 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(),
1715 kMaxWaitMs);
1716}
1717
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001718// This test sets up a Jsep call with SCTP DataChannel and verifies the
1719// negotiation is completed without error.
1720#ifdef HAVE_SCTP
deadbeef7c73bdb2015-12-10 15:10:44 -08001721TEST_F(P2PTestConductor, CreateOfferWithSctpDataChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001722 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001723 FakeConstraints constraints;
1724 constraints.SetMandatory(
1725 MediaConstraintsInterface::kEnableDtlsSrtp, true);
1726 ASSERT_TRUE(CreateTestClients(&constraints, &constraints));
1727 initializing_client()->CreateDataChannel();
1728 initializing_client()->Negotiate(false, false);
1729}
1730#endif
1731
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732// This test sets up a call between two parties with audio, and video.
1733// During the call, the initializing side restart ice and the test verifies that
1734// new ice candidates are generated and audio and video still can flow.
deadbeef7c73bdb2015-12-10 15:10:44 -08001735TEST_F(P2PTestConductor, IceRestart) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736 ASSERT_TRUE(CreateTestClients());
1737
1738 // Negotiate and wait for ice completion and make sure audio and video plays.
1739 LocalP2PTest();
1740
1741 // Create a SDP string of the first audio candidate for both clients.
1742 const webrtc::IceCandidateCollection* audio_candidates_initiator =
1743 initializing_client()->pc()->local_description()->candidates(0);
1744 const webrtc::IceCandidateCollection* audio_candidates_receiver =
1745 receiving_client()->pc()->local_description()->candidates(0);
1746 ASSERT_GT(audio_candidates_initiator->count(), 0u);
1747 ASSERT_GT(audio_candidates_receiver->count(), 0u);
1748 std::string initiator_candidate;
1749 EXPECT_TRUE(
1750 audio_candidates_initiator->at(0)->ToString(&initiator_candidate));
1751 std::string receiver_candidate;
1752 EXPECT_TRUE(audio_candidates_receiver->at(0)->ToString(&receiver_candidate));
1753
1754 // Restart ice on the initializing client.
1755 receiving_client()->SetExpectIceRestart(true);
1756 initializing_client()->IceRestart();
1757
1758 // Negotiate and wait for ice completion again and make sure audio and video
1759 // plays.
1760 LocalP2PTest();
1761
1762 // Create a SDP string of the first audio candidate for both clients again.
1763 const webrtc::IceCandidateCollection* audio_candidates_initiator_restart =
1764 initializing_client()->pc()->local_description()->candidates(0);
1765 const webrtc::IceCandidateCollection* audio_candidates_reciever_restart =
1766 receiving_client()->pc()->local_description()->candidates(0);
1767 ASSERT_GT(audio_candidates_initiator_restart->count(), 0u);
1768 ASSERT_GT(audio_candidates_reciever_restart->count(), 0u);
1769 std::string initiator_candidate_restart;
1770 EXPECT_TRUE(audio_candidates_initiator_restart->at(0)->ToString(
1771 &initiator_candidate_restart));
1772 std::string receiver_candidate_restart;
1773 EXPECT_TRUE(audio_candidates_reciever_restart->at(0)->ToString(
1774 &receiver_candidate_restart));
1775
1776 // Verify that the first candidates in the local session descriptions has
1777 // changed.
1778 EXPECT_NE(initiator_candidate, initiator_candidate_restart);
1779 EXPECT_NE(receiver_candidate, receiver_candidate_restart);
1780}
1781
deadbeeffaac4972015-11-12 15:33:07 -08001782// This test sets up a call between two parties with audio, and video.
1783// It then renegotiates setting the video m-line to "port 0", then later
1784// renegotiates again, enabling video.
deadbeef7c73bdb2015-12-10 15:10:44 -08001785TEST_F(P2PTestConductor, LocalP2PTestVideoDisableEnable) {
deadbeeffaac4972015-11-12 15:33:07 -08001786 ASSERT_TRUE(CreateTestClients());
1787
1788 // Do initial negotiation. Will result in video and audio sendonly m-lines.
1789 receiving_client()->set_auto_add_stream(false);
1790 initializing_client()->AddMediaStream(true, true);
1791 initializing_client()->Negotiate();
1792
1793 // Negotiate again, disabling the video m-line (receiving client will
1794 // set port to 0 due to mandatory "OfferToReceiveVideo: false" constraint).
1795 receiving_client()->SetReceiveVideo(false);
1796 initializing_client()->Negotiate();
1797
1798 // Enable video and do negotiation again, making sure video is received
1799 // end-to-end.
1800 receiving_client()->SetReceiveVideo(true);
1801 receiving_client()->AddMediaStream(true, true);
1802 LocalP2PTest();
1803}
1804
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805// This test sets up a Jsep call between two parties with external
1806// VideoDecoderFactory.
stefan@webrtc.orgda790082013-09-17 13:11:38 +00001807// TODO(holmer): Disabled due to sometimes crashing on buildbots.
1808// See issue webrtc/2378.
deadbeef7c73bdb2015-12-10 15:10:44 -08001809TEST_F(P2PTestConductor, DISABLED_LocalP2PTestWithVideoDecoderFactory) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 ASSERT_TRUE(CreateTestClients());
1811 EnableVideoDecoderFactory();
1812 LocalP2PTest();
1813}
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001814
deadbeeffac06552015-11-25 11:26:01 -08001815// This tests that if we negotiate after calling CreateSender but before we
1816// have a track, then set a track later, frames from the newly-set track are
1817// received end-to-end.
deadbeef7c73bdb2015-12-10 15:10:44 -08001818TEST_F(P2PTestConductor, EarlyWarmupTest) {
deadbeeffac06552015-11-25 11:26:01 -08001819 ASSERT_TRUE(CreateTestClients());
1820 auto audio_sender = initializing_client()->pc()->CreateSender("audio");
1821 auto video_sender = initializing_client()->pc()->CreateSender("video");
1822 initializing_client()->Negotiate();
1823 // Wait for ICE connection to complete, without any tracks.
1824 // Note that the receiving client WILL (in HandleIncomingOffer) create
1825 // tracks, so it's only the initiator here that's doing early warmup.
1826 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
1827 VerifySessionDescriptions();
1828 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
1829 initializing_client()->ice_connection_state(),
1830 kMaxWaitForFramesMs);
1831 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
1832 receiving_client()->ice_connection_state(),
1833 kMaxWaitForFramesMs);
1834 // Now set the tracks, and expect frames to immediately start flowing.
1835 EXPECT_TRUE(
1836 audio_sender->SetTrack(initializing_client()->CreateLocalAudioTrack("")));
1837 EXPECT_TRUE(
1838 video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack("")));
1839 EXPECT_TRUE_WAIT(FramesNotPending(kEndAudioFrameCount, kEndVideoFrameCount),
1840 kMaxWaitForFramesMs);
1841}
1842
deadbeef0a6c4ca2015-10-06 11:38:28 -07001843class IceServerParsingTest : public testing::Test {
1844 public:
1845 // Convenience for parsing a single URL.
1846 bool ParseUrl(const std::string& url) {
1847 return ParseUrl(url, std::string(), std::string());
1848 }
1849
1850 bool ParseUrl(const std::string& url,
1851 const std::string& username,
1852 const std::string& password) {
1853 PeerConnectionInterface::IceServers servers;
1854 PeerConnectionInterface::IceServer server;
1855 server.urls.push_back(url);
1856 server.username = username;
1857 server.password = password;
1858 servers.push_back(server);
1859 return webrtc::ParseIceServers(servers, &stun_configurations_,
1860 &turn_configurations_);
1861 }
1862
1863 protected:
1864 webrtc::StunConfigurations stun_configurations_;
1865 webrtc::TurnConfigurations turn_configurations_;
1866};
1867
1868// Make sure all STUN/TURN prefixes are parsed correctly.
1869TEST_F(IceServerParsingTest, ParseStunPrefixes) {
1870 EXPECT_TRUE(ParseUrl("stun:hostname"));
1871 EXPECT_EQ(1U, stun_configurations_.size());
1872 EXPECT_EQ(0U, turn_configurations_.size());
1873 stun_configurations_.clear();
1874
1875 EXPECT_TRUE(ParseUrl("stuns:hostname"));
1876 EXPECT_EQ(1U, stun_configurations_.size());
1877 EXPECT_EQ(0U, turn_configurations_.size());
1878 stun_configurations_.clear();
1879
1880 EXPECT_TRUE(ParseUrl("turn:hostname"));
1881 EXPECT_EQ(0U, stun_configurations_.size());
1882 EXPECT_EQ(1U, turn_configurations_.size());
1883 EXPECT_FALSE(turn_configurations_[0].secure);
1884 turn_configurations_.clear();
1885
1886 EXPECT_TRUE(ParseUrl("turns:hostname"));
1887 EXPECT_EQ(0U, stun_configurations_.size());
1888 EXPECT_EQ(1U, turn_configurations_.size());
1889 EXPECT_TRUE(turn_configurations_[0].secure);
1890 turn_configurations_.clear();
1891
1892 // invalid prefixes
1893 EXPECT_FALSE(ParseUrl("stunn:hostname"));
1894 EXPECT_FALSE(ParseUrl(":hostname"));
1895 EXPECT_FALSE(ParseUrl(":"));
1896 EXPECT_FALSE(ParseUrl(""));
1897}
1898
1899TEST_F(IceServerParsingTest, VerifyDefaults) {
1900 // TURNS defaults
1901 EXPECT_TRUE(ParseUrl("turns:hostname"));
1902 EXPECT_EQ(1U, turn_configurations_.size());
1903 EXPECT_EQ(5349, turn_configurations_[0].server.port());
1904 EXPECT_EQ("tcp", turn_configurations_[0].transport_type);
1905 turn_configurations_.clear();
1906
1907 // TURN defaults
1908 EXPECT_TRUE(ParseUrl("turn:hostname"));
1909 EXPECT_EQ(1U, turn_configurations_.size());
1910 EXPECT_EQ(3478, turn_configurations_[0].server.port());
1911 EXPECT_EQ("udp", turn_configurations_[0].transport_type);
1912 turn_configurations_.clear();
1913
1914 // STUN defaults
1915 EXPECT_TRUE(ParseUrl("stun:hostname"));
1916 EXPECT_EQ(1U, stun_configurations_.size());
1917 EXPECT_EQ(3478, stun_configurations_[0].server.port());
1918 stun_configurations_.clear();
1919}
1920
1921// Check that the 6 combinations of IPv4/IPv6/hostname and with/without port
1922// can be parsed correctly.
1923TEST_F(IceServerParsingTest, ParseHostnameAndPort) {
1924 EXPECT_TRUE(ParseUrl("stun:1.2.3.4:1234"));
1925 EXPECT_EQ(1U, stun_configurations_.size());
1926 EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname());
1927 EXPECT_EQ(1234, stun_configurations_[0].server.port());
1928 stun_configurations_.clear();
1929
1930 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]:4321"));
1931 EXPECT_EQ(1U, stun_configurations_.size());
1932 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname());
1933 EXPECT_EQ(4321, stun_configurations_[0].server.port());
1934 stun_configurations_.clear();
1935
1936 EXPECT_TRUE(ParseUrl("stun:hostname:9999"));
1937 EXPECT_EQ(1U, stun_configurations_.size());
1938 EXPECT_EQ("hostname", stun_configurations_[0].server.hostname());
1939 EXPECT_EQ(9999, stun_configurations_[0].server.port());
1940 stun_configurations_.clear();
1941
1942 EXPECT_TRUE(ParseUrl("stun:1.2.3.4"));
1943 EXPECT_EQ(1U, stun_configurations_.size());
1944 EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname());
1945 EXPECT_EQ(3478, stun_configurations_[0].server.port());
1946 stun_configurations_.clear();
1947
1948 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]"));
1949 EXPECT_EQ(1U, stun_configurations_.size());
1950 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname());
1951 EXPECT_EQ(3478, stun_configurations_[0].server.port());
1952 stun_configurations_.clear();
1953
1954 EXPECT_TRUE(ParseUrl("stun:hostname"));
1955 EXPECT_EQ(1U, stun_configurations_.size());
1956 EXPECT_EQ("hostname", stun_configurations_[0].server.hostname());
1957 EXPECT_EQ(3478, stun_configurations_[0].server.port());
1958 stun_configurations_.clear();
1959
1960 // Try some invalid hostname:port strings.
1961 EXPECT_FALSE(ParseUrl("stun:hostname:99a99"));
1962 EXPECT_FALSE(ParseUrl("stun:hostname:-1"));
1963 EXPECT_FALSE(ParseUrl("stun:hostname:"));
1964 EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000"));
1965 EXPECT_FALSE(ParseUrl("stun::5555"));
1966 EXPECT_FALSE(ParseUrl("stun:"));
1967}
1968
1969// Test parsing the "?transport=xxx" part of the URL.
1970TEST_F(IceServerParsingTest, ParseTransport) {
1971 EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp"));
1972 EXPECT_EQ(1U, turn_configurations_.size());
1973 EXPECT_EQ("tcp", turn_configurations_[0].transport_type);
1974 turn_configurations_.clear();
1975
1976 EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp"));
1977 EXPECT_EQ(1U, turn_configurations_.size());
1978 EXPECT_EQ("udp", turn_configurations_[0].transport_type);
1979 turn_configurations_.clear();
1980
1981 EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid"));
1982}
1983
1984// Test parsing ICE username contained in URL.
1985TEST_F(IceServerParsingTest, ParseUsername) {
1986 EXPECT_TRUE(ParseUrl("turn:user@hostname"));
1987 EXPECT_EQ(1U, turn_configurations_.size());
1988 EXPECT_EQ("user", turn_configurations_[0].username);
1989 turn_configurations_.clear();
1990
1991 EXPECT_FALSE(ParseUrl("turn:@hostname"));
1992 EXPECT_FALSE(ParseUrl("turn:username@"));
1993 EXPECT_FALSE(ParseUrl("turn:@"));
1994 EXPECT_FALSE(ParseUrl("turn:user@name@hostname"));
1995}
1996
1997// Test that username and password from IceServer is copied into the resulting
1998// TurnConfiguration.
1999TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) {
2000 EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password"));
2001 EXPECT_EQ(1U, turn_configurations_.size());
2002 EXPECT_EQ("username", turn_configurations_[0].username);
2003 EXPECT_EQ("password", turn_configurations_[0].password);
2004}
2005
2006// Ensure that if a server has multiple URLs, each one is parsed.
2007TEST_F(IceServerParsingTest, ParseMultipleUrls) {
2008 PeerConnectionInterface::IceServers servers;
2009 PeerConnectionInterface::IceServer server;
2010 server.urls.push_back("stun:hostname");
2011 server.urls.push_back("turn:hostname");
2012 servers.push_back(server);
2013 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_,
2014 &turn_configurations_));
2015 EXPECT_EQ(1U, stun_configurations_.size());
2016 EXPECT_EQ(1U, turn_configurations_.size());
2017}
2018
kjellander@webrtc.orgd1cfa712013-10-16 16:51:52 +00002019#endif // if !defined(THREAD_SANITIZER)