blob: 83826c5b6d4977f980251cc4e0855973e6429a72 [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>
33#include <vector>
34
35#include "talk/app/webrtc/dtmfsender.h"
36#include "talk/app/webrtc/fakeportallocatorfactory.h"
37#include "talk/app/webrtc/localaudiosource.h"
38#include "talk/app/webrtc/mediastreaminterface.h"
39#include "talk/app/webrtc/peerconnectionfactory.h"
40#include "talk/app/webrtc/peerconnectioninterface.h"
41#include "talk/app/webrtc/test/fakeaudiocapturemodule.h"
42#include "talk/app/webrtc/test/fakeconstraints.h"
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +000043#include "talk/app/webrtc/test/fakedtlsidentityservice.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044#include "talk/app/webrtc/test/fakeperiodicvideocapturer.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000045#include "talk/app/webrtc/test/fakevideotrackrenderer.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046#include "talk/app/webrtc/test/mockpeerconnectionobservers.h"
47#include "talk/app/webrtc/videosourceinterface.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000048#include "talk/media/webrtc/fakewebrtcvideoengine.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000049#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000050#include "webrtc/base/gunit.h"
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +000051#include "webrtc/base/physicalsocketserver.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000052#include "webrtc/base/scoped_ptr.h"
53#include "webrtc/base/ssladapter.h"
54#include "webrtc/base/sslstreamadapter.h"
55#include "webrtc/base/thread.h"
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +000056#include "webrtc/base/virtualsocketserver.h"
57#include "webrtc/p2p/base/constants.h"
58#include "webrtc/p2p/base/sessiondescription.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059
60#define MAYBE_SKIP_TEST(feature) \
61 if (!(feature())) { \
62 LOG(LS_INFO) << "Feature disabled... skipping"; \
63 return; \
64 }
65
66using cricket::ContentInfo;
67using cricket::FakeWebRtcVideoDecoder;
68using cricket::FakeWebRtcVideoDecoderFactory;
69using cricket::FakeWebRtcVideoEncoder;
70using cricket::FakeWebRtcVideoEncoderFactory;
71using cricket::MediaContentDescription;
72using webrtc::DataBuffer;
73using webrtc::DataChannelInterface;
74using webrtc::DtmfSender;
75using webrtc::DtmfSenderInterface;
76using webrtc::DtmfSenderObserverInterface;
77using webrtc::FakeConstraints;
78using webrtc::MediaConstraintsInterface;
79using webrtc::MediaStreamTrackInterface;
80using webrtc::MockCreateSessionDescriptionObserver;
81using webrtc::MockDataChannelObserver;
82using webrtc::MockSetSessionDescriptionObserver;
83using webrtc::MockStatsObserver;
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +000084using webrtc::PeerConnectionInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085using webrtc::SessionDescriptionInterface;
86using webrtc::StreamCollectionInterface;
87
jiayl@webrtc.org369f6822015-03-03 23:13:54 +000088static const int kMaxWaitMs = 10000;
pbos@webrtc.org044bdac2014-06-03 09:40:01 +000089// Disable for TSan v2, see
90// https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
91// This declaration is also #ifdef'd as it causes uninitialized-variable
92// warnings.
93#if !defined(THREAD_SANITIZER)
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094static const int kMaxWaitForStatsMs = 3000;
pbos@webrtc.org044bdac2014-06-03 09:40:01 +000095#endif
buildbot@webrtc.org3e01e0b2014-05-13 17:54:10 +000096static const int kMaxWaitForFramesMs = 10000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097static const int kEndAudioFrameCount = 3;
98static const int kEndVideoFrameCount = 3;
99
100static const char kStreamLabelBase[] = "stream_label";
101static const char kVideoTrackLabelBase[] = "video_track";
102static const char kAudioTrackLabelBase[] = "audio_track";
103static const char kDataChannelLabel[] = "data_channel";
104
105static void RemoveLinesFromSdp(const std::string& line_start,
106 std::string* sdp) {
107 const char kSdpLineEnd[] = "\r\n";
108 size_t ssrc_pos = 0;
109 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) !=
110 std::string::npos) {
111 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos);
112 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd));
113 }
114}
115
116class SignalingMessageReceiver {
117 public:
118 protected:
119 SignalingMessageReceiver() {}
120 virtual ~SignalingMessageReceiver() {}
121};
122
123class JsepMessageReceiver : public SignalingMessageReceiver {
124 public:
125 virtual void ReceiveSdpMessage(const std::string& type,
126 std::string& msg) = 0;
127 virtual void ReceiveIceMessage(const std::string& sdp_mid,
128 int sdp_mline_index,
129 const std::string& msg) = 0;
130
131 protected:
132 JsepMessageReceiver() {}
133 virtual ~JsepMessageReceiver() {}
134};
135
136template <typename MessageReceiver>
137class PeerConnectionTestClientBase
138 : public webrtc::PeerConnectionObserver,
139 public MessageReceiver {
140 public:
141 ~PeerConnectionTestClientBase() {
142 while (!fake_video_renderers_.empty()) {
143 RenderMap::iterator it = fake_video_renderers_.begin();
144 delete it->second;
145 fake_video_renderers_.erase(it);
146 }
147 }
148
149 virtual void Negotiate() = 0;
150
151 virtual void Negotiate(bool audio, bool video) = 0;
152
153 virtual void SetVideoConstraints(
154 const webrtc::FakeConstraints& video_constraint) {
155 video_constraints_ = video_constraint;
156 }
157
158 void AddMediaStream(bool audio, bool video) {
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000159 std::string stream_label = kStreamLabelBase +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000160 rtc::ToString<int>(
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000161 static_cast<int>(peer_connection_->local_streams()->count()));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000162 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream =
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000163 peer_connection_factory_->CreateLocalMediaStream(stream_label);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164
165 if (audio && can_receive_audio()) {
166 FakeConstraints constraints;
167 // Disable highpass filter so that we can get all the test audio frames.
168 constraints.AddMandatory(
169 MediaConstraintsInterface::kHighpassFilter, false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000170 rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +0000171 peer_connection_factory_->CreateAudioSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 // TODO(perkj): Test audio source when it is implemented. Currently audio
173 // always use the default input.
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000174 std::string label = stream_label + kAudioTrackLabelBase;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000175 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000176 peer_connection_factory_->CreateAudioTrack(label, source));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177 stream->AddTrack(audio_track);
178 }
179 if (video && can_receive_video()) {
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000180 stream->AddTrack(CreateLocalVideoTrack(stream_label));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 }
182
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000183 EXPECT_TRUE(peer_connection_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 }
185
186 size_t NumberOfLocalMediaStreams() {
187 return peer_connection_->local_streams()->count();
188 }
189
190 bool SessionActive() {
191 return peer_connection_->signaling_state() ==
192 webrtc::PeerConnectionInterface::kStable;
193 }
194
195 void set_signaling_message_receiver(
196 MessageReceiver* signaling_message_receiver) {
197 signaling_message_receiver_ = signaling_message_receiver;
198 }
199
200 void EnableVideoDecoderFactory() {
201 video_decoder_factory_enabled_ = true;
202 fake_video_decoder_factory_->AddSupportedVideoCodecType(
203 webrtc::kVideoCodecVP8);
204 }
205
206 bool AudioFramesReceivedCheck(int number_of_frames) const {
207 return number_of_frames <= fake_audio_capture_module_->frames_received();
208 }
209
210 bool VideoFramesReceivedCheck(int number_of_frames) {
211 if (video_decoder_factory_enabled_) {
212 const std::vector<FakeWebRtcVideoDecoder*>& decoders
213 = fake_video_decoder_factory_->decoders();
214 if (decoders.empty()) {
215 return number_of_frames <= 0;
216 }
217
218 for (std::vector<FakeWebRtcVideoDecoder*>::const_iterator
219 it = decoders.begin(); it != decoders.end(); ++it) {
220 if (number_of_frames > (*it)->GetNumFramesReceived()) {
221 return false;
222 }
223 }
224 return true;
225 } else {
226 if (fake_video_renderers_.empty()) {
227 return number_of_frames <= 0;
228 }
229
230 for (RenderMap::const_iterator it = fake_video_renderers_.begin();
231 it != fake_video_renderers_.end(); ++it) {
232 if (number_of_frames > it->second->num_rendered_frames()) {
233 return false;
234 }
235 }
236 return true;
237 }
238 }
239 // Verify the CreateDtmfSender interface
240 void VerifyDtmf() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000241 rtc::scoped_ptr<DummyDtmfObserver> observer(new DummyDtmfObserver());
242 rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243
244 // We can't create a DTMF sender with an invalid audio track or a non local
245 // track.
246 EXPECT_TRUE(peer_connection_->CreateDtmfSender(NULL) == NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000247 rtc::scoped_refptr<webrtc::AudioTrackInterface> non_localtrack(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 peer_connection_factory_->CreateAudioTrack("dummy_track",
249 NULL));
250 EXPECT_TRUE(peer_connection_->CreateDtmfSender(non_localtrack) == NULL);
251
252 // We should be able to create a DTMF sender from a local track.
253 webrtc::AudioTrackInterface* localtrack =
254 peer_connection_->local_streams()->at(0)->GetAudioTracks()[0];
255 dtmf_sender = peer_connection_->CreateDtmfSender(localtrack);
256 EXPECT_TRUE(dtmf_sender.get() != NULL);
257 dtmf_sender->RegisterObserver(observer.get());
258
259 // Test the DtmfSender object just created.
260 EXPECT_TRUE(dtmf_sender->CanInsertDtmf());
261 EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50));
262
263 // We don't need to verify that the DTMF tones are actually sent out because
264 // that is already covered by the tests of the lower level components.
265
266 EXPECT_TRUE_WAIT(observer->completed(), kMaxWaitMs);
267 std::vector<std::string> tones;
268 tones.push_back("1");
269 tones.push_back("a");
270 tones.push_back("");
271 observer->Verify(tones);
272
273 dtmf_sender->UnregisterObserver();
274 }
275
276 // Verifies that the SessionDescription have rejected the appropriate media
277 // content.
278 void VerifyRejectedMediaInSessionDescription() {
279 ASSERT_TRUE(peer_connection_->remote_description() != NULL);
280 ASSERT_TRUE(peer_connection_->local_description() != NULL);
281 const cricket::SessionDescription* remote_desc =
282 peer_connection_->remote_description()->description();
283 const cricket::SessionDescription* local_desc =
284 peer_connection_->local_description()->description();
285
286 const ContentInfo* remote_audio_content = GetFirstAudioContent(remote_desc);
287 if (remote_audio_content) {
288 const ContentInfo* audio_content =
289 GetFirstAudioContent(local_desc);
290 EXPECT_EQ(can_receive_audio(), !audio_content->rejected);
291 }
292
293 const ContentInfo* remote_video_content = GetFirstVideoContent(remote_desc);
294 if (remote_video_content) {
295 const ContentInfo* video_content =
296 GetFirstVideoContent(local_desc);
297 EXPECT_EQ(can_receive_video(), !video_content->rejected);
298 }
299 }
300
301 void SetExpectIceRestart(bool expect_restart) {
302 expect_ice_restart_ = expect_restart;
303 }
304
305 bool ExpectIceRestart() const { return expect_ice_restart_; }
306
307 void VerifyLocalIceUfragAndPassword() {
308 ASSERT_TRUE(peer_connection_->local_description() != NULL);
309 const cricket::SessionDescription* desc =
310 peer_connection_->local_description()->description();
311 const cricket::ContentInfos& contents = desc->contents();
312
313 for (size_t index = 0; index < contents.size(); ++index) {
314 if (contents[index].rejected)
315 continue;
316 const cricket::TransportDescription* transport_desc =
317 desc->GetTransportDescriptionByName(contents[index].name);
318
319 std::map<int, IceUfragPwdPair>::const_iterator ufragpair_it =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000320 ice_ufrag_pwd_.find(static_cast<int>(index));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321 if (ufragpair_it == ice_ufrag_pwd_.end()) {
322 ASSERT_FALSE(ExpectIceRestart());
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000323 ice_ufrag_pwd_[static_cast<int>(index)] =
324 IceUfragPwdPair(transport_desc->ice_ufrag, transport_desc->ice_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 } else if (ExpectIceRestart()) {
326 const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second;
327 EXPECT_NE(ufrag_pwd.first, transport_desc->ice_ufrag);
328 EXPECT_NE(ufrag_pwd.second, transport_desc->ice_pwd);
329 } else {
330 const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second;
331 EXPECT_EQ(ufrag_pwd.first, transport_desc->ice_ufrag);
332 EXPECT_EQ(ufrag_pwd.second, transport_desc->ice_pwd);
333 }
334 }
335 }
336
337 int GetAudioOutputLevelStats(webrtc::MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000338 rtc::scoped_refptr<MockStatsObserver>
339 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000340 EXPECT_TRUE(peer_connection_->GetStats(
341 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
343 return observer->AudioOutputLevel();
344 }
345
346 int GetAudioInputLevelStats() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000347 rtc::scoped_refptr<MockStatsObserver>
348 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000349 EXPECT_TRUE(peer_connection_->GetStats(
350 observer, NULL, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
352 return observer->AudioInputLevel();
353 }
354
355 int GetBytesReceivedStats(webrtc::MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000356 rtc::scoped_refptr<MockStatsObserver>
357 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000358 EXPECT_TRUE(peer_connection_->GetStats(
359 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
361 return observer->BytesReceived();
362 }
363
364 int GetBytesSentStats(webrtc::MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000365 rtc::scoped_refptr<MockStatsObserver>
366 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000367 EXPECT_TRUE(peer_connection_->GetStats(
368 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
370 return observer->BytesSent();
371 }
372
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000373 int GetAvailableReceivedBandwidthStats() {
374 rtc::scoped_refptr<MockStatsObserver>
375 observer(new rtc::RefCountedObject<MockStatsObserver>());
376 EXPECT_TRUE(peer_connection_->GetStats(
377 observer, NULL, PeerConnectionInterface::kStatsOutputLevelStandard));
378 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
379 int bw = observer->AvailableReceiveBandwidth();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000380 return bw;
381 }
382
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383 int rendered_width() {
384 EXPECT_FALSE(fake_video_renderers_.empty());
385 return fake_video_renderers_.empty() ? 1 :
386 fake_video_renderers_.begin()->second->width();
387 }
388
389 int rendered_height() {
390 EXPECT_FALSE(fake_video_renderers_.empty());
391 return fake_video_renderers_.empty() ? 1 :
392 fake_video_renderers_.begin()->second->height();
393 }
394
395 size_t number_of_remote_streams() {
396 if (!pc())
397 return 0;
398 return pc()->remote_streams()->count();
399 }
400
401 StreamCollectionInterface* remote_streams() {
402 if (!pc()) {
403 ADD_FAILURE();
404 return NULL;
405 }
406 return pc()->remote_streams();
407 }
408
409 StreamCollectionInterface* local_streams() {
410 if (!pc()) {
411 ADD_FAILURE();
412 return NULL;
413 }
414 return pc()->local_streams();
415 }
416
417 webrtc::PeerConnectionInterface::SignalingState signaling_state() {
418 return pc()->signaling_state();
419 }
420
421 webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() {
422 return pc()->ice_connection_state();
423 }
424
425 webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() {
426 return pc()->ice_gathering_state();
427 }
428
429 // PeerConnectionObserver callbacks.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430 virtual void OnMessage(const std::string&) {}
431 virtual void OnSignalingMessage(const std::string& /*msg*/) {}
432 virtual void OnSignalingChange(
433 webrtc::PeerConnectionInterface::SignalingState new_state) {
434 EXPECT_EQ(peer_connection_->signaling_state(), new_state);
435 }
436 virtual void OnAddStream(webrtc::MediaStreamInterface* media_stream) {
437 for (size_t i = 0; i < media_stream->GetVideoTracks().size(); ++i) {
438 const std::string id = media_stream->GetVideoTracks()[i]->id();
439 ASSERT_TRUE(fake_video_renderers_.find(id) ==
440 fake_video_renderers_.end());
441 fake_video_renderers_[id] = new webrtc::FakeVideoTrackRenderer(
442 media_stream->GetVideoTracks()[i]);
443 }
444 }
445 virtual void OnRemoveStream(webrtc::MediaStreamInterface* media_stream) {}
446 virtual void OnRenegotiationNeeded() {}
447 virtual void OnIceConnectionChange(
448 webrtc::PeerConnectionInterface::IceConnectionState new_state) {
449 EXPECT_EQ(peer_connection_->ice_connection_state(), new_state);
450 }
451 virtual void OnIceGatheringChange(
452 webrtc::PeerConnectionInterface::IceGatheringState new_state) {
453 EXPECT_EQ(peer_connection_->ice_gathering_state(), new_state);
454 }
455 virtual void OnIceCandidate(
456 const webrtc::IceCandidateInterface* /*candidate*/) {}
457
458 webrtc::PeerConnectionInterface* pc() {
459 return peer_connection_.get();
460 }
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000461 void StopVideoCapturers() {
462 for (std::vector<cricket::VideoCapturer*>::iterator it =
463 video_capturers_.begin(); it != video_capturers_.end(); ++it) {
464 (*it)->Stop();
465 }
466 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000467
468 protected:
469 explicit PeerConnectionTestClientBase(const std::string& id)
470 : id_(id),
471 expect_ice_restart_(false),
472 fake_video_decoder_factory_(NULL),
473 fake_video_encoder_factory_(NULL),
474 video_decoder_factory_enabled_(false),
475 signaling_message_receiver_(NULL) {
476 }
477 bool Init(const MediaConstraintsInterface* constraints) {
478 EXPECT_TRUE(!peer_connection_);
479 EXPECT_TRUE(!peer_connection_factory_);
480 allocator_factory_ = webrtc::FakePortAllocatorFactory::Create();
481 if (!allocator_factory_) {
482 return false;
483 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484 fake_audio_capture_module_ = FakeAudioCaptureModule::Create(
jiayl@webrtc.org3987b6d2014-09-24 17:14:05 +0000485 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000486
487 if (fake_audio_capture_module_ == NULL) {
488 return false;
489 }
490 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory();
491 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory();
492 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000493 rtc::Thread::Current(), rtc::Thread::Current(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494 fake_audio_capture_module_, fake_video_encoder_factory_,
495 fake_video_decoder_factory_);
496 if (!peer_connection_factory_) {
497 return false;
498 }
499 peer_connection_ = CreatePeerConnection(allocator_factory_.get(),
500 constraints);
501 return peer_connection_.get() != NULL;
502 }
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000503 virtual rtc::scoped_refptr<webrtc::PeerConnectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000504 CreatePeerConnection(webrtc::PortAllocatorFactoryInterface* factory,
505 const MediaConstraintsInterface* constraints) = 0;
506 MessageReceiver* signaling_message_receiver() {
507 return signaling_message_receiver_;
508 }
509 webrtc::PeerConnectionFactoryInterface* peer_connection_factory() {
510 return peer_connection_factory_.get();
511 }
512
513 virtual bool can_receive_audio() = 0;
514 virtual bool can_receive_video() = 0;
515 const std::string& id() const { return id_; }
516
517 private:
518 class DummyDtmfObserver : public DtmfSenderObserverInterface {
519 public:
520 DummyDtmfObserver() : completed_(false) {}
521
522 // Implements DtmfSenderObserverInterface.
523 void OnToneChange(const std::string& tone) {
524 tones_.push_back(tone);
525 if (tone.empty()) {
526 completed_ = true;
527 }
528 }
529
530 void Verify(const std::vector<std::string>& tones) const {
531 ASSERT_TRUE(tones_.size() == tones.size());
532 EXPECT_TRUE(std::equal(tones.begin(), tones.end(), tones_.begin()));
533 }
534
535 bool completed() const { return completed_; }
536
537 private:
538 bool completed_;
539 std::vector<std::string> tones_;
540 };
541
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000542 rtc::scoped_refptr<webrtc::VideoTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000543 CreateLocalVideoTrack(const std::string stream_label) {
544 // Set max frame rate to 10fps to reduce the risk of the tests to be flaky.
545 FakeConstraints source_constraints = video_constraints_;
546 source_constraints.SetMandatoryMaxFrameRate(10);
547
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000548 cricket::FakeVideoCapturer* fake_capturer =
549 new webrtc::FakePeriodicVideoCapturer();
550 video_capturers_.push_back(fake_capturer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000551 rtc::scoped_refptr<webrtc::VideoSourceInterface> source =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000552 peer_connection_factory_->CreateVideoSource(
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000553 fake_capturer, &source_constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000554 std::string label = stream_label + kVideoTrackLabelBase;
555 return peer_connection_factory_->CreateVideoTrack(label, source);
556 }
557
558 std::string id_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000560 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 allocator_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000562 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
563 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564 peer_connection_factory_;
565
566 typedef std::pair<std::string, std::string> IceUfragPwdPair;
567 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_;
568 bool expect_ice_restart_;
569
570 // Needed to keep track of number of frames send.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000571 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 // Needed to keep track of number of frames received.
573 typedef std::map<std::string, webrtc::FakeVideoTrackRenderer*> RenderMap;
574 RenderMap fake_video_renderers_;
575 // Needed to keep track of number of frames received when external decoder
576 // used.
577 FakeWebRtcVideoDecoderFactory* fake_video_decoder_factory_;
578 FakeWebRtcVideoEncoderFactory* fake_video_encoder_factory_;
579 bool video_decoder_factory_enabled_;
580 webrtc::FakeConstraints video_constraints_;
581
582 // For remote peer communication.
583 MessageReceiver* signaling_message_receiver_;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000584
585 // Store references to the video capturers we've created, so that we can stop
586 // them, if required.
587 std::vector<cricket::VideoCapturer*> video_capturers_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000588};
589
590class JsepTestClient
591 : public PeerConnectionTestClientBase<JsepMessageReceiver> {
592 public:
593 static JsepTestClient* CreateClient(
594 const std::string& id,
595 const MediaConstraintsInterface* constraints) {
596 JsepTestClient* client(new JsepTestClient(id));
597 if (!client->Init(constraints)) {
598 delete client;
599 return NULL;
600 }
601 return client;
602 }
603 ~JsepTestClient() {}
604
605 virtual void Negotiate() {
606 Negotiate(true, true);
607 }
608 virtual void Negotiate(bool audio, bool video) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000609 rtc::scoped_ptr<SessionDescriptionInterface> offer;
pbos@webrtc.orgceb956b2014-09-04 15:27:49 +0000610 ASSERT_TRUE(DoCreateOffer(offer.use()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000611
612 if (offer->description()->GetContentByName("audio")) {
613 offer->description()->GetContentByName("audio")->rejected = !audio;
614 }
615 if (offer->description()->GetContentByName("video")) {
616 offer->description()->GetContentByName("video")->rejected = !video;
617 }
618
619 std::string sdp;
620 EXPECT_TRUE(offer->ToString(&sdp));
621 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
622 signaling_message_receiver()->ReceiveSdpMessage(
623 webrtc::SessionDescriptionInterface::kOffer, sdp);
624 }
625 // JsepMessageReceiver callback.
626 virtual void ReceiveSdpMessage(const std::string& type,
627 std::string& msg) {
628 FilterIncomingSdpMessage(&msg);
629 if (type == webrtc::SessionDescriptionInterface::kOffer) {
630 HandleIncomingOffer(msg);
631 } else {
632 HandleIncomingAnswer(msg);
633 }
634 }
635 // JsepMessageReceiver callback.
636 virtual void ReceiveIceMessage(const std::string& sdp_mid,
637 int sdp_mline_index,
638 const std::string& msg) {
639 LOG(INFO) << id() << "ReceiveIceMessage";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000640 rtc::scoped_ptr<webrtc::IceCandidateInterface> candidate(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000641 webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, msg, NULL));
642 EXPECT_TRUE(pc()->AddIceCandidate(candidate.get()));
643 }
644 // Implements PeerConnectionObserver functions needed by Jsep.
645 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
646 LOG(INFO) << id() << "OnIceCandidate";
647
648 std::string ice_sdp;
649 EXPECT_TRUE(candidate->ToString(&ice_sdp));
650 if (signaling_message_receiver() == NULL) {
651 // Remote party may be deleted.
652 return;
653 }
654 signaling_message_receiver()->ReceiveIceMessage(candidate->sdp_mid(),
655 candidate->sdp_mline_index(), ice_sdp);
656 }
657
658 void IceRestart() {
659 session_description_constraints_.SetMandatoryIceRestart(true);
660 SetExpectIceRestart(true);
661 }
662
663 void SetReceiveAudioVideo(bool audio, bool video) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000664 SetReceiveAudio(audio);
665 SetReceiveVideo(video);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666 ASSERT_EQ(audio, can_receive_audio());
667 ASSERT_EQ(video, can_receive_video());
668 }
669
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000670 void SetReceiveAudio(bool audio) {
671 if (audio && can_receive_audio())
672 return;
673 session_description_constraints_.SetMandatoryReceiveAudio(audio);
674 }
675
676 void SetReceiveVideo(bool video) {
677 if (video && can_receive_video())
678 return;
679 session_description_constraints_.SetMandatoryReceiveVideo(video);
680 }
681
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000682 void RemoveMsidFromReceivedSdp(bool remove) {
683 remove_msid_ = remove;
684 }
685
686 void RemoveSdesCryptoFromReceivedSdp(bool remove) {
687 remove_sdes_ = remove;
688 }
689
690 void RemoveBundleFromReceivedSdp(bool remove) {
691 remove_bundle_ = remove;
692 }
693
694 virtual bool can_receive_audio() {
695 bool value;
696 if (webrtc::FindConstraint(&session_description_constraints_,
697 MediaConstraintsInterface::kOfferToReceiveAudio, &value, NULL)) {
698 return value;
699 }
700 return true;
701 }
702
703 virtual bool can_receive_video() {
704 bool value;
705 if (webrtc::FindConstraint(&session_description_constraints_,
706 MediaConstraintsInterface::kOfferToReceiveVideo, &value, NULL)) {
707 return value;
708 }
709 return true;
710 }
711
712 virtual void OnIceComplete() {
713 LOG(INFO) << id() << "OnIceComplete";
714 }
715
716 virtual void OnDataChannel(DataChannelInterface* data_channel) {
717 LOG(INFO) << id() << "OnDataChannel";
718 data_channel_ = data_channel;
719 data_observer_.reset(new MockDataChannelObserver(data_channel));
720 }
721
722 void CreateDataChannel() {
723 data_channel_ = pc()->CreateDataChannel(kDataChannelLabel,
724 NULL);
725 ASSERT_TRUE(data_channel_.get() != NULL);
726 data_observer_.reset(new MockDataChannelObserver(data_channel_));
727 }
728
729 DataChannelInterface* data_channel() { return data_channel_; }
730 const MockDataChannelObserver* data_observer() const {
731 return data_observer_.get();
732 }
733
734 protected:
735 explicit JsepTestClient(const std::string& id)
736 : PeerConnectionTestClientBase<JsepMessageReceiver>(id),
737 remove_msid_(false),
738 remove_bundle_(false),
739 remove_sdes_(false) {
740 }
741
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000742 virtual rtc::scoped_refptr<webrtc::PeerConnectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 CreatePeerConnection(webrtc::PortAllocatorFactoryInterface* factory,
744 const MediaConstraintsInterface* constraints) {
745 // CreatePeerConnection with IceServers.
746 webrtc::PeerConnectionInterface::IceServers ice_servers;
747 webrtc::PeerConnectionInterface::IceServer ice_server;
748 ice_server.uri = "stun:stun.l.google.com:19302";
749 ice_servers.push_back(ice_server);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000750
buildbot@webrtc.org61c1b8e2014-04-09 06:06:38 +0000751 FakeIdentityService* dtls_service =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000752 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
buildbot@webrtc.org61c1b8e2014-04-09 06:06:38 +0000753 new FakeIdentityService() : NULL;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 return peer_connection_factory()->CreatePeerConnection(
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000755 ice_servers, constraints, factory, dtls_service, this);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 }
757
758 void HandleIncomingOffer(const std::string& msg) {
759 LOG(INFO) << id() << "HandleIncomingOffer ";
760 if (NumberOfLocalMediaStreams() == 0) {
761 // If we are not sending any streams ourselves it is time to add some.
762 AddMediaStream(true, true);
763 }
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000764 rtc::scoped_ptr<SessionDescriptionInterface> desc(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765 webrtc::CreateSessionDescription("offer", msg, NULL));
766 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000767 rtc::scoped_ptr<SessionDescriptionInterface> answer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000768 EXPECT_TRUE(DoCreateAnswer(answer.use()));
769 std::string sdp;
770 EXPECT_TRUE(answer->ToString(&sdp));
771 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
772 if (signaling_message_receiver()) {
773 signaling_message_receiver()->ReceiveSdpMessage(
774 webrtc::SessionDescriptionInterface::kAnswer, sdp);
775 }
776 }
777
778 void HandleIncomingAnswer(const std::string& msg) {
779 LOG(INFO) << id() << "HandleIncomingAnswer";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000780 rtc::scoped_ptr<SessionDescriptionInterface> desc(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 webrtc::CreateSessionDescription("answer", msg, NULL));
782 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
783 }
784
785 bool DoCreateOfferAnswer(SessionDescriptionInterface** desc,
786 bool offer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000787 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
788 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 MockCreateSessionDescriptionObserver>());
790 if (offer) {
791 pc()->CreateOffer(observer, &session_description_constraints_);
792 } else {
793 pc()->CreateAnswer(observer, &session_description_constraints_);
794 }
795 EXPECT_EQ_WAIT(true, observer->called(), kMaxWaitMs);
796 *desc = observer->release_desc();
797 if (observer->result() && ExpectIceRestart()) {
798 EXPECT_EQ(0u, (*desc)->candidates(0)->count());
799 }
800 return observer->result();
801 }
802
803 bool DoCreateOffer(SessionDescriptionInterface** desc) {
804 return DoCreateOfferAnswer(desc, true);
805 }
806
807 bool DoCreateAnswer(SessionDescriptionInterface** desc) {
808 return DoCreateOfferAnswer(desc, false);
809 }
810
811 bool DoSetLocalDescription(SessionDescriptionInterface* desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000812 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
813 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814 MockSetSessionDescriptionObserver>());
815 LOG(INFO) << id() << "SetLocalDescription ";
816 pc()->SetLocalDescription(observer, desc);
817 // Ignore the observer result. If we wait for the result with
818 // EXPECT_TRUE_WAIT, local ice candidates might be sent to the remote peer
819 // before the offer which is an error.
820 // The reason is that EXPECT_TRUE_WAIT uses
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000821 // rtc::Thread::Current()->ProcessMessages(1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 // ProcessMessages waits at least 1ms but processes all messages before
823 // returning. Since this test is synchronous and send messages to the remote
824 // peer whenever a callback is invoked, this can lead to messages being
825 // sent to the remote peer in the wrong order.
826 // TODO(perkj): Find a way to check the result without risking that the
827 // order of sent messages are changed. Ex- by posting all messages that are
828 // sent to the remote peer.
829 return true;
830 }
831
832 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000833 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
834 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 MockSetSessionDescriptionObserver>());
836 LOG(INFO) << id() << "SetRemoteDescription ";
837 pc()->SetRemoteDescription(observer, desc);
838 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
839 return observer->result();
840 }
841
842 // This modifies all received SDP messages before they are processed.
843 void FilterIncomingSdpMessage(std::string* sdp) {
844 if (remove_msid_) {
845 const char kSdpSsrcAttribute[] = "a=ssrc:";
846 RemoveLinesFromSdp(kSdpSsrcAttribute, sdp);
847 const char kSdpMsidSupportedAttribute[] = "a=msid-semantic:";
848 RemoveLinesFromSdp(kSdpMsidSupportedAttribute, sdp);
849 }
850 if (remove_bundle_) {
851 const char kSdpBundleAttribute[] = "a=group:BUNDLE";
852 RemoveLinesFromSdp(kSdpBundleAttribute, sdp);
853 }
854 if (remove_sdes_) {
855 const char kSdpSdesCryptoAttribute[] = "a=crypto";
856 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp);
857 }
858 }
859
860 private:
861 webrtc::FakeConstraints session_description_constraints_;
862 bool remove_msid_; // True if MSID should be removed in received SDP.
863 bool remove_bundle_; // True if bundle should be removed in received SDP.
864 bool remove_sdes_; // True if a=crypto should be removed in received SDP.
865
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000866 rtc::scoped_refptr<DataChannelInterface> data_channel_;
867 rtc::scoped_ptr<MockDataChannelObserver> data_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868};
869
870template <typename SignalingClass>
871class P2PTestConductor : public testing::Test {
872 public:
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +0000873 P2PTestConductor()
874 : pss_(new rtc::PhysicalSocketServer),
875 ss_(new rtc::VirtualSocketServer(pss_.get())),
876 ss_scope_(ss_.get()) {}
877
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 bool SessionActive() {
879 return initiating_client_->SessionActive() &&
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +0000880 receiving_client_->SessionActive();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881 }
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +0000882
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 // Return true if the number of frames provided have been received or it is
884 // known that that will never occur (e.g. no frames will be sent or
885 // captured).
886 bool FramesNotPending(int audio_frames_to_receive,
887 int video_frames_to_receive) {
888 return VideoFramesReceivedCheck(video_frames_to_receive) &&
889 AudioFramesReceivedCheck(audio_frames_to_receive);
890 }
891 bool AudioFramesReceivedCheck(int frames_received) {
892 return initiating_client_->AudioFramesReceivedCheck(frames_received) &&
893 receiving_client_->AudioFramesReceivedCheck(frames_received);
894 }
895 bool VideoFramesReceivedCheck(int frames_received) {
896 return initiating_client_->VideoFramesReceivedCheck(frames_received) &&
897 receiving_client_->VideoFramesReceivedCheck(frames_received);
898 }
899 void VerifyDtmf() {
900 initiating_client_->VerifyDtmf();
901 receiving_client_->VerifyDtmf();
902 }
903
904 void TestUpdateOfferWithRejectedContent() {
905 initiating_client_->Negotiate(true, false);
906 EXPECT_TRUE_WAIT(
907 FramesNotPending(kEndAudioFrameCount * 2, kEndVideoFrameCount),
908 kMaxWaitForFramesMs);
909 // There shouldn't be any more video frame after the new offer is
910 // negotiated.
911 EXPECT_FALSE(VideoFramesReceivedCheck(kEndVideoFrameCount + 1));
912 }
913
914 void VerifyRenderedSize(int width, int height) {
915 EXPECT_EQ(width, receiving_client()->rendered_width());
916 EXPECT_EQ(height, receiving_client()->rendered_height());
917 EXPECT_EQ(width, initializing_client()->rendered_width());
918 EXPECT_EQ(height, initializing_client()->rendered_height());
919 }
920
921 void VerifySessionDescriptions() {
922 initiating_client_->VerifyRejectedMediaInSessionDescription();
923 receiving_client_->VerifyRejectedMediaInSessionDescription();
924 initiating_client_->VerifyLocalIceUfragAndPassword();
925 receiving_client_->VerifyLocalIceUfragAndPassword();
926 }
927
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 ~P2PTestConductor() {
929 if (initiating_client_) {
930 initiating_client_->set_signaling_message_receiver(NULL);
931 }
932 if (receiving_client_) {
933 receiving_client_->set_signaling_message_receiver(NULL);
934 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 }
936
937 bool CreateTestClients() {
938 return CreateTestClients(NULL, NULL);
939 }
940
941 bool CreateTestClients(MediaConstraintsInterface* init_constraints,
942 MediaConstraintsInterface* recv_constraints) {
943 initiating_client_.reset(SignalingClass::CreateClient("Caller: ",
944 init_constraints));
945 receiving_client_.reset(SignalingClass::CreateClient("Callee: ",
946 recv_constraints));
947 if (!initiating_client_ || !receiving_client_) {
948 return false;
949 }
950 initiating_client_->set_signaling_message_receiver(receiving_client_.get());
951 receiving_client_->set_signaling_message_receiver(initiating_client_.get());
952 return true;
953 }
954
955 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints,
956 const webrtc::FakeConstraints& recv_constraints) {
957 initiating_client_->SetVideoConstraints(init_constraints);
958 receiving_client_->SetVideoConstraints(recv_constraints);
959 }
960
961 void EnableVideoDecoderFactory() {
962 initiating_client_->EnableVideoDecoderFactory();
963 receiving_client_->EnableVideoDecoderFactory();
964 }
965
966 // This test sets up a call between two parties. Both parties send static
967 // frames to each other. Once the test is finished the number of sent frames
968 // is compared to the number of received frames.
969 void LocalP2PTest() {
970 if (initiating_client_->NumberOfLocalMediaStreams() == 0) {
971 initiating_client_->AddMediaStream(true, true);
972 }
973 initiating_client_->Negotiate();
974 const int kMaxWaitForActivationMs = 5000;
975 // Assert true is used here since next tests are guaranteed to fail and
976 // would eat up 5 seconds.
977 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
978 VerifySessionDescriptions();
979
980
981 int audio_frame_count = kEndAudioFrameCount;
982 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly.
983 if (!initiating_client_->can_receive_audio() ||
984 !receiving_client_->can_receive_audio()) {
985 audio_frame_count = -1;
986 }
987 int video_frame_count = kEndVideoFrameCount;
988 if (!initiating_client_->can_receive_video() ||
989 !receiving_client_->can_receive_video()) {
990 video_frame_count = -1;
991 }
992
993 if (audio_frame_count != -1 || video_frame_count != -1) {
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000994 // Audio or video is expected to flow, so both clients should reach the
995 // Connected state, and the offerer (ICE controller) should proceed to
996 // Completed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000997 // Note: These tests have been observed to fail under heavy load at
998 // shorter timeouts, so they may be flaky.
999 EXPECT_EQ_WAIT(
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001000 webrtc::PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001 initiating_client_->ice_connection_state(),
1002 kMaxWaitForFramesMs);
1003 EXPECT_EQ_WAIT(
1004 webrtc::PeerConnectionInterface::kIceConnectionConnected,
1005 receiving_client_->ice_connection_state(),
1006 kMaxWaitForFramesMs);
1007 }
1008
1009 if (initiating_client_->can_receive_audio() ||
1010 initiating_client_->can_receive_video()) {
1011 // The initiating client can receive media, so it must produce candidates
1012 // that will serve as destinations for that media.
1013 // TODO(bemasc): Understand why the state is not already Complete here, as
1014 // seems to be the case for the receiving client. This may indicate a bug
1015 // in the ICE gathering system.
1016 EXPECT_NE(webrtc::PeerConnectionInterface::kIceGatheringNew,
1017 initiating_client_->ice_gathering_state());
1018 }
1019 if (receiving_client_->can_receive_audio() ||
1020 receiving_client_->can_receive_video()) {
1021 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
1022 receiving_client_->ice_gathering_state(),
1023 kMaxWaitForFramesMs);
1024 }
1025
1026 EXPECT_TRUE_WAIT(FramesNotPending(audio_frame_count, video_frame_count),
1027 kMaxWaitForFramesMs);
1028 }
1029
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001030 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) {
1031 // Messages may get lost on the unreliable DataChannel, so we send multiple
1032 // times to avoid test flakiness.
1033 static const size_t kSendAttempts = 5;
1034
1035 for (size_t i = 0; i < kSendAttempts; ++i) {
1036 dc->Send(DataBuffer(data));
1037 }
1038 }
1039
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001040 SignalingClass* initializing_client() { return initiating_client_.get(); }
1041 SignalingClass* receiving_client() { return receiving_client_.get(); }
1042
1043 private:
pbos@webrtc.org9eacb8c2015-01-02 09:03:19 +00001044 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1045 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_;
1046 rtc::SocketServerScope ss_scope_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001047 rtc::scoped_ptr<SignalingClass> initiating_client_;
1048 rtc::scoped_ptr<SignalingClass> receiving_client_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001049};
1050typedef P2PTestConductor<JsepTestClient> JsepPeerConnectionP2PTestClient;
1051
kjellander@webrtc.orgd1cfa712013-10-16 16:51:52 +00001052// Disable for TSan v2, see
1053// https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
1054#if !defined(THREAD_SANITIZER)
1055
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056// This test sets up a Jsep call between two parties and test Dtmf.
stefan@webrtc.orgda790082013-09-17 13:11:38 +00001057// TODO(holmer): Disabled due to sometimes crashing on buildbots.
1058// See issue webrtc/2378.
1059TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 ASSERT_TRUE(CreateTestClients());
1061 LocalP2PTest();
1062 VerifyDtmf();
1063}
1064
1065// This test sets up a Jsep call between two parties and test that we can get a
1066// video aspect ratio of 16:9.
1067TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTest16To9) {
1068 ASSERT_TRUE(CreateTestClients());
1069 FakeConstraints constraint;
1070 double requested_ratio = 640.0/360;
1071 constraint.SetMandatoryMinAspectRatio(requested_ratio);
1072 SetVideoConstraints(constraint, constraint);
1073 LocalP2PTest();
1074
1075 ASSERT_LE(0, initializing_client()->rendered_height());
1076 double initiating_video_ratio =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001077 static_cast<double>(initializing_client()->rendered_width()) /
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 initializing_client()->rendered_height();
1079 EXPECT_LE(requested_ratio, initiating_video_ratio);
1080
1081 ASSERT_LE(0, receiving_client()->rendered_height());
1082 double receiving_video_ratio =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001083 static_cast<double>(receiving_client()->rendered_width()) /
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084 receiving_client()->rendered_height();
1085 EXPECT_LE(requested_ratio, receiving_video_ratio);
1086}
1087
1088// This test sets up a Jsep call between two parties and test that the
1089// received video has a resolution of 1280*720.
1090// TODO(mallinath): Enable when
1091// http://code.google.com/p/webrtc/issues/detail?id=981 is fixed.
1092TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTest1280By720) {
1093 ASSERT_TRUE(CreateTestClients());
1094 FakeConstraints constraint;
1095 constraint.SetMandatoryMinWidth(1280);
1096 constraint.SetMandatoryMinHeight(720);
1097 SetVideoConstraints(constraint, constraint);
1098 LocalP2PTest();
1099 VerifyRenderedSize(1280, 720);
1100}
1101
1102// This test sets up a call between two endpoints that are configured to use
1103// DTLS key agreement. As a result, DTLS is negotiated and used for transport.
1104TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001105 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 FakeConstraints setup_constraints;
1107 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1108 true);
1109 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1110 LocalP2PTest();
1111 VerifyRenderedSize(640, 480);
1112}
1113
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001114// This test sets up a audio call initially and then upgrades to audio/video,
1115// using DTLS.
mallinath@webrtc.org50bc5532013-10-21 17:58:35 +00001116TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestDtlsRenegotiate) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001117 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001118 FakeConstraints setup_constraints;
1119 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1120 true);
1121 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1122 receiving_client()->SetReceiveAudioVideo(true, false);
1123 LocalP2PTest();
1124 receiving_client()->SetReceiveAudioVideo(true, true);
1125 receiving_client()->Negotiate();
1126}
1127
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001128// This test sets up a call between two endpoints that are configured to use
1129// DTLS key agreement. The offerer don't support SDES. As a result, DTLS is
1130// negotiated and used for transport.
1131TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestOfferDtlsButNotSdes) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001132 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001133 FakeConstraints setup_constraints;
1134 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1135 true);
1136 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1137 receiving_client()->RemoveSdesCryptoFromReceivedSdp(true);
1138 LocalP2PTest();
1139 VerifyRenderedSize(640, 480);
1140}
1141
1142// This test sets up a Jsep call between two parties, and the callee only
1143// accept to receive video.
solenberg@webrtc.org503c3362015-02-12 13:12:50 +00001144TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestAnswerVideo) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001145 ASSERT_TRUE(CreateTestClients());
1146 receiving_client()->SetReceiveAudioVideo(false, true);
1147 LocalP2PTest();
1148}
1149
1150// This test sets up a Jsep call between two parties, and the callee only
1151// accept to receive audio.
solenberg@webrtc.org503c3362015-02-12 13:12:50 +00001152TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestAnswerAudio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001153 ASSERT_TRUE(CreateTestClients());
1154 receiving_client()->SetReceiveAudioVideo(true, false);
1155 LocalP2PTest();
1156}
1157
1158// This test sets up a Jsep call between two parties, and the callee reject both
1159// audio and video.
1160TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestAnswerNone) {
1161 ASSERT_TRUE(CreateTestClients());
1162 receiving_client()->SetReceiveAudioVideo(false, false);
1163 LocalP2PTest();
1164}
1165
1166// This test sets up an audio and video call between two parties. After the call
1167// runs for a while (10 frames), the caller sends an update offer with video
1168// being rejected. Once the re-negotiation is done, the video flow should stop
1169// and the audio flow should continue.
buildbot@webrtc.org688ed692014-05-14 18:26:09 +00001170// Disabled due to b/14955157.
1171TEST_F(JsepPeerConnectionP2PTestClient,
1172 DISABLED_UpdateOfferWithRejectedContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001173 ASSERT_TRUE(CreateTestClients());
1174 LocalP2PTest();
1175 TestUpdateOfferWithRejectedContent();
1176}
1177
1178// This test sets up a Jsep call between two parties. The MSID is removed from
1179// the SDP strings from the caller.
buildbot@webrtc.org688ed692014-05-14 18:26:09 +00001180// Disabled due to b/14955157.
1181TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestWithoutMsid) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001182 ASSERT_TRUE(CreateTestClients());
1183 receiving_client()->RemoveMsidFromReceivedSdp(true);
1184 // TODO(perkj): Currently there is a bug that cause audio to stop playing if
1185 // audio and video is muxed when MSID is disabled. Remove
1186 // SetRemoveBundleFromSdp once
1187 // https://code.google.com/p/webrtc/issues/detail?id=1193 is fixed.
1188 receiving_client()->RemoveBundleFromReceivedSdp(true);
1189 LocalP2PTest();
1190}
1191
1192// This test sets up a Jsep call between two parties and the initiating peer
1193// sends two steams.
1194// TODO(perkj): Disabled due to
1195// https://code.google.com/p/webrtc/issues/detail?id=1454
1196TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestTwoStreams) {
1197 ASSERT_TRUE(CreateTestClients());
1198 // Set optional video constraint to max 320pixels to decrease CPU usage.
1199 FakeConstraints constraint;
1200 constraint.SetOptionalMaxWidth(320);
1201 SetVideoConstraints(constraint, constraint);
1202 initializing_client()->AddMediaStream(true, true);
1203 initializing_client()->AddMediaStream(false, true);
1204 ASSERT_EQ(2u, initializing_client()->NumberOfLocalMediaStreams());
1205 LocalP2PTest();
1206 EXPECT_EQ(2u, receiving_client()->number_of_remote_streams());
1207}
1208
1209// Test that we can receive the audio output level from a remote audio track.
1210TEST_F(JsepPeerConnectionP2PTestClient, GetAudioOutputLevelStats) {
1211 ASSERT_TRUE(CreateTestClients());
1212 LocalP2PTest();
1213
1214 StreamCollectionInterface* remote_streams =
1215 initializing_client()->remote_streams();
1216 ASSERT_GT(remote_streams->count(), 0u);
1217 ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u);
1218 MediaStreamTrackInterface* remote_audio_track =
1219 remote_streams->at(0)->GetAudioTracks()[0];
1220
1221 // Get the audio output level stats. Note that the level is not available
1222 // until a RTCP packet has been received.
1223 EXPECT_TRUE_WAIT(
1224 initializing_client()->GetAudioOutputLevelStats(remote_audio_track) > 0,
1225 kMaxWaitForStatsMs);
1226}
1227
1228// Test that an audio input level is reported.
1229TEST_F(JsepPeerConnectionP2PTestClient, GetAudioInputLevelStats) {
1230 ASSERT_TRUE(CreateTestClients());
1231 LocalP2PTest();
1232
1233 // Get the audio input level stats. The level should be available very
1234 // soon after the test starts.
1235 EXPECT_TRUE_WAIT(initializing_client()->GetAudioInputLevelStats() > 0,
1236 kMaxWaitForStatsMs);
1237}
1238
1239// Test that we can get incoming byte counts from both audio and video tracks.
1240TEST_F(JsepPeerConnectionP2PTestClient, GetBytesReceivedStats) {
1241 ASSERT_TRUE(CreateTestClients());
1242 LocalP2PTest();
1243
1244 StreamCollectionInterface* remote_streams =
1245 initializing_client()->remote_streams();
1246 ASSERT_GT(remote_streams->count(), 0u);
1247 ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u);
1248 MediaStreamTrackInterface* remote_audio_track =
1249 remote_streams->at(0)->GetAudioTracks()[0];
1250 EXPECT_TRUE_WAIT(
1251 initializing_client()->GetBytesReceivedStats(remote_audio_track) > 0,
1252 kMaxWaitForStatsMs);
1253
1254 MediaStreamTrackInterface* remote_video_track =
1255 remote_streams->at(0)->GetVideoTracks()[0];
1256 EXPECT_TRUE_WAIT(
1257 initializing_client()->GetBytesReceivedStats(remote_video_track) > 0,
1258 kMaxWaitForStatsMs);
1259}
1260
1261// Test that we can get outgoing byte counts from both audio and video tracks.
1262TEST_F(JsepPeerConnectionP2PTestClient, GetBytesSentStats) {
1263 ASSERT_TRUE(CreateTestClients());
1264 LocalP2PTest();
1265
1266 StreamCollectionInterface* local_streams =
1267 initializing_client()->local_streams();
1268 ASSERT_GT(local_streams->count(), 0u);
1269 ASSERT_GT(local_streams->at(0)->GetAudioTracks().size(), 0u);
1270 MediaStreamTrackInterface* local_audio_track =
1271 local_streams->at(0)->GetAudioTracks()[0];
1272 EXPECT_TRUE_WAIT(
1273 initializing_client()->GetBytesSentStats(local_audio_track) > 0,
1274 kMaxWaitForStatsMs);
1275
1276 MediaStreamTrackInterface* local_video_track =
1277 local_streams->at(0)->GetVideoTracks()[0];
1278 EXPECT_TRUE_WAIT(
1279 initializing_client()->GetBytesSentStats(local_video_track) > 0,
1280 kMaxWaitForStatsMs);
1281}
1282
1283// This test sets up a call between two parties with audio, video and data.
1284TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestDataChannel) {
1285 FakeConstraints setup_constraints;
1286 setup_constraints.SetAllowRtpDataChannels();
1287 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1288 initializing_client()->CreateDataChannel();
1289 LocalP2PTest();
1290 ASSERT_TRUE(initializing_client()->data_channel() != NULL);
1291 ASSERT_TRUE(receiving_client()->data_channel() != NULL);
1292 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
1293 kMaxWaitMs);
1294 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(),
1295 kMaxWaitMs);
1296
1297 std::string data = "hello world";
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001298
1299 SendRtpData(initializing_client()->data_channel(), data);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(),
1301 kMaxWaitMs);
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001302
1303 SendRtpData(receiving_client()->data_channel(), data);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(),
1305 kMaxWaitMs);
1306
1307 receiving_client()->data_channel()->Close();
1308 // Send new offer and answer.
1309 receiving_client()->Negotiate();
1310 EXPECT_FALSE(initializing_client()->data_observer()->IsOpen());
1311 EXPECT_FALSE(receiving_client()->data_observer()->IsOpen());
1312}
1313
1314// This test sets up a call between two parties and creates a data channel.
1315// The test tests that received data is buffered unless an observer has been
1316// registered.
1317// Rtp data channels can receive data before the underlying
1318// transport has detected that a channel is writable and thus data can be
1319// received before the data channel state changes to open. That is hard to test
1320// but the same buffering is used in that case.
1321TEST_F(JsepPeerConnectionP2PTestClient, RegisterDataChannelObserver) {
1322 FakeConstraints setup_constraints;
1323 setup_constraints.SetAllowRtpDataChannels();
1324 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1325 initializing_client()->CreateDataChannel();
1326 initializing_client()->Negotiate();
1327
1328 ASSERT_TRUE(initializing_client()->data_channel() != NULL);
1329 ASSERT_TRUE(receiving_client()->data_channel() != NULL);
1330 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
1331 kMaxWaitMs);
1332 EXPECT_EQ_WAIT(DataChannelInterface::kOpen,
1333 receiving_client()->data_channel()->state(), kMaxWaitMs);
1334
1335 // Unregister the existing observer.
1336 receiving_client()->data_channel()->UnregisterObserver();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001337
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338 std::string data = "hello world";
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001339 SendRtpData(initializing_client()->data_channel(), data);
1340
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001341 // Wait a while to allow the sent data to arrive before an observer is
1342 // registered..
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001343 rtc::Thread::Current()->ProcessMessages(100);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001344
1345 MockDataChannelObserver new_observer(receiving_client()->data_channel());
1346 EXPECT_EQ_WAIT(data, new_observer.last_message(), kMaxWaitMs);
1347}
1348
1349// This test sets up a call between two parties with audio, video and but only
1350// the initiating client support data.
1351TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestReceiverDoesntSupportData) {
buildbot@webrtc.org61c1b8e2014-04-09 06:06:38 +00001352 FakeConstraints setup_constraints_1;
1353 setup_constraints_1.SetAllowRtpDataChannels();
1354 // Must disable DTLS to make negotiation succeed.
1355 setup_constraints_1.SetMandatory(
1356 MediaConstraintsInterface::kEnableDtlsSrtp, false);
1357 FakeConstraints setup_constraints_2;
1358 setup_constraints_2.SetMandatory(
1359 MediaConstraintsInterface::kEnableDtlsSrtp, false);
1360 ASSERT_TRUE(CreateTestClients(&setup_constraints_1, &setup_constraints_2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001361 initializing_client()->CreateDataChannel();
1362 LocalP2PTest();
1363 EXPECT_TRUE(initializing_client()->data_channel() != NULL);
1364 EXPECT_FALSE(receiving_client()->data_channel());
1365 EXPECT_FALSE(initializing_client()->data_observer()->IsOpen());
1366}
1367
1368// This test sets up a call between two parties with audio, video. When audio
1369// and video is setup and flowing and data channel is negotiated.
1370TEST_F(JsepPeerConnectionP2PTestClient, AddDataChannelAfterRenegotiation) {
1371 FakeConstraints setup_constraints;
1372 setup_constraints.SetAllowRtpDataChannels();
1373 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1374 LocalP2PTest();
1375 initializing_client()->CreateDataChannel();
1376 // Send new offer and answer.
1377 initializing_client()->Negotiate();
1378 ASSERT_TRUE(initializing_client()->data_channel() != NULL);
1379 ASSERT_TRUE(receiving_client()->data_channel() != NULL);
1380 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
1381 kMaxWaitMs);
1382 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(),
1383 kMaxWaitMs);
1384}
1385
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001386// This test sets up a Jsep call with SCTP DataChannel and verifies the
1387// negotiation is completed without error.
1388#ifdef HAVE_SCTP
1389TEST_F(JsepPeerConnectionP2PTestClient, CreateOfferWithSctpDataChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001390 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001391 FakeConstraints constraints;
1392 constraints.SetMandatory(
1393 MediaConstraintsInterface::kEnableDtlsSrtp, true);
1394 ASSERT_TRUE(CreateTestClients(&constraints, &constraints));
1395 initializing_client()->CreateDataChannel();
1396 initializing_client()->Negotiate(false, false);
1397}
1398#endif
1399
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001400// This test sets up a call between two parties with audio, and video.
1401// During the call, the initializing side restart ice and the test verifies that
1402// new ice candidates are generated and audio and video still can flow.
1403TEST_F(JsepPeerConnectionP2PTestClient, IceRestart) {
1404 ASSERT_TRUE(CreateTestClients());
1405
1406 // Negotiate and wait for ice completion and make sure audio and video plays.
1407 LocalP2PTest();
1408
1409 // Create a SDP string of the first audio candidate for both clients.
1410 const webrtc::IceCandidateCollection* audio_candidates_initiator =
1411 initializing_client()->pc()->local_description()->candidates(0);
1412 const webrtc::IceCandidateCollection* audio_candidates_receiver =
1413 receiving_client()->pc()->local_description()->candidates(0);
1414 ASSERT_GT(audio_candidates_initiator->count(), 0u);
1415 ASSERT_GT(audio_candidates_receiver->count(), 0u);
1416 std::string initiator_candidate;
1417 EXPECT_TRUE(
1418 audio_candidates_initiator->at(0)->ToString(&initiator_candidate));
1419 std::string receiver_candidate;
1420 EXPECT_TRUE(audio_candidates_receiver->at(0)->ToString(&receiver_candidate));
1421
1422 // Restart ice on the initializing client.
1423 receiving_client()->SetExpectIceRestart(true);
1424 initializing_client()->IceRestart();
1425
1426 // Negotiate and wait for ice completion again and make sure audio and video
1427 // plays.
1428 LocalP2PTest();
1429
1430 // Create a SDP string of the first audio candidate for both clients again.
1431 const webrtc::IceCandidateCollection* audio_candidates_initiator_restart =
1432 initializing_client()->pc()->local_description()->candidates(0);
1433 const webrtc::IceCandidateCollection* audio_candidates_reciever_restart =
1434 receiving_client()->pc()->local_description()->candidates(0);
1435 ASSERT_GT(audio_candidates_initiator_restart->count(), 0u);
1436 ASSERT_GT(audio_candidates_reciever_restart->count(), 0u);
1437 std::string initiator_candidate_restart;
1438 EXPECT_TRUE(audio_candidates_initiator_restart->at(0)->ToString(
1439 &initiator_candidate_restart));
1440 std::string receiver_candidate_restart;
1441 EXPECT_TRUE(audio_candidates_reciever_restart->at(0)->ToString(
1442 &receiver_candidate_restart));
1443
1444 // Verify that the first candidates in the local session descriptions has
1445 // changed.
1446 EXPECT_NE(initiator_candidate, initiator_candidate_restart);
1447 EXPECT_NE(receiver_candidate, receiver_candidate_restart);
1448}
1449
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450// This test sets up a Jsep call between two parties with external
1451// VideoDecoderFactory.
stefan@webrtc.orgda790082013-09-17 13:11:38 +00001452// TODO(holmer): Disabled due to sometimes crashing on buildbots.
1453// See issue webrtc/2378.
1454TEST_F(JsepPeerConnectionP2PTestClient,
1455 DISABLED_LocalP2PTestWithVideoDecoderFactory) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001456 ASSERT_TRUE(CreateTestClients());
1457 EnableVideoDecoderFactory();
1458 LocalP2PTest();
1459}
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001460
kjellander@webrtc.orgd1cfa712013-10-16 16:51:52 +00001461#endif // if !defined(THREAD_SANITIZER)