blob: 48cccf43b2a8522c22965f35b1211366b02afdfb [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2012, Google Inc.
4 *
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 "talk/app/webrtc/audiotrack.h"
29#include "talk/app/webrtc/jsepicecandidate.h"
30#include "talk/app/webrtc/jsepsessiondescription.h"
31#include "talk/app/webrtc/mediastreamsignaling.h"
32#include "talk/app/webrtc/streamcollection.h"
33#include "talk/app/webrtc/videotrack.h"
34#include "talk/app/webrtc/test/fakeconstraints.h"
35#include "talk/app/webrtc/webrtcsession.h"
36#include "talk/base/fakenetwork.h"
37#include "talk/base/firewallsocketserver.h"
38#include "talk/base/gunit.h"
39#include "talk/base/logging.h"
40#include "talk/base/network.h"
41#include "talk/base/physicalsocketserver.h"
42#include "talk/base/sslstreamadapter.h"
43#include "talk/base/stringutils.h"
44#include "talk/base/thread.h"
45#include "talk/base/virtualsocketserver.h"
46#include "talk/media/base/fakemediaengine.h"
47#include "talk/media/base/fakevideorenderer.h"
48#include "talk/media/base/mediachannel.h"
49#include "talk/media/devices/fakedevicemanager.h"
50#include "talk/p2p/base/stunserver.h"
51#include "talk/p2p/base/teststunserver.h"
52#include "talk/p2p/client/basicportallocator.h"
53#include "talk/session/media/channelmanager.h"
54#include "talk/session/media/mediasession.h"
55
56#define MAYBE_SKIP_TEST(feature) \
57 if (!(feature())) { \
58 LOG(LS_INFO) << "Feature disabled... skipping"; \
59 return; \
60 }
61
62using cricket::BaseSession;
63using cricket::DF_PLAY;
64using cricket::DF_SEND;
65using cricket::FakeVoiceMediaChannel;
66using cricket::NS_GINGLE_P2P;
67using cricket::NS_JINGLE_ICE_UDP;
68using cricket::TransportInfo;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069using talk_base::SocketAddress;
70using talk_base::scoped_ptr;
71using webrtc::CreateSessionDescription;
72using webrtc::FakeConstraints;
73using webrtc::IceCandidateCollection;
74using webrtc::JsepIceCandidate;
75using webrtc::JsepSessionDescription;
76using webrtc::PeerConnectionInterface;
77using webrtc::SessionDescriptionInterface;
78using webrtc::StreamCollection;
79using webrtc::kMlineMismatch;
80using webrtc::kSdpWithoutCrypto;
81using webrtc::kSessionError;
82using webrtc::kSetLocalSdpFailed;
83using webrtc::kSetRemoteSdpFailed;
84using webrtc::kPushDownAnswerTDFailed;
85using webrtc::kPushDownPranswerTDFailed;
86
87static const SocketAddress kClientAddr1("11.11.11.11", 0);
88static const SocketAddress kClientAddr2("22.22.22.22", 0);
89static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT);
90
91static const char kSessionVersion[] = "1";
92
93static const char kStream1[] = "stream1";
94static const char kVideoTrack1[] = "video1";
95static const char kAudioTrack1[] = "audio1";
96
97static const char kStream2[] = "stream2";
98static const char kVideoTrack2[] = "video2";
99static const char kAudioTrack2[] = "audio2";
100
101// Media index of candidates belonging to the first media content.
102static const int kMediaContentIndex0 = 0;
103static const char kMediaContentName0[] = "audio";
104
105// Media index of candidates belonging to the second media content.
106static const int kMediaContentIndex1 = 1;
107static const char kMediaContentName1[] = "video";
108
109static const int kIceCandidatesTimeout = 10000;
110
111static const cricket::AudioCodec
112 kTelephoneEventCodec(106, "telephone-event", 8000, 0, 1, 0);
113static const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
114static const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
115
116// Add some extra |newlines| to the |message| after |line|.
117static void InjectAfter(const std::string& line,
118 const std::string& newlines,
119 std::string* message) {
120 const std::string tmp = line + newlines;
121 talk_base::replace_substrs(line.c_str(), line.length(),
122 tmp.c_str(), tmp.length(), message);
123}
124
125class MockIceObserver : public webrtc::IceObserver {
126 public:
127 MockIceObserver()
128 : oncandidatesready_(false),
129 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
130 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
131 }
132
133 virtual void OnIceConnectionChange(
134 PeerConnectionInterface::IceConnectionState new_state) {
135 ice_connection_state_ = new_state;
136 }
137 virtual void OnIceGatheringChange(
138 PeerConnectionInterface::IceGatheringState new_state) {
139 // We can never transition back to "new".
140 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
141 ice_gathering_state_ = new_state;
142
143 // oncandidatesready_ really means "ICE gathering is complete".
144 // This if statement ensures that this value remains correct when we
145 // transition from kIceGatheringComplete to kIceGatheringGathering.
146 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
147 oncandidatesready_ = false;
148 }
149 }
150
151 // Found a new candidate.
152 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
153 if (candidate->sdp_mline_index() == kMediaContentIndex0) {
154 mline_0_candidates_.push_back(candidate->candidate());
155 } else if (candidate->sdp_mline_index() == kMediaContentIndex1) {
156 mline_1_candidates_.push_back(candidate->candidate());
157 }
158 // The ICE gathering state should always be Gathering when a candidate is
159 // received (or possibly Completed in the case of the final candidate).
160 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
161 }
162
163 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
164 virtual void OnIceComplete() {
165 EXPECT_FALSE(oncandidatesready_);
166 oncandidatesready_ = true;
167
168 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
169 // be called approximately simultaneously. For ease of testing, this
170 // check additionally requires that they be called in the above order.
171 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
172 ice_gathering_state_);
173 }
174
175 bool oncandidatesready_;
176 std::vector<cricket::Candidate> mline_0_candidates_;
177 std::vector<cricket::Candidate> mline_1_candidates_;
178 PeerConnectionInterface::IceConnectionState ice_connection_state_;
179 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
180};
181
182class WebRtcSessionForTest : public webrtc::WebRtcSession {
183 public:
184 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
185 talk_base::Thread* signaling_thread,
186 talk_base::Thread* worker_thread,
187 cricket::PortAllocator* port_allocator,
188 webrtc::IceObserver* ice_observer,
189 webrtc::MediaStreamSignaling* mediastream_signaling)
190 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
191 mediastream_signaling) {
192 RegisterIceObserver(ice_observer);
193 }
194 virtual ~WebRtcSessionForTest() {}
195
196 using cricket::BaseSession::GetTransportProxy;
197 using webrtc::WebRtcSession::SetAudioPlayout;
198 using webrtc::WebRtcSession::SetAudioSend;
199 using webrtc::WebRtcSession::SetCaptureDevice;
200 using webrtc::WebRtcSession::SetVideoPlayout;
201 using webrtc::WebRtcSession::SetVideoSend;
202};
203
204class FakeMediaStreamSignaling : public webrtc::MediaStreamSignaling,
205 public webrtc::MediaStreamSignalingObserver {
206 public:
207 FakeMediaStreamSignaling() :
208 webrtc::MediaStreamSignaling(talk_base::Thread::Current(), this) {
209 }
210
211 void SendAudioVideoStream1() {
212 ClearLocalStreams();
213 AddLocalStream(CreateStream(kStream1, kAudioTrack1, kVideoTrack1));
214 }
215
216 void SendAudioVideoStream2() {
217 ClearLocalStreams();
218 AddLocalStream(CreateStream(kStream2, kAudioTrack2, kVideoTrack2));
219 }
220
221 void SendAudioVideoStream1And2() {
222 ClearLocalStreams();
223 AddLocalStream(CreateStream(kStream1, kAudioTrack1, kVideoTrack1));
224 AddLocalStream(CreateStream(kStream2, kAudioTrack2, kVideoTrack2));
225 }
226
227 void SendNothing() {
228 ClearLocalStreams();
229 }
230
231 void UseOptionsAudioOnly() {
232 ClearLocalStreams();
233 AddLocalStream(CreateStream(kStream2, kAudioTrack2, ""));
234 }
235
236 void UseOptionsVideoOnly() {
237 ClearLocalStreams();
238 AddLocalStream(CreateStream(kStream2, "", kVideoTrack2));
239 }
240
241 void ClearLocalStreams() {
242 while (local_streams()->count() != 0) {
243 RemoveLocalStream(local_streams()->at(0));
244 }
245 }
246
247 // Implements MediaStreamSignalingObserver.
248 virtual void OnAddRemoteStream(webrtc::MediaStreamInterface* stream) {
249 }
250 virtual void OnRemoveRemoteStream(webrtc::MediaStreamInterface* stream) {
251 }
252 virtual void OnAddDataChannel(webrtc::DataChannelInterface* data_channel) {
253 }
254 virtual void OnAddLocalAudioTrack(webrtc::MediaStreamInterface* stream,
255 webrtc::AudioTrackInterface* audio_track,
256 uint32 ssrc) {
257 }
258 virtual void OnAddLocalVideoTrack(webrtc::MediaStreamInterface* stream,
259 webrtc::VideoTrackInterface* video_track,
260 uint32 ssrc) {
261 }
262 virtual void OnAddRemoteAudioTrack(webrtc::MediaStreamInterface* stream,
263 webrtc::AudioTrackInterface* audio_track,
264 uint32 ssrc) {
265 }
266
267 virtual void OnAddRemoteVideoTrack(webrtc::MediaStreamInterface* stream,
268 webrtc::VideoTrackInterface* video_track,
269 uint32 ssrc) {
270 }
271
272 virtual void OnRemoveRemoteAudioTrack(
273 webrtc::MediaStreamInterface* stream,
274 webrtc::AudioTrackInterface* audio_track) {
275 }
276
277 virtual void OnRemoveRemoteVideoTrack(
278 webrtc::MediaStreamInterface* stream,
279 webrtc::VideoTrackInterface* video_track) {
280 }
281
282 virtual void OnRemoveLocalAudioTrack(
283 webrtc::MediaStreamInterface* stream,
284 webrtc::AudioTrackInterface* audio_track) {
285 }
286 virtual void OnRemoveLocalVideoTrack(
287 webrtc::MediaStreamInterface* stream,
288 webrtc::VideoTrackInterface* video_track) {
289 }
290 virtual void OnRemoveLocalStream(webrtc::MediaStreamInterface* stream) {
291 }
292
293 private:
294 talk_base::scoped_refptr<webrtc::MediaStreamInterface> CreateStream(
295 const std::string& stream_label,
296 const std::string& audio_track_id,
297 const std::string& video_track_id) {
298 talk_base::scoped_refptr<webrtc::MediaStreamInterface> stream(
299 webrtc::MediaStream::Create(stream_label));
300
301 if (!audio_track_id.empty()) {
302 talk_base::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
303 webrtc::AudioTrack::Create(audio_track_id, NULL));
304 stream->AddTrack(audio_track);
305 }
306
307 if (!video_track_id.empty()) {
308 talk_base::scoped_refptr<webrtc::VideoTrackInterface> video_track(
309 webrtc::VideoTrack::Create(video_track_id, NULL));
310 stream->AddTrack(video_track);
311 }
312 return stream;
313 }
314
315 cricket::MediaSessionOptions options_;
316};
317
318class WebRtcSessionTest : public testing::Test {
319 protected:
320 // TODO Investigate why ChannelManager crashes, if it's created
321 // after stun_server.
322 WebRtcSessionTest()
323 : media_engine_(new cricket::FakeMediaEngine()),
324 data_engine_(new cricket::FakeDataEngine()),
325 device_manager_(new cricket::FakeDeviceManager()),
326 channel_manager_(new cricket::ChannelManager(
327 media_engine_, data_engine_, device_manager_,
328 new cricket::CaptureManager(), talk_base::Thread::Current())),
329 tdesc_factory_(new cricket::TransportDescriptionFactory()),
330 desc_factory_(new cricket::MediaSessionDescriptionFactory(
331 channel_manager_.get(), tdesc_factory_.get())),
332 pss_(new talk_base::PhysicalSocketServer),
333 vss_(new talk_base::VirtualSocketServer(pss_.get())),
334 fss_(new talk_base::FirewallSocketServer(vss_.get())),
335 ss_scope_(fss_.get()),
336 stun_server_(talk_base::Thread::Current(), kStunAddr),
337 allocator_(&network_manager_, kStunAddr,
338 SocketAddress(), SocketAddress(), SocketAddress()) {
339 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
340 allocator_.set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
341 cricket::PORTALLOCATOR_DISABLE_RELAY |
342 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
343 EXPECT_TRUE(channel_manager_->Init());
344 desc_factory_->set_add_legacy_streams(false);
345 }
346
347 void AddInterface(const SocketAddress& addr) {
348 network_manager_.AddInterface(addr);
349 }
350
351 void Init() {
352 ASSERT_TRUE(session_.get() == NULL);
353 session_.reset(new WebRtcSessionForTest(
354 channel_manager_.get(), talk_base::Thread::Current(),
355 talk_base::Thread::Current(), &allocator_,
356 &observer_,
357 &mediastream_signaling_));
358
359 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
360 observer_.ice_connection_state_);
361 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
362 observer_.ice_gathering_state_);
363
364 EXPECT_TRUE(session_->Initialize(constraints_.get()));
365 }
366
367 void InitWithDtmfCodec() {
368 // Add kTelephoneEventCodec for dtmf test.
369 std::vector<cricket::AudioCodec> codecs;
370 codecs.push_back(kTelephoneEventCodec);
371 media_engine_->SetAudioCodecs(codecs);
372 desc_factory_->set_audio_codecs(codecs);
373 Init();
374 }
375
376 void InitWithDtls() {
377 constraints_.reset(new FakeConstraints());
378 constraints_->AddOptional(
379 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, true);
380
381 Init();
382 }
383
384 // Creates a local offer and applies it. Starts ice.
385 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
386 // to decide which streams to create.
387 void InitiateCall() {
388 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
389 SetLocalDescriptionWithoutError(offer);
390 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
391 observer_.ice_gathering_state_,
392 kIceCandidatesTimeout);
393 }
394
395 bool ChannelsExist() {
396 return (session_->voice_channel() != NULL &&
397 session_->video_channel() != NULL);
398 }
399
400 void CheckTransportChannels() {
401 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
402 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
403 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
404 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
405 }
406
407 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
408 ASSERT_TRUE(session_.get() != NULL);
409 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
410 ASSERT_TRUE(content != NULL);
411 const cricket::AudioContentDescription* audio_content =
412 static_cast<const cricket::AudioContentDescription*>(
413 content->description);
414 ASSERT_TRUE(audio_content != NULL);
415 ASSERT_EQ(1U, audio_content->cryptos().size());
416 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
417 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
418 audio_content->cryptos()[0].cipher_suite);
419 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
420 audio_content->protocol());
421
422 content = cricket::GetFirstVideoContent(sdp);
423 ASSERT_TRUE(content != NULL);
424 const cricket::VideoContentDescription* video_content =
425 static_cast<const cricket::VideoContentDescription*>(
426 content->description);
427 ASSERT_TRUE(video_content != NULL);
428 ASSERT_EQ(1U, video_content->cryptos().size());
429 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
430 video_content->cryptos()[0].cipher_suite);
431 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
432 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
433 video_content->protocol());
434 }
435
436 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
437 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
438 ASSERT_TRUE(content != NULL);
439 const cricket::AudioContentDescription* audio_content =
440 static_cast<const cricket::AudioContentDescription*>(
441 content->description);
442 ASSERT_TRUE(audio_content != NULL);
443 ASSERT_EQ(0U, audio_content->cryptos().size());
444
445 content = cricket::GetFirstVideoContent(sdp);
446 ASSERT_TRUE(content != NULL);
447 const cricket::VideoContentDescription* video_content =
448 static_cast<const cricket::VideoContentDescription*>(
449 content->description);
450 ASSERT_TRUE(video_content != NULL);
451 ASSERT_EQ(0U, video_content->cryptos().size());
452
453 if (dtls) {
454 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
455 audio_content->protocol());
456 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
457 video_content->protocol());
458 } else {
459 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
460 audio_content->protocol());
461 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
462 video_content->protocol());
463 }
464 }
465
466 // Set the internal fake description factories to do DTLS-SRTP.
467 void SetFactoryDtlsSrtp() {
468 desc_factory_->set_secure(cricket::SEC_ENABLED);
469 std::string identity_name = "WebRTC" +
470 talk_base::ToString(talk_base::CreateRandomId());
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000471 identity_.reset(talk_base::SSLIdentity::Generate(identity_name));
472 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000473 tdesc_factory_->set_digest_algorithm(talk_base::DIGEST_SHA_256);
474 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
475 }
476
477 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
478 bool expected) {
479 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
480 ASSERT_TRUE(audio != NULL);
481 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
482 if (expected) {
483 ASSERT_EQ(std::string(talk_base::DIGEST_SHA_256), audio->description.
484 identity_fingerprint->algorithm);
485 }
486 const TransportInfo* video = sdp->GetTransportInfoByName("video");
487 ASSERT_TRUE(video != NULL);
488 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
489 if (expected) {
490 ASSERT_EQ(std::string(talk_base::DIGEST_SHA_256), video->description.
491 identity_fingerprint->algorithm);
492 }
493 }
494
495 void VerifyAnswerFromNonCryptoOffer() {
496 // Create a SDP without Crypto.
497 cricket::MediaSessionOptions options;
498 options.has_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000499 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000500 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000501 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 VerifyNoCryptoParams(offer->description(), false);
503 SetRemoteDescriptionExpectError("Called with a SDP without crypto enabled",
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000504 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000505 const webrtc::SessionDescriptionInterface* answer =
506 session_->CreateAnswer(NULL);
507 // Answer should be NULL as no crypto params in offer.
508 ASSERT_TRUE(answer == NULL);
509 }
510
511 void VerifyAnswerFromCryptoOffer() {
512 cricket::MediaSessionOptions options;
513 options.has_video = true;
514 options.bundle_enabled = true;
515 scoped_ptr<JsepSessionDescription> offer(
516 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
517 ASSERT_TRUE(offer.get() != NULL);
518 VerifyCryptoParams(offer->description());
519 SetRemoteDescriptionWithoutError(offer.release());
520 scoped_ptr<SessionDescriptionInterface> answer(
521 session_->CreateAnswer(NULL));
522 ASSERT_TRUE(answer.get() != NULL);
523 VerifyCryptoParams(answer->description());
524 }
525
526 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
527 const cricket::SessionDescription* desc2,
528 bool expect_equal) {
529 if (desc1->contents().size() != desc2->contents().size()) {
530 EXPECT_FALSE(expect_equal);
531 return;
532 }
533
534 const cricket::ContentInfos& contents = desc1->contents();
535 cricket::ContentInfos::const_iterator it = contents.begin();
536
537 for (; it != contents.end(); ++it) {
538 const cricket::TransportDescription* transport_desc1 =
539 desc1->GetTransportDescriptionByName(it->name);
540 const cricket::TransportDescription* transport_desc2 =
541 desc2->GetTransportDescriptionByName(it->name);
542 if (!transport_desc1 || !transport_desc2) {
543 EXPECT_FALSE(expect_equal);
544 return;
545 }
546 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
547 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
548 EXPECT_FALSE(expect_equal);
549 return;
550 }
551 }
552 EXPECT_TRUE(expect_equal);
553 }
554 // Creates a remote offer and and applies it as a remote description,
555 // creates a local answer and applies is as a local description.
556 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
557 // to decide which local and remote streams to create.
558 void CreateAndSetRemoteOfferAndLocalAnswer() {
559 SessionDescriptionInterface* offer = CreateRemoteOffer();
560 SetRemoteDescriptionWithoutError(offer);
561 SessionDescriptionInterface* answer = session_->CreateAnswer(NULL);
562 SetLocalDescriptionWithoutError(answer);
563 }
564 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
565 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
566 }
567 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
568 BaseSession::State expected_state) {
569 SetLocalDescriptionWithoutError(desc);
570 EXPECT_EQ(expected_state, session_->state());
571 }
572 void SetLocalDescriptionExpectError(const std::string& expected_error,
573 SessionDescriptionInterface* desc) {
574 std::string error;
575 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
576 EXPECT_NE(std::string::npos, error.find(kSetLocalSdpFailed));
577 EXPECT_NE(std::string::npos, error.find(expected_error));
578 }
579 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
580 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
581 }
582 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
583 BaseSession::State expected_state) {
584 SetRemoteDescriptionWithoutError(desc);
585 EXPECT_EQ(expected_state, session_->state());
586 }
587 void SetRemoteDescriptionExpectError(const std::string& expected_error,
588 SessionDescriptionInterface* desc) {
589 std::string error;
590 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
591 EXPECT_NE(std::string::npos, error.find(kSetRemoteSdpFailed));
592 EXPECT_NE(std::string::npos, error.find(expected_error));
593 }
594
595 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
596 SessionDescriptionInterface** nocrypto_answer) {
597 // Create a SDP without Crypto.
598 cricket::MediaSessionOptions options;
599 options.has_video = true;
600 options.bundle_enabled = true;
601 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
602 ASSERT_TRUE(*offer != NULL);
603 VerifyCryptoParams((*offer)->description());
604
605 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
606 cricket::SEC_DISABLED);
607 EXPECT_TRUE(*nocrypto_answer != NULL);
608 }
609
610 JsepSessionDescription* CreateRemoteOfferWithVersion(
611 cricket::MediaSessionOptions options,
612 cricket::SecurePolicy secure_policy,
613 const std::string& session_version,
614 const SessionDescriptionInterface* current_desc) {
615 std::string session_id = talk_base::ToString(talk_base::CreateRandomId64());
616 const cricket::SessionDescription* cricket_desc = NULL;
617 if (current_desc) {
618 cricket_desc = current_desc->description();
619 session_id = current_desc->session_id();
620 }
621
622 desc_factory_->set_secure(secure_policy);
623 JsepSessionDescription* offer(
624 new JsepSessionDescription(JsepSessionDescription::kOffer));
625 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
626 session_id, session_version)) {
627 delete offer;
628 offer = NULL;
629 }
630 return offer;
631 }
632 JsepSessionDescription* CreateRemoteOffer(
633 cricket::MediaSessionOptions options) {
634 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
635 kSessionVersion, NULL);
636 }
637 JsepSessionDescription* CreateRemoteOffer(
638 cricket::MediaSessionOptions options, cricket::SecurePolicy policy) {
639 return CreateRemoteOfferWithVersion(options, policy, kSessionVersion, NULL);
640 }
641 JsepSessionDescription* CreateRemoteOffer(
642 cricket::MediaSessionOptions options,
643 const SessionDescriptionInterface* current_desc) {
644 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
645 kSessionVersion, current_desc);
646 }
647
648 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
649 // before this function to decide which streams to create.
650 JsepSessionDescription* CreateRemoteOffer() {
651 cricket::MediaSessionOptions options;
652 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
653 return CreateRemoteOffer(options, session_->remote_description());
654 }
655
656 JsepSessionDescription* CreateRemoteAnswer(
657 const SessionDescriptionInterface* offer,
658 cricket::MediaSessionOptions options,
659 cricket::SecurePolicy policy) {
660 desc_factory_->set_secure(policy);
661 const std::string session_id =
662 talk_base::ToString(talk_base::CreateRandomId64());
663 JsepSessionDescription* answer(
664 new JsepSessionDescription(JsepSessionDescription::kAnswer));
665 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
666 options, NULL),
667 session_id, kSessionVersion)) {
668 delete answer;
669 answer = NULL;
670 }
671 return answer;
672 }
673
674 JsepSessionDescription* CreateRemoteAnswer(
675 const SessionDescriptionInterface* offer,
676 cricket::MediaSessionOptions options) {
677 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
678 }
679
680 // Creates an answer session description with streams based on
681 // |mediastream_signaling_|. Call
682 // mediastream_signaling_.UseOptionsWithStreamX() before this function
683 // to decide which streams to create.
684 JsepSessionDescription* CreateRemoteAnswer(
685 const SessionDescriptionInterface* offer) {
686 cricket::MediaSessionOptions options;
687 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
688 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
689 }
690
691 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
692 AddInterface(kClientAddr1);
693 Init();
694 mediastream_signaling_.SendAudioVideoStream1();
695 FakeConstraints constraints;
696 constraints.SetMandatoryUseRtpMux(bundle);
697 SessionDescriptionInterface* offer = session_->CreateOffer(&constraints);
698 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
699 // and answer.
700 SetLocalDescriptionWithoutError(offer);
701
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000702 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
703 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 std::string sdp;
705 EXPECT_TRUE(answer->ToString(&sdp));
706
707 size_t expected_candidate_num = 2;
708 if (!rtcp_mux) {
709 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
710 // for rtp and rtcp.
711 expected_candidate_num = 4;
712 // Disable rtcp-mux from the answer
713
714 const std::string kRtcpMux = "a=rtcp-mux";
715 const std::string kXRtcpMux = "a=xrtcp-mux";
716 talk_base::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
717 kXRtcpMux.c_str(), kXRtcpMux.length(),
718 &sdp);
719 }
720
721 SessionDescriptionInterface* new_answer = CreateSessionDescription(
722 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723
724 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000725 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
727 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
728 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
729 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
730 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
731 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
732 if (bundle) {
733 EXPECT_TRUE(c0.IsEquivalent(c1));
734 } else {
735 EXPECT_FALSE(c0.IsEquivalent(c1));
736 }
737 }
738 }
739 // Tests that we can only send DTMF when the dtmf codec is supported.
740 void TestCanInsertDtmf(bool can) {
741 if (can) {
742 InitWithDtmfCodec();
743 } else {
744 Init();
745 }
746 mediastream_signaling_.SendAudioVideoStream1();
747 CreateAndSetRemoteOfferAndLocalAnswer();
748 EXPECT_FALSE(session_->CanInsertDtmf(""));
749 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
750 }
751
752 // The method sets up a call from the session to itself, in a loopback
753 // arrangement. It also uses a firewall rule to create a temporary
754 // disconnection. This code is placed as a method so that it can be invoked
755 // by multiple tests with different allocators (e.g. with and without BUNDLE).
756 // While running the call, this method also checks if the session goes through
757 // the correct sequence of ICE states when a connection is established,
758 // broken, and re-established.
759 // The Connection state should go:
760 // New -> Checking -> Connected -> Disconnected -> Connected.
761 // The Gathering state should go: New -> Gathering -> Completed.
762 void TestLoopbackCall() {
763 AddInterface(kClientAddr1);
764 Init();
765 mediastream_signaling_.SendAudioVideoStream1();
766 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
767
768 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
769 observer_.ice_gathering_state_);
770 SetLocalDescriptionWithoutError(offer);
771 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
772 observer_.ice_connection_state_);
773 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
774 observer_.ice_gathering_state_,
775 kIceCandidatesTimeout);
776 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
777 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
778 observer_.ice_gathering_state_,
779 kIceCandidatesTimeout);
780
781 std::string sdp;
782 offer->ToString(&sdp);
783 SessionDescriptionInterface* desc =
784 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
785 ASSERT_TRUE(desc != NULL);
786 SetRemoteDescriptionWithoutError(desc);
787
788 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
789 observer_.ice_connection_state_,
790 kIceCandidatesTimeout);
791 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionConnected,
792 observer_.ice_connection_state_,
793 kIceCandidatesTimeout);
794 // TODO(bemasc): EXPECT(Completed) once the details are standardized.
795
796 // Adding firewall rule to block ping requests, which should cause
797 // transport channel failure.
798 fss_->AddRule(false, talk_base::FP_ANY, talk_base::FD_ANY, kClientAddr1);
799 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
800 observer_.ice_connection_state_,
801 kIceCandidatesTimeout);
802
803 // Clearing the rules, session should move back to completed state.
804 fss_->ClearRules();
805 // Session is automatically calling OnSignalingReady after creation of
806 // new portallocator session which will allocate new set of candidates.
807
808 // TODO(bemasc): Change this to Completed once the details are standardized.
809 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionConnected,
810 observer_.ice_connection_state_,
811 kIceCandidatesTimeout);
812 }
813
814 void VerifyTransportType(const std::string& content_name,
815 cricket::TransportProtocol protocol) {
816 const cricket::Transport* transport = session_->GetTransport(content_name);
817 ASSERT_TRUE(transport != NULL);
818 EXPECT_EQ(protocol, transport->protocol());
819 }
820
821 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
822 void AddCNCodecs() {
823 // Add kTelephoneEventCodec for dtmf test.
824 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
825 codecs.push_back(kCNCodec1);
826 codecs.push_back(kCNCodec2);
827 media_engine_->SetAudioCodecs(codecs);
828 desc_factory_->set_audio_codecs(codecs);
829 }
830
831 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
832 const cricket::ContentDescription* description = content->description;
833 ASSERT(description != NULL);
834 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000835 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836 ASSERT(audio_content_desc != NULL);
837 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
838 if (audio_content_desc->codecs()[i].name == "CN")
839 return false;
840 }
841 return true;
842 }
843
844 void SetLocalDescriptionWithDataChannel() {
845 webrtc::DataChannelInit dci;
846 dci.reliable = false;
847 session_->CreateDataChannel("datachannel", &dci);
848 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
849 SetLocalDescriptionWithoutError(offer);
850 }
851
852 cricket::FakeMediaEngine* media_engine_;
853 cricket::FakeDataEngine* data_engine_;
854 cricket::FakeDeviceManager* device_manager_;
855 talk_base::scoped_ptr<cricket::ChannelManager> channel_manager_;
856 talk_base::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000857 talk_base::scoped_ptr<talk_base::SSLIdentity> identity_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 talk_base::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
859 talk_base::scoped_ptr<talk_base::PhysicalSocketServer> pss_;
860 talk_base::scoped_ptr<talk_base::VirtualSocketServer> vss_;
861 talk_base::scoped_ptr<talk_base::FirewallSocketServer> fss_;
862 talk_base::SocketServerScope ss_scope_;
863 cricket::TestStunServer stun_server_;
864 talk_base::FakeNetworkManager network_manager_;
865 cricket::BasicPortAllocator allocator_;
866 talk_base::scoped_ptr<FakeConstraints> constraints_;
867 FakeMediaStreamSignaling mediastream_signaling_;
868 talk_base::scoped_ptr<WebRtcSessionForTest> session_;
869 MockIceObserver observer_;
870 cricket::FakeVideoMediaChannel* video_channel_;
871 cricket::FakeVoiceMediaChannel* voice_channel_;
872};
873
874TEST_F(WebRtcSessionTest, TestInitialize) {
875 Init();
876}
877
878TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
879 InitWithDtls();
880}
881
882TEST_F(WebRtcSessionTest, TestSessionCandidates) {
883 TestSessionCandidatesWithBundleRtcpMux(false, false);
884}
885
886// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
887// with rtcp-mux and/or bundle.
888TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
889 TestSessionCandidatesWithBundleRtcpMux(false, true);
890}
891
892TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundle) {
893 TestSessionCandidatesWithBundleRtcpMux(true, false);
894}
895
896TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
897 TestSessionCandidatesWithBundleRtcpMux(true, true);
898}
899
900TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
901 AddInterface(kClientAddr1);
902 AddInterface(kClientAddr2);
903 Init();
904 mediastream_signaling_.SendAudioVideoStream1();
905 InitiateCall();
906 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
907 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
908 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
909}
910
911TEST_F(WebRtcSessionTest, TestStunError) {
912 AddInterface(kClientAddr1);
913 AddInterface(kClientAddr2);
914 fss_->AddRule(false, talk_base::FP_UDP, talk_base::FD_ANY, kClientAddr1);
915 Init();
916 mediastream_signaling_.SendAudioVideoStream1();
917 InitiateCall();
918 // Since kClientAddr1 is blocked, not expecting stun candidates for it.
919 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
920 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
921 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
922}
923
924// Test creating offers and receive answers and make sure the
925// media engine creates the expected send and receive streams.
926TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswer) {
927 Init();
928 mediastream_signaling_.SendAudioVideoStream1();
929 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
930 const std::string session_id_orig = offer->session_id();
931 const std::string session_version_orig = offer->session_version();
932 SetLocalDescriptionWithoutError(offer);
933
934 mediastream_signaling_.SendAudioVideoStream2();
935 SessionDescriptionInterface* answer =
936 CreateRemoteAnswer(session_->local_description());
937 SetRemoteDescriptionWithoutError(answer);
938
939 video_channel_ = media_engine_->GetVideoChannel(0);
940 voice_channel_ = media_engine_->GetVoiceChannel(0);
941
942 ASSERT_EQ(1u, video_channel_->recv_streams().size());
943 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
944
945 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
946 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
947
948 ASSERT_EQ(1u, video_channel_->send_streams().size());
949 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
950 ASSERT_EQ(1u, voice_channel_->send_streams().size());
951 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
952
953 // Create new offer without send streams.
954 mediastream_signaling_.SendNothing();
955 offer = session_->CreateOffer(NULL);
956
957 // Verify the session id is the same and the session version is
958 // increased.
959 EXPECT_EQ(session_id_orig, offer->session_id());
960 EXPECT_LT(talk_base::FromString<uint64>(session_version_orig),
961 talk_base::FromString<uint64>(offer->session_version()));
962
963 SetLocalDescriptionWithoutError(offer);
964
965 mediastream_signaling_.SendAudioVideoStream2();
966 answer = CreateRemoteAnswer(session_->local_description());
967 SetRemoteDescriptionWithoutError(answer);
968
969 EXPECT_EQ(0u, video_channel_->send_streams().size());
970 EXPECT_EQ(0u, voice_channel_->send_streams().size());
971
972 // Make sure the receive streams have not changed.
973 ASSERT_EQ(1u, video_channel_->recv_streams().size());
974 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
975 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
976 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
977}
978
979// Test receiving offers and creating answers and make sure the
980// media engine creates the expected send and receive streams.
981TEST_F(WebRtcSessionTest, TestReceiveOfferCreateAnswer) {
982 Init();
983 mediastream_signaling_.SendAudioVideoStream2();
984 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
985 SetRemoteDescriptionWithoutError(offer);
986
987 mediastream_signaling_.SendAudioVideoStream1();
988 SessionDescriptionInterface* answer = session_->CreateAnswer(NULL);
989 SetLocalDescriptionWithoutError(answer);
990
991 const std::string session_id_orig = answer->session_id();
992 const std::string session_version_orig = answer->session_version();
993
994 video_channel_ = media_engine_->GetVideoChannel(0);
995 voice_channel_ = media_engine_->GetVoiceChannel(0);
996
997 ASSERT_EQ(1u, video_channel_->recv_streams().size());
998 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
999
1000 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1001 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1002
1003 ASSERT_EQ(1u, video_channel_->send_streams().size());
1004 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1005 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1006 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1007
1008 mediastream_signaling_.SendAudioVideoStream1And2();
1009 offer = session_->CreateOffer(NULL);
1010 SetRemoteDescriptionWithoutError(offer);
1011
1012 // Answer by turning off all send streams.
1013 mediastream_signaling_.SendNothing();
1014 answer = session_->CreateAnswer(NULL);
1015
1016 // Verify the session id is the same and the session version is
1017 // increased.
1018 EXPECT_EQ(session_id_orig, answer->session_id());
1019 EXPECT_LT(talk_base::FromString<uint64>(session_version_orig),
1020 talk_base::FromString<uint64>(answer->session_version()));
1021 SetLocalDescriptionWithoutError(answer);
1022
1023 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1024 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1025 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1026 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1027 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1028 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1029
1030 // Make sure we have no send streams.
1031 EXPECT_EQ(0u, video_channel_->send_streams().size());
1032 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1033}
1034
1035// Test we will return fail when apply an offer that doesn't have
1036// crypto enabled.
1037TEST_F(WebRtcSessionTest, SetNonCryptoOffer) {
1038 Init();
1039 cricket::MediaSessionOptions options;
1040 options.has_video = true;
1041 JsepSessionDescription* offer = CreateRemoteOffer(
1042 options, cricket::SEC_DISABLED);
1043 ASSERT_TRUE(offer != NULL);
1044 VerifyNoCryptoParams(offer->description(), false);
1045 // SetRemoteDescription and SetLocalDescription will take the ownership of
1046 // the offer.
1047 SetRemoteDescriptionExpectError(kSdpWithoutCrypto, offer);
1048 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1049 ASSERT_TRUE(offer != NULL);
1050 SetLocalDescriptionExpectError(kSdpWithoutCrypto, offer);
1051}
1052
1053// Test we will return fail when apply an answer that doesn't have
1054// crypto enabled.
1055TEST_F(WebRtcSessionTest, SetLocalNonCryptoAnswer) {
1056 Init();
1057 SessionDescriptionInterface* offer = NULL;
1058 SessionDescriptionInterface* answer = NULL;
1059 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1060 // SetRemoteDescription and SetLocalDescription will take the ownership of
1061 // the offer.
1062 SetRemoteDescriptionWithoutError(offer);
1063 SetLocalDescriptionExpectError(kSdpWithoutCrypto, answer);
1064}
1065
1066// Test we will return fail when apply an answer that doesn't have
1067// crypto enabled.
1068TEST_F(WebRtcSessionTest, SetRemoteNonCryptoAnswer) {
1069 Init();
1070 SessionDescriptionInterface* offer = NULL;
1071 SessionDescriptionInterface* answer = NULL;
1072 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1073 // SetRemoteDescription and SetLocalDescription will take the ownership of
1074 // the offer.
1075 SetLocalDescriptionWithoutError(offer);
1076 SetRemoteDescriptionExpectError(kSdpWithoutCrypto, answer);
1077}
1078
1079// Test that we can create and set an offer with a DTLS fingerprint.
1080TEST_F(WebRtcSessionTest, CreateSetDtlsOffer) {
1081 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
1082 InitWithDtls();
1083 mediastream_signaling_.SendAudioVideoStream1();
1084 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
1085 ASSERT_TRUE(offer != NULL);
1086 VerifyFingerprintStatus(offer->description(), true);
1087 // SetLocalDescription will take the ownership of the offer.
1088 SetLocalDescriptionWithoutError(offer);
1089}
1090
1091// Test that we can process an offer with a DTLS fingerprint
1092// and that we return an answer with a fingerprint.
1093TEST_F(WebRtcSessionTest, ReceiveDtlsOfferCreateAnswer) {
1094 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
1095 InitWithDtls();
1096 SetFactoryDtlsSrtp();
1097 cricket::MediaSessionOptions options;
1098 options.has_video = true;
1099 JsepSessionDescription* offer = CreateRemoteOffer(options);
1100 ASSERT_TRUE(offer != NULL);
1101 VerifyFingerprintStatus(offer->description(), true);
1102
1103 // SetRemoteDescription will take the ownership of the offer.
1104 SetRemoteDescriptionWithoutError(offer);
1105
1106 // Verify that we get a crypto fingerprint in the answer.
1107 SessionDescriptionInterface* answer = session_->CreateAnswer(NULL);
1108 ASSERT_TRUE(answer != NULL);
1109 VerifyFingerprintStatus(answer->description(), true);
1110 // Check that we don't have an a=crypto line in the answer.
1111 VerifyNoCryptoParams(answer->description(), true);
1112
1113 // Now set the local description, which should work, even without a=crypto.
1114 SetLocalDescriptionWithoutError(answer);
1115}
1116
1117// Test that even if we support DTLS, if the other side didn't offer a
1118// fingerprint, we don't either.
1119TEST_F(WebRtcSessionTest, ReceiveNoDtlsOfferCreateAnswer) {
1120 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
1121 InitWithDtls();
1122 cricket::MediaSessionOptions options;
1123 options.has_video = true;
1124 JsepSessionDescription* offer = CreateRemoteOffer(
1125 options, cricket::SEC_REQUIRED);
1126 ASSERT_TRUE(offer != NULL);
1127 VerifyFingerprintStatus(offer->description(), false);
1128
1129 // SetRemoteDescription will take the ownership of
1130 // the offer.
1131 SetRemoteDescriptionWithoutError(offer);
1132
1133 // Verify that we don't get a crypto fingerprint in the answer.
1134 SessionDescriptionInterface* answer = session_->CreateAnswer(NULL);
1135 ASSERT_TRUE(answer != NULL);
1136 VerifyFingerprintStatus(answer->description(), false);
1137
1138 // Now set the local description.
1139 SetLocalDescriptionWithoutError(answer);
1140}
1141
1142TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
1143 Init();
1144 mediastream_signaling_.SendNothing();
1145 // SetLocalDescription take ownership of offer.
1146 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
1147 SetLocalDescriptionWithoutError(offer);
1148
1149 // SetLocalDescription take ownership of offer.
1150 SessionDescriptionInterface* offer2 = session_->CreateOffer(NULL);
1151 SetLocalDescriptionWithoutError(offer2);
1152}
1153
1154TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
1155 Init();
1156 mediastream_signaling_.SendNothing();
1157 // SetLocalDescription take ownership of offer.
1158 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
1159 SetRemoteDescriptionWithoutError(offer);
1160
1161 SessionDescriptionInterface* offer2 = session_->CreateOffer(NULL);
1162 SetRemoteDescriptionWithoutError(offer2);
1163}
1164
1165TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
1166 Init();
1167 mediastream_signaling_.SendNothing();
1168 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
1169 SetLocalDescriptionWithoutError(offer);
1170 offer = session_->CreateOffer(NULL);
1171 SetRemoteDescriptionExpectError(
1172 "Called with type in wrong state, type: offer state: STATE_SENTINITIATE",
1173 offer);
1174}
1175
1176TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
1177 Init();
1178 mediastream_signaling_.SendNothing();
1179 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
1180 SetRemoteDescriptionWithoutError(offer);
1181 offer = session_->CreateOffer(NULL);
1182 SetLocalDescriptionExpectError(
1183 "Called with type in wrong state, type: "
1184 "offer state: STATE_RECEIVEDINITIATE",
1185 offer);
1186}
1187
1188TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
1189 Init();
1190 mediastream_signaling_.SendNothing();
1191 SessionDescriptionInterface* offer = CreateRemoteOffer();
1192 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1193
1194 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
1195 session_->CreateAnswer(NULL));
1196 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1197 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1198
1199 mediastream_signaling_.SendAudioVideoStream1();
1200 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
1201 session_->CreateAnswer(NULL));
1202 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1203
1204 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1205
1206 mediastream_signaling_.SendAudioVideoStream2();
1207 SessionDescriptionInterface* answer = session_->CreateAnswer(NULL);
1208 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1209}
1210
1211TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
1212 Init();
1213 mediastream_signaling_.SendNothing();
1214 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
1215 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1216
1217 JsepSessionDescription* pranswer =
1218 CreateRemoteAnswer(session_->local_description());
1219 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1220
1221 SetRemoteDescriptionExpectState(pranswer,
1222 BaseSession::STATE_RECEIVEDPRACCEPT);
1223
1224 mediastream_signaling_.SendAudioVideoStream1();
1225 JsepSessionDescription* pranswer2 =
1226 CreateRemoteAnswer(session_->local_description());
1227 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1228
1229 SetRemoteDescriptionExpectState(pranswer2,
1230 BaseSession::STATE_RECEIVEDPRACCEPT);
1231
1232 mediastream_signaling_.SendAudioVideoStream2();
1233 SessionDescriptionInterface* answer =
1234 CreateRemoteAnswer(session_->local_description());
1235 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1236}
1237
1238TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
1239 Init();
1240 mediastream_signaling_.SendNothing();
1241 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
1242 session_->CreateOffer(NULL));
1243 SessionDescriptionInterface* answer =
1244 CreateRemoteAnswer(offer.get());
1245 SetLocalDescriptionExpectError(
1246 "Called with type in wrong state, type: answer state: STATE_INIT",
1247 answer);
1248}
1249
1250TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
1251 Init();
1252 mediastream_signaling_.SendNothing();
1253 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
1254 session_->CreateOffer(NULL));
1255 SessionDescriptionInterface* answer =
1256 CreateRemoteAnswer(offer.get());
1257 SetRemoteDescriptionExpectError(
1258 "Called with type in wrong state, type: answer state: STATE_INIT",
1259 answer);
1260}
1261
1262TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
1263 Init();
1264 mediastream_signaling_.SendAudioVideoStream1();
1265
1266 cricket::Candidate candidate;
1267 candidate.set_component(1);
1268 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1269
1270 // Fail since we have not set a offer description.
1271 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1272
1273 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
1274 SetLocalDescriptionWithoutError(offer);
1275 // Candidate should be allowed to add before remote description.
1276 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1277 candidate.set_component(2);
1278 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1279 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1280
1281 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1282 session_->local_description());
1283 SetRemoteDescriptionWithoutError(answer);
1284
1285 // Verifying the candidates are copied properly from internal vector.
1286 const SessionDescriptionInterface* remote_desc =
1287 session_->remote_description();
1288 ASSERT_TRUE(remote_desc != NULL);
1289 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1290 const IceCandidateCollection* candidates =
1291 remote_desc->candidates(kMediaContentIndex0);
1292 ASSERT_EQ(2u, candidates->count());
1293 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1294 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1295 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1296 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1297
1298 candidate.set_component(2);
1299 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1300 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
1301 ASSERT_EQ(3u, candidates->count());
1302
1303 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1304 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1305}
1306
1307// Test that a remote candidate is added to the remote session description and
1308// that it is retained if the remote session description is changed.
1309TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
1310 Init();
1311 cricket::Candidate candidate1;
1312 candidate1.set_component(1);
1313 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1314 candidate1);
1315 mediastream_signaling_.SendAudioVideoStream1();
1316 CreateAndSetRemoteOfferAndLocalAnswer();
1317
1318 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1319 const SessionDescriptionInterface* remote_desc =
1320 session_->remote_description();
1321 ASSERT_TRUE(remote_desc != NULL);
1322 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1323 const IceCandidateCollection* candidates =
1324 remote_desc->candidates(kMediaContentIndex0);
1325 ASSERT_EQ(1u, candidates->count());
1326 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1327
1328 // Update the RemoteSessionDescription with a new session description and
1329 // a candidate and check that the new remote session description contains both
1330 // candidates.
1331 SessionDescriptionInterface* offer = CreateRemoteOffer();
1332 cricket::Candidate candidate2;
1333 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1334 candidate2);
1335 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1336 SetRemoteDescriptionWithoutError(offer);
1337
1338 remote_desc = session_->remote_description();
1339 ASSERT_TRUE(remote_desc != NULL);
1340 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1341 candidates = remote_desc->candidates(kMediaContentIndex0);
1342 ASSERT_EQ(2u, candidates->count());
1343 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1344 // Username and password have be updated with the TransportInfo of the
1345 // SessionDescription, won't be equal to the original one.
1346 candidate2.set_username(candidates->at(0)->candidate().username());
1347 candidate2.set_password(candidates->at(0)->candidate().password());
1348 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1349 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1350 // No need to verify the username and password.
1351 candidate1.set_username(candidates->at(1)->candidate().username());
1352 candidate1.set_password(candidates->at(1)->candidate().password());
1353 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1354
1355 // Test that the candidate is ignored if we can add the same candidate again.
1356 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1357}
1358
1359// Test that local candidates are added to the local session description and
1360// that they are retained if the local session description is changed.
1361TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
1362 AddInterface(kClientAddr1);
1363 Init();
1364 mediastream_signaling_.SendAudioVideoStream1();
1365 CreateAndSetRemoteOfferAndLocalAnswer();
1366
1367 const SessionDescriptionInterface* local_desc = session_->local_description();
1368 const IceCandidateCollection* candidates =
1369 local_desc->candidates(kMediaContentIndex0);
1370 ASSERT_TRUE(candidates != NULL);
1371 EXPECT_EQ(0u, candidates->count());
1372
1373 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1374
1375 local_desc = session_->local_description();
1376 candidates = local_desc->candidates(kMediaContentIndex0);
1377 ASSERT_TRUE(candidates != NULL);
1378 EXPECT_LT(0u, candidates->count());
1379 candidates = local_desc->candidates(1);
1380 ASSERT_TRUE(candidates != NULL);
1381 EXPECT_LT(0u, candidates->count());
1382
1383 // Update the session descriptions.
1384 mediastream_signaling_.SendAudioVideoStream1();
1385 CreateAndSetRemoteOfferAndLocalAnswer();
1386
1387 local_desc = session_->local_description();
1388 candidates = local_desc->candidates(kMediaContentIndex0);
1389 ASSERT_TRUE(candidates != NULL);
1390 EXPECT_LT(0u, candidates->count());
1391 candidates = local_desc->candidates(1);
1392 ASSERT_TRUE(candidates != NULL);
1393 EXPECT_LT(0u, candidates->count());
1394}
1395
1396// Test that we can set a remote session description with remote candidates.
1397TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
1398 Init();
1399
1400 cricket::Candidate candidate1;
1401 candidate1.set_component(1);
1402 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
1403 candidate1);
1404 mediastream_signaling_.SendAudioVideoStream1();
1405 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
1406
1407 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
1408 SetRemoteDescriptionWithoutError(offer);
1409
1410 const SessionDescriptionInterface* remote_desc =
1411 session_->remote_description();
1412 ASSERT_TRUE(remote_desc != NULL);
1413 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1414 const IceCandidateCollection* candidates =
1415 remote_desc->candidates(kMediaContentIndex0);
1416 ASSERT_EQ(1u, candidates->count());
1417 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1418
1419 SessionDescriptionInterface* answer = session_->CreateAnswer(NULL);
1420 SetLocalDescriptionWithoutError(answer);
1421}
1422
1423// Test that offers and answers contains ice candidates when Ice candidates have
1424// been gathered.
1425TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
1426 AddInterface(kClientAddr1);
1427 Init();
1428 mediastream_signaling_.SendAudioVideoStream1();
1429 // Ice is started but candidates are not provided until SetLocalDescription
1430 // is called.
1431 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1432 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1433 CreateAndSetRemoteOfferAndLocalAnswer();
1434 // Wait until at least one local candidate has been collected.
1435 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
1436 kIceCandidatesTimeout);
1437 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
1438 kIceCandidatesTimeout);
1439
1440 talk_base::scoped_ptr<SessionDescriptionInterface> local_offer(
1441 session_->CreateOffer(NULL));
1442 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
1443 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
1444 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
1445 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
1446
1447 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
1448 SetRemoteDescriptionWithoutError(remote_offer);
1449 SessionDescriptionInterface* answer = session_->CreateAnswer(NULL);
1450 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
1451 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
1452 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
1453 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
1454 SetLocalDescriptionWithoutError(answer);
1455}
1456
1457// Verifies TransportProxy and media channels are created with content names
1458// present in the SessionDescription.
1459TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
1460 Init();
1461 mediastream_signaling_.SendAudioVideoStream1();
1462 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
1463 session_->CreateOffer(NULL));
1464
1465 // CreateOffer creates session description with the content names "audio" and
1466 // "video". Goal is to modify these content names and verify transport channel
1467 // proxy in the BaseSession, as proxies are created with the content names
1468 // present in SDP.
1469 std::string sdp;
1470 EXPECT_TRUE(offer->ToString(&sdp));
1471 const std::string kAudioMid = "a=mid:audio";
1472 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
1473 const std::string kVideoMid = "a=mid:video";
1474 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
1475
1476 // Replacing |audio| with |audio_content_name|.
1477 talk_base::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
1478 kAudioMidReplaceStr.c_str(),
1479 kAudioMidReplaceStr.length(),
1480 &sdp);
1481 // Replacing |video| with |video_content_name|.
1482 talk_base::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
1483 kVideoMidReplaceStr.c_str(),
1484 kVideoMidReplaceStr.length(),
1485 &sdp);
1486
1487 SessionDescriptionInterface* modified_offer =
1488 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
1489
1490 SetRemoteDescriptionWithoutError(modified_offer);
1491
1492 SessionDescriptionInterface* answer =
1493 session_->CreateAnswer(NULL);
1494 SetLocalDescriptionWithoutError(answer);
1495
1496 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
1497 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
1498 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
1499 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
1500}
1501
1502// Test that an offer contains the correct media content descriptions based on
1503// the send streams when no constraints have been set.
1504TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
1505 Init();
1506 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
1507 session_->CreateOffer(NULL));
1508 ASSERT_TRUE(offer != NULL);
1509 const cricket::ContentInfo* content =
1510 cricket::GetFirstAudioContent(offer->description());
1511 EXPECT_TRUE(content != NULL);
1512 content = cricket::GetFirstVideoContent(offer->description());
1513 EXPECT_TRUE(content == NULL);
1514}
1515
1516// Test that an offer contains the correct media content descriptions based on
1517// the send streams when no constraints have been set.
1518TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
1519 Init();
1520 // Test Audio only offer.
1521 mediastream_signaling_.UseOptionsAudioOnly();
1522 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
1523 session_->CreateOffer(NULL));
1524 const cricket::ContentInfo* content =
1525 cricket::GetFirstAudioContent(offer->description());
1526 EXPECT_TRUE(content != NULL);
1527 content = cricket::GetFirstVideoContent(offer->description());
1528 EXPECT_TRUE(content == NULL);
1529
1530 // Test Audio / Video offer.
1531 mediastream_signaling_.SendAudioVideoStream1();
1532 offer.reset(session_->CreateOffer(NULL));
1533 content = cricket::GetFirstAudioContent(offer->description());
1534 EXPECT_TRUE(content != NULL);
1535 content = cricket::GetFirstVideoContent(offer->description());
1536 EXPECT_TRUE(content != NULL);
1537}
1538
1539// Test that an offer contains no media content descriptions if
1540// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
1541TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
1542 Init();
1543 webrtc::FakeConstraints constraints_no_receive;
1544 constraints_no_receive.SetMandatoryReceiveAudio(false);
1545 constraints_no_receive.SetMandatoryReceiveVideo(false);
1546
1547 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
1548 session_->CreateOffer(&constraints_no_receive));
1549 ASSERT_TRUE(offer != NULL);
1550 const cricket::ContentInfo* content =
1551 cricket::GetFirstAudioContent(offer->description());
1552 EXPECT_TRUE(content == NULL);
1553 content = cricket::GetFirstVideoContent(offer->description());
1554 EXPECT_TRUE(content == NULL);
1555}
1556
1557// Test that an offer contains only audio media content descriptions if
1558// kOfferToReceiveAudio constraints are set to true.
1559TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
1560 Init();
1561 webrtc::FakeConstraints constraints_audio_only;
1562 constraints_audio_only.SetMandatoryReceiveAudio(true);
1563 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
1564 session_->CreateOffer(&constraints_audio_only));
1565
1566 const cricket::ContentInfo* content =
1567 cricket::GetFirstAudioContent(offer->description());
1568 EXPECT_TRUE(content != NULL);
1569 content = cricket::GetFirstVideoContent(offer->description());
1570 EXPECT_TRUE(content == NULL);
1571}
1572
1573// Test that an offer contains audio and video media content descriptions if
1574// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
1575TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
1576 Init();
1577 // Test Audio / Video offer.
1578 webrtc::FakeConstraints constraints_audio_video;
1579 constraints_audio_video.SetMandatoryReceiveAudio(true);
1580 constraints_audio_video.SetMandatoryReceiveVideo(true);
1581 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
1582 session_->CreateOffer(&constraints_audio_video));
1583 const cricket::ContentInfo* content =
1584 cricket::GetFirstAudioContent(offer->description());
1585
1586 EXPECT_TRUE(content != NULL);
1587 content = cricket::GetFirstVideoContent(offer->description());
1588 EXPECT_TRUE(content != NULL);
1589
1590 // TODO(perkj): Should the direction be set to SEND_ONLY if
1591 // The constraints is set to not receive audio or video but a track is added?
1592}
1593
1594// Test that an answer can not be created if the last remote description is not
1595// an offer.
1596TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
1597 Init();
1598 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
1599 SetLocalDescriptionWithoutError(offer);
1600 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
1601 SetRemoteDescriptionWithoutError(answer);
1602 EXPECT_TRUE(session_->CreateAnswer(NULL) == NULL);
1603}
1604
1605// Test that an answer contains the correct media content descriptions when no
1606// constraints have been set.
1607TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
1608 Init();
1609 // Create a remote offer with audio and video content.
1610 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1611 SetRemoteDescriptionWithoutError(offer.release());
1612 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
1613 session_->CreateAnswer(NULL));
1614 const cricket::ContentInfo* content =
1615 cricket::GetFirstAudioContent(answer->description());
1616 ASSERT_TRUE(content != NULL);
1617 EXPECT_FALSE(content->rejected);
1618
1619 content = cricket::GetFirstVideoContent(answer->description());
1620 ASSERT_TRUE(content != NULL);
1621 EXPECT_FALSE(content->rejected);
1622}
1623
1624// Test that an answer contains the correct media content descriptions when no
1625// constraints have been set and the offer only contain audio.
1626TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
1627 Init();
1628 // Create a remote offer with audio only.
1629 cricket::MediaSessionOptions options;
1630 options.has_audio = true;
1631 options.has_video = false;
1632 talk_base::scoped_ptr<JsepSessionDescription> offer(
1633 CreateRemoteOffer(options));
1634 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
1635 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
1636
1637 SetRemoteDescriptionWithoutError(offer.release());
1638 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
1639 session_->CreateAnswer(NULL));
1640 const cricket::ContentInfo* content =
1641 cricket::GetFirstAudioContent(answer->description());
1642 ASSERT_TRUE(content != NULL);
1643 EXPECT_FALSE(content->rejected);
1644
1645 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
1646}
1647
1648// Test that an answer contains the correct media content descriptions when no
1649// constraints have been set.
1650TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
1651 Init();
1652 // Create a remote offer with audio and video content.
1653 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1654 SetRemoteDescriptionWithoutError(offer.release());
1655 // Test with a stream with tracks.
1656 mediastream_signaling_.SendAudioVideoStream1();
1657 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
1658 session_->CreateAnswer(NULL));
1659 const cricket::ContentInfo* content =
1660 cricket::GetFirstAudioContent(answer->description());
1661 ASSERT_TRUE(content != NULL);
1662 EXPECT_FALSE(content->rejected);
1663
1664 content = cricket::GetFirstVideoContent(answer->description());
1665 ASSERT_TRUE(content != NULL);
1666 EXPECT_FALSE(content->rejected);
1667}
1668
1669// Test that an answer contains the correct media content descriptions when
1670// constraints have been set but no stream is sent.
1671TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
1672 Init();
1673 // Create a remote offer with audio and video content.
1674 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1675 SetRemoteDescriptionWithoutError(offer.release());
1676
1677 webrtc::FakeConstraints constraints_no_receive;
1678 constraints_no_receive.SetMandatoryReceiveAudio(false);
1679 constraints_no_receive.SetMandatoryReceiveVideo(false);
1680
1681 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
1682 session_->CreateAnswer(&constraints_no_receive));
1683 const cricket::ContentInfo* content =
1684 cricket::GetFirstAudioContent(answer->description());
1685 ASSERT_TRUE(content != NULL);
1686 EXPECT_TRUE(content->rejected);
1687
1688 content = cricket::GetFirstVideoContent(answer->description());
1689 ASSERT_TRUE(content != NULL);
1690 EXPECT_TRUE(content->rejected);
1691}
1692
1693// Test that an answer contains the correct media content descriptions when
1694// constraints have been set and streams are sent.
1695TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
1696 Init();
1697 // Create a remote offer with audio and video content.
1698 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1699 SetRemoteDescriptionWithoutError(offer.release());
1700
1701 webrtc::FakeConstraints constraints_no_receive;
1702 constraints_no_receive.SetMandatoryReceiveAudio(false);
1703 constraints_no_receive.SetMandatoryReceiveVideo(false);
1704
1705 // Test with a stream with tracks.
1706 mediastream_signaling_.SendAudioVideoStream1();
1707 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
1708 session_->CreateAnswer(&constraints_no_receive));
1709
1710 // TODO(perkj): Should the direction be set to SEND_ONLY?
1711 const cricket::ContentInfo* content =
1712 cricket::GetFirstAudioContent(answer->description());
1713 ASSERT_TRUE(content != NULL);
1714 EXPECT_FALSE(content->rejected);
1715
1716 // TODO(perkj): Should the direction be set to SEND_ONLY?
1717 content = cricket::GetFirstVideoContent(answer->description());
1718 ASSERT_TRUE(content != NULL);
1719 EXPECT_FALSE(content->rejected);
1720}
1721
1722TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
1723 AddCNCodecs();
1724 Init();
1725 webrtc::FakeConstraints constraints;
1726 constraints.SetOptionalVAD(false);
1727 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
1728 session_->CreateOffer(&constraints));
1729 const cricket::ContentInfo* content =
1730 cricket::GetFirstAudioContent(offer->description());
1731 EXPECT_TRUE(content != NULL);
1732 EXPECT_TRUE(VerifyNoCNCodecs(content));
1733}
1734
1735TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
1736 AddCNCodecs();
1737 Init();
1738 // Create a remote offer with audio and video content.
1739 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1740 SetRemoteDescriptionWithoutError(offer.release());
1741
1742 webrtc::FakeConstraints constraints;
1743 constraints.SetOptionalVAD(false);
1744 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
1745 session_->CreateAnswer(&constraints));
1746 const cricket::ContentInfo* content =
1747 cricket::GetFirstAudioContent(answer->description());
1748 ASSERT_TRUE(content != NULL);
1749 EXPECT_TRUE(VerifyNoCNCodecs(content));
1750}
1751
1752// This test verifies the call setup when remote answer with audio only and
1753// later updates with video.
1754TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
1755 Init();
1756 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
1757 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
1758
1759 mediastream_signaling_.SendAudioVideoStream1();
1760 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
1761
1762 cricket::MediaSessionOptions options;
1763 options.has_video = false;
1764 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
1765
1766 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1767 // and answer;
1768 SetLocalDescriptionWithoutError(offer);
1769 SetRemoteDescriptionWithoutError(answer);
1770
1771 video_channel_ = media_engine_->GetVideoChannel(0);
1772 voice_channel_ = media_engine_->GetVoiceChannel(0);
1773
1774 ASSERT_TRUE(video_channel_ == NULL);
1775
1776 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
1777 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1778 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
1779
1780 // Let the remote end update the session descriptions, with Audio and Video.
1781 mediastream_signaling_.SendAudioVideoStream2();
1782 CreateAndSetRemoteOfferAndLocalAnswer();
1783
1784 video_channel_ = media_engine_->GetVideoChannel(0);
1785 voice_channel_ = media_engine_->GetVoiceChannel(0);
1786
1787 ASSERT_TRUE(video_channel_ != NULL);
1788 ASSERT_TRUE(voice_channel_ != NULL);
1789
1790 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1791 ASSERT_EQ(1u, video_channel_->send_streams().size());
1792 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
1793 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
1794 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1795 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1796 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
1797 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
1798
1799 // Change session back to audio only.
1800 mediastream_signaling_.UseOptionsAudioOnly();
1801 CreateAndSetRemoteOfferAndLocalAnswer();
1802
1803 EXPECT_EQ(0u, video_channel_->recv_streams().size());
1804 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1805 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
1806 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1807 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
1808}
1809
1810// This test verifies the call setup when remote answer with video only and
1811// later updates with audio.
1812TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
1813 Init();
1814 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
1815 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
1816 mediastream_signaling_.SendAudioVideoStream1();
1817 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
1818
1819 cricket::MediaSessionOptions options;
1820 options.has_audio = false;
1821 options.has_video = true;
1822 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1823 offer, options, cricket::SEC_ENABLED);
1824
1825 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1826 // and answer.
1827 SetLocalDescriptionWithoutError(offer);
1828 SetRemoteDescriptionWithoutError(answer);
1829
1830 video_channel_ = media_engine_->GetVideoChannel(0);
1831 voice_channel_ = media_engine_->GetVoiceChannel(0);
1832
1833 ASSERT_TRUE(voice_channel_ == NULL);
1834 ASSERT_TRUE(video_channel_ != NULL);
1835
1836 EXPECT_EQ(0u, video_channel_->recv_streams().size());
1837 ASSERT_EQ(1u, video_channel_->send_streams().size());
1838 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
1839
1840 // Update the session descriptions, with Audio and Video.
1841 mediastream_signaling_.SendAudioVideoStream2();
1842 CreateAndSetRemoteOfferAndLocalAnswer();
1843
1844 voice_channel_ = media_engine_->GetVoiceChannel(0);
1845 ASSERT_TRUE(voice_channel_ != NULL);
1846
1847 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1848 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1849 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
1850 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
1851
1852 // Change session back to video only.
1853 mediastream_signaling_.UseOptionsVideoOnly();
1854 CreateAndSetRemoteOfferAndLocalAnswer();
1855
1856 video_channel_ = media_engine_->GetVideoChannel(0);
1857 voice_channel_ = media_engine_->GetVoiceChannel(0);
1858
1859 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1860 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
1861 ASSERT_EQ(1u, video_channel_->send_streams().size());
1862 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
1863}
1864
1865TEST_F(WebRtcSessionTest, TestDefaultSetSecurePolicy) {
1866 Init();
1867 EXPECT_EQ(cricket::SEC_REQUIRED, session_->secure_policy());
1868}
1869
1870TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
1871 Init();
1872 mediastream_signaling_.SendAudioVideoStream1();
1873 scoped_ptr<SessionDescriptionInterface> offer(
1874 session_->CreateOffer(NULL));
1875 VerifyCryptoParams(offer->description());
1876 SetRemoteDescriptionWithoutError(offer.release());
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001877 scoped_ptr<SessionDescriptionInterface> answer(
1878 session_->CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 VerifyCryptoParams(answer->description());
1880}
1881
1882TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
1883 Init();
1884 session_->set_secure_policy(cricket::SEC_DISABLED);
1885 mediastream_signaling_.SendAudioVideoStream1();
1886 scoped_ptr<SessionDescriptionInterface> offer(
1887 session_->CreateOffer(NULL));
1888 VerifyNoCryptoParams(offer->description(), false);
1889}
1890
1891TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
1892 Init();
1893 VerifyAnswerFromNonCryptoOffer();
1894}
1895
1896TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
1897 Init();
1898 VerifyAnswerFromCryptoOffer();
1899}
1900
1901TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) {
1902 // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in
1903 // local description is removed by the application, BUNDLE flag should be
1904 // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc.
1905 Init();
1906 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) ==
1907 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
1908 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
1909 session_->CreateOffer(NULL));
1910 cricket::SessionDescription* offer_copy =
1911 offer->description()->Copy();
1912 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
1913 JsepSessionDescription* modified_offer =
1914 new JsepSessionDescription(JsepSessionDescription::kOffer);
1915 modified_offer->Initialize(offer_copy, "1", "1");
1916
1917 SetLocalDescriptionWithoutError(modified_offer);
1918 EXPECT_FALSE(allocator_.flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE);
1919}
1920
1921TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) {
1922 Init();
1923 mediastream_signaling_.SendAudioVideoStream1();
1924 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) ==
1925 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
1926 FakeConstraints constraints;
1927 constraints.SetMandatoryUseRtpMux(true);
1928 SessionDescriptionInterface* offer = session_->CreateOffer(&constraints);
1929 SetLocalDescriptionWithoutError(offer);
1930 mediastream_signaling_.SendAudioVideoStream2();
1931 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
1932 CreateRemoteAnswer(session_->local_description()));
1933 cricket::SessionDescription* answer_copy = answer->description()->Copy();
1934 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
1935 JsepSessionDescription* modified_answer =
1936 new JsepSessionDescription(JsepSessionDescription::kAnswer);
1937 modified_answer->Initialize(answer_copy, "1", "1");
1938 SetRemoteDescriptionWithoutError(modified_answer);
1939 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) ==
1940 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
1941
1942 video_channel_ = media_engine_->GetVideoChannel(0);
1943 voice_channel_ = media_engine_->GetVoiceChannel(0);
1944
1945 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1946 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1947
1948 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1949 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1950
1951 ASSERT_EQ(1u, video_channel_->send_streams().size());
1952 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1953 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1954 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1955}
1956
1957TEST_F(WebRtcSessionTest, SetAudioPlayout) {
1958 Init();
1959 mediastream_signaling_.SendAudioVideoStream1();
1960 CreateAndSetRemoteOfferAndLocalAnswer();
1961 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
1962 ASSERT_TRUE(channel != NULL);
1963 ASSERT_EQ(1u, channel->recv_streams().size());
1964 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
1965 double left_vol, right_vol;
1966 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
1967 EXPECT_EQ(1, left_vol);
1968 EXPECT_EQ(1, right_vol);
1969 session_->SetAudioPlayout(receive_ssrc, false);
1970 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
1971 EXPECT_EQ(0, left_vol);
1972 EXPECT_EQ(0, right_vol);
1973 session_->SetAudioPlayout(receive_ssrc, true);
1974 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
1975 EXPECT_EQ(1, left_vol);
1976 EXPECT_EQ(1, right_vol);
1977}
1978
1979TEST_F(WebRtcSessionTest, SetAudioSend) {
1980 Init();
1981 mediastream_signaling_.SendAudioVideoStream1();
1982 CreateAndSetRemoteOfferAndLocalAnswer();
1983 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
1984 ASSERT_TRUE(channel != NULL);
1985 ASSERT_EQ(1u, channel->send_streams().size());
1986 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
1987 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
1988
1989 cricket::AudioOptions options;
1990 options.echo_cancellation.Set(true);
1991
1992 session_->SetAudioSend(send_ssrc, false, options);
1993 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
1994 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
1995
1996 session_->SetAudioSend(send_ssrc, true, options);
1997 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
1998 bool value;
1999 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2000 EXPECT_TRUE(value);
2001}
2002
2003TEST_F(WebRtcSessionTest, SetVideoPlayout) {
2004 Init();
2005 mediastream_signaling_.SendAudioVideoStream1();
2006 CreateAndSetRemoteOfferAndLocalAnswer();
2007 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2008 ASSERT_TRUE(channel != NULL);
2009 ASSERT_LT(0u, channel->renderers().size());
2010 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2011 ASSERT_EQ(1u, channel->recv_streams().size());
2012 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2013 cricket::FakeVideoRenderer renderer;
2014 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2015 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2016 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2017 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2018}
2019
2020TEST_F(WebRtcSessionTest, SetVideoSend) {
2021 Init();
2022 mediastream_signaling_.SendAudioVideoStream1();
2023 CreateAndSetRemoteOfferAndLocalAnswer();
2024 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2025 ASSERT_TRUE(channel != NULL);
2026 ASSERT_EQ(1u, channel->send_streams().size());
2027 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2028 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2029 cricket::VideoOptions* options = NULL;
2030 session_->SetVideoSend(send_ssrc, false, options);
2031 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2032 session_->SetVideoSend(send_ssrc, true, options);
2033 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2034}
2035
2036TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2037 TestCanInsertDtmf(false);
2038}
2039
2040TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2041 TestCanInsertDtmf(true);
2042}
2043
2044TEST_F(WebRtcSessionTest, InsertDtmf) {
2045 // Setup
2046 Init();
2047 mediastream_signaling_.SendAudioVideoStream1();
2048 CreateAndSetRemoteOfferAndLocalAnswer();
2049 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2050 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2051
2052 // Insert DTMF
2053 const int expected_flags = DF_SEND;
2054 const int expected_duration = 90;
2055 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2056 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2057 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2058
2059 // Verify
2060 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2061 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2062 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2063 expected_duration, expected_flags));
2064 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2065 expected_duration, expected_flags));
2066 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2067 expected_duration, expected_flags));
2068}
2069
2070// This test verifies the |initiator| flag when session initiates the call.
2071TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
2072 Init();
2073 EXPECT_FALSE(session_->initiator());
2074 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
2075 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2076 SetLocalDescriptionWithoutError(offer);
2077 EXPECT_TRUE(session_->initiator());
2078 SetRemoteDescriptionWithoutError(answer);
2079 EXPECT_TRUE(session_->initiator());
2080}
2081
2082// This test verifies the |initiator| flag when session receives the call.
2083TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
2084 Init();
2085 EXPECT_FALSE(session_->initiator());
2086 SessionDescriptionInterface* offer = CreateRemoteOffer();
2087 SetRemoteDescriptionWithoutError(offer);
2088 SessionDescriptionInterface* answer = session_->CreateAnswer(NULL);
2089
2090 EXPECT_FALSE(session_->initiator());
2091 SetLocalDescriptionWithoutError(answer);
2092 EXPECT_FALSE(session_->initiator());
2093}
2094
2095// This test verifies the ice protocol type at initiator of the call
2096// if |a=ice-options:google-ice| is present in answer.
2097TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
2098 Init();
2099 mediastream_signaling_.SendAudioVideoStream1();
2100 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
henrike@webrtc.org723d6832013-07-12 16:04:50 +00002101 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
2102 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 SetLocalDescriptionWithoutError(offer);
2104 std::string sdp;
2105 EXPECT_TRUE(answer->ToString(&sdp));
2106 // Adding ice-options to the session level.
2107 InjectAfter("t=0 0\r\n",
2108 "a=ice-options:google-ice\r\n",
2109 &sdp);
2110 SessionDescriptionInterface* answer_with_gice =
2111 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2112 SetRemoteDescriptionWithoutError(answer_with_gice);
2113 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2114 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2115}
2116
2117// This test verifies the ice protocol type at initiator of the call
2118// if ICE RFC5245 is supported in answer.
2119TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
2120 Init();
2121 mediastream_signaling_.SendAudioVideoStream1();
2122 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
2123 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2124 SetLocalDescriptionWithoutError(offer);
2125
2126 SetRemoteDescriptionWithoutError(answer);
2127 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2128 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2129}
2130
2131// This test verifies the ice protocol type at receiver side of the call if
2132// receiver decides to use google-ice.
2133TEST_F(WebRtcSessionTest, TestReceiverGIceInOffer) {
2134 Init();
2135 mediastream_signaling_.SendAudioVideoStream1();
2136 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
2137 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.org723d6832013-07-12 16:04:50 +00002138 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
2139 session_->CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 std::string sdp;
2141 EXPECT_TRUE(answer->ToString(&sdp));
2142 // Adding ice-options to the session level.
2143 InjectAfter("t=0 0\r\n",
2144 "a=ice-options:google-ice\r\n",
2145 &sdp);
2146 SessionDescriptionInterface* answer_with_gice =
2147 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2148 SetLocalDescriptionWithoutError(answer_with_gice);
2149 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2150 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2151}
2152
2153// This test verifies the ice protocol type at receiver side of the call if
2154// receiver decides to use ice RFC 5245.
2155TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
2156 Init();
2157 mediastream_signaling_.SendAudioVideoStream1();
2158 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
2159 SetRemoteDescriptionWithoutError(offer);
2160 SessionDescriptionInterface* answer = session_->CreateAnswer(NULL);
2161 SetLocalDescriptionWithoutError(answer);
2162 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2163 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2164}
2165
2166// This test verifies the session state when ICE RFC5245 in offer and
2167// ICE google-ice in answer.
2168TEST_F(WebRtcSessionTest, TestIceOfferGIceOnlyAnswer) {
2169 Init();
2170 mediastream_signaling_.SendAudioVideoStream1();
2171 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
2172 session_->CreateOffer(NULL));
2173 std::string offer_str;
2174 offer->ToString(&offer_str);
2175 // Disable google-ice
2176 const std::string gice_option = "google-ice";
2177 const std::string xgoogle_xice = "xgoogle-xice";
2178 talk_base::replace_substrs(gice_option.c_str(), gice_option.length(),
2179 xgoogle_xice.c_str(), xgoogle_xice.length(),
2180 &offer_str);
2181 JsepSessionDescription *ice_only_offer =
2182 new JsepSessionDescription(JsepSessionDescription::kOffer);
2183 EXPECT_TRUE((ice_only_offer)->Initialize(offer_str, NULL));
2184 SetLocalDescriptionWithoutError(ice_only_offer);
2185 std::string original_offer_sdp;
2186 EXPECT_TRUE(offer->ToString(&original_offer_sdp));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002187 SessionDescriptionInterface* pranswer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002188 CreateSessionDescription(JsepSessionDescription::kPrAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002189 original_offer_sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190 SetRemoteDescriptionExpectError(kPushDownPranswerTDFailed,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002191 pranswer_with_gice);
2192 SessionDescriptionInterface* answer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002193 CreateSessionDescription(JsepSessionDescription::kAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002194 original_offer_sdp, NULL);
henrike@webrtc.org723d6832013-07-12 16:04:50 +00002195 SetRemoteDescriptionExpectError(kPushDownAnswerTDFailed,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002196 answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002197}
2198
2199// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2200TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
2201 Init();
2202 mediastream_signaling_.SendAudioVideoStream1();
2203 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
2204 SetLocalDescriptionWithoutError(offer);
2205 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
2206 CreateRemoteAnswer(session_->local_description()));
2207
2208 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2209 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002210 JsepSessionDescription* modified_answer =
2211 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212
2213 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2214 answer->session_id(),
2215 answer->session_version()));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002216 SetRemoteDescriptionExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217
2218 // Modifying content names.
2219 std::string sdp;
2220 EXPECT_TRUE(answer->ToString(&sdp));
2221 const std::string kAudioMid = "a=mid:audio";
2222 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2223
2224 // Replacing |audio| with |audio_content_name|.
2225 talk_base::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
2226 kAudioMidReplaceStr.c_str(),
2227 kAudioMidReplaceStr.length(),
2228 &sdp);
2229
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002230 SessionDescriptionInterface* modified_answer1 =
2231 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2232 SetRemoteDescriptionExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233
2234 SetRemoteDescriptionWithoutError(answer.release());
2235}
2236
2237// Verifying remote offer and local answer have matching m-lines as per
2238// RFC 3264.
2239TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
2240 Init();
2241 mediastream_signaling_.SendAudioVideoStream1();
2242 SessionDescriptionInterface* offer = CreateRemoteOffer();
2243 SetRemoteDescriptionWithoutError(offer);
2244 SessionDescriptionInterface* answer = session_->CreateAnswer(NULL);
2245
2246 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2247 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002248 JsepSessionDescription* modified_answer =
2249 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250
2251 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2252 answer->session_id(),
2253 answer->session_version()));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002254 SetLocalDescriptionExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002255 SetLocalDescriptionWithoutError(answer);
2256}
2257
2258// This test verifies that WebRtcSession does not start candidate allocation
2259// before SetLocalDescription is called.
2260TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
2261 Init();
2262 mediastream_signaling_.SendAudioVideoStream1();
2263 SessionDescriptionInterface* offer = CreateRemoteOffer();
2264 cricket::Candidate candidate;
2265 candidate.set_component(1);
2266 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2267 candidate);
2268 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2269 cricket::Candidate candidate1;
2270 candidate1.set_component(1);
2271 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2272 candidate1);
2273 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2274 SetRemoteDescriptionWithoutError(offer);
2275 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
2276 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
2277
2278 // Pump for 1 second and verify that no candidates are generated.
2279 talk_base::Thread::Current()->ProcessMessages(1000);
2280 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
2281 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
2282
2283 SessionDescriptionInterface* answer = session_->CreateAnswer(NULL);
2284 SetLocalDescriptionWithoutError(answer);
2285 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
2286 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
2287 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2288}
2289
2290// This test verifies that crypto parameter is updated in local session
2291// description as per security policy set in MediaSessionDescriptionFactory.
2292TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
2293 Init();
2294 mediastream_signaling_.SendAudioVideoStream1();
2295 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
2296 session_->CreateOffer(NULL));
2297
2298 // Making sure SetLocalDescription correctly sets crypto value in
2299 // SessionDescription object after de-serialization of sdp string. The value
2300 // will be set as per MediaSessionDescriptionFactory.
2301 std::string offer_str;
2302 offer->ToString(&offer_str);
2303 SessionDescriptionInterface* jsep_offer_str =
2304 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2305 SetLocalDescriptionWithoutError(jsep_offer_str);
2306 EXPECT_TRUE(session_->voice_channel()->secure_required());
2307 EXPECT_TRUE(session_->video_channel()->secure_required());
2308}
2309
2310// This test verifies the crypto parameter when security is disabled.
2311TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
2312 Init();
2313 mediastream_signaling_.SendAudioVideoStream1();
2314 session_->set_secure_policy(cricket::SEC_DISABLED);
2315 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
2316 session_->CreateOffer(NULL));
2317
2318 // Making sure SetLocalDescription correctly sets crypto value in
2319 // SessionDescription object after de-serialization of sdp string. The value
2320 // will be set as per MediaSessionDescriptionFactory.
2321 std::string offer_str;
2322 offer->ToString(&offer_str);
2323 SessionDescriptionInterface *jsep_offer_str =
2324 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2325 SetLocalDescriptionWithoutError(jsep_offer_str);
2326 EXPECT_FALSE(session_->voice_channel()->secure_required());
2327 EXPECT_FALSE(session_->video_channel()->secure_required());
2328}
2329
2330// This test verifies that an answer contains new ufrag and password if an offer
2331// with new ufrag and password is received.
2332TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
2333 Init();
2334 cricket::MediaSessionOptions options;
2335 options.has_audio = true;
2336 options.has_video = true;
2337 talk_base::scoped_ptr<JsepSessionDescription> offer(
2338 CreateRemoteOffer(options));
2339 SetRemoteDescriptionWithoutError(offer.release());
2340
2341 mediastream_signaling_.SendAudioVideoStream1();
2342 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
2343 session_->CreateAnswer(NULL));
2344 SetLocalDescriptionWithoutError(answer.release());
2345
2346 // Receive an offer with new ufrag and password.
2347 options.transport_options.ice_restart = true;
2348 talk_base::scoped_ptr<JsepSessionDescription> updated_offer1(
2349 CreateRemoteOffer(options,
2350 session_->remote_description()));
2351 SetRemoteDescriptionWithoutError(updated_offer1.release());
2352
2353 talk_base::scoped_ptr<SessionDescriptionInterface> updated_answer1(
2354 session_->CreateAnswer(NULL));
2355
2356 CompareIceUfragAndPassword(updated_answer1->description(),
2357 session_->local_description()->description(),
2358 false);
2359
2360 SetLocalDescriptionWithoutError(updated_answer1.release());
2361
2362 // Receive yet an offer without changed ufrag or password.
2363 options.transport_options.ice_restart = false;
2364 talk_base::scoped_ptr<JsepSessionDescription> updated_offer2(
2365 CreateRemoteOffer(options,
2366 session_->remote_description()));
2367 SetRemoteDescriptionWithoutError(updated_offer2.release());
2368
2369 talk_base::scoped_ptr<SessionDescriptionInterface> updated_answer2(
2370 session_->CreateAnswer(NULL));
2371
2372 CompareIceUfragAndPassword(updated_answer2->description(),
2373 session_->local_description()->description(),
2374 true);
2375
2376 SetLocalDescriptionWithoutError(updated_answer2.release());
2377}
2378
2379TEST_F(WebRtcSessionTest, TestSessionContentError) {
2380 Init();
2381 mediastream_signaling_.SendAudioVideoStream1();
2382 SessionDescriptionInterface* offer = session_->CreateOffer(NULL);
2383 const std::string session_id_orig = offer->session_id();
2384 const std::string session_version_orig = offer->session_version();
2385 SetLocalDescriptionWithoutError(offer);
2386
2387 video_channel_ = media_engine_->GetVideoChannel(0);
2388 video_channel_->set_fail_set_send_codecs(true);
2389
2390 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002391 SessionDescriptionInterface* answer =
2392 CreateRemoteAnswer(session_->local_description());
2393 SetRemoteDescriptionExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394}
2395
2396// Runs the loopback call test with BUNDLE and STUN disabled.
2397TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
2398 // Lets try with only UDP ports.
2399 allocator_.set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
2400 cricket::PORTALLOCATOR_DISABLE_TCP |
2401 cricket::PORTALLOCATOR_DISABLE_STUN |
2402 cricket::PORTALLOCATOR_DISABLE_RELAY);
2403 TestLoopbackCall();
2404}
2405
2406// Regression-test for a crash which should have been an error.
2407TEST_F(WebRtcSessionTest, TestNoStateTransitionPendingError) {
2408 Init();
2409 cricket::MediaSessionOptions options;
2410 options.has_audio = true;
2411 options.has_video = true;
2412
2413 session_->SetError(cricket::BaseSession::ERROR_CONTENT);
2414 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
2415 SessionDescriptionInterface* answer =
2416 CreateRemoteAnswer(offer, options);
2417 SetRemoteDescriptionExpectError(kSessionError, offer);
2418 SetLocalDescriptionExpectError(kSessionError, answer);
2419 // Not crashing is our success.
2420}
2421
2422TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
2423 constraints_.reset(new FakeConstraints());
2424 constraints_->AddOptional(
2425 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
2426 Init();
2427
2428 SetLocalDescriptionWithDataChannel();
2429 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
2430}
2431
2432TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
2433 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2434
2435 constraints_.reset(new FakeConstraints());
2436 constraints_->AddOptional(
2437 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
2438 constraints_->AddOptional(
2439 webrtc::MediaConstraintsInterface::kEnableSctpDataChannels, true);
2440 constraints_->AddOptional(
2441 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, true);
2442 Init();
2443
2444 SetLocalDescriptionWithDataChannel();
2445 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
2446}
2447
2448TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
2449 constraints_.reset(new FakeConstraints());
2450 constraints_->AddOptional(
2451 webrtc::MediaConstraintsInterface::kEnableSctpDataChannels, true);
2452 Init();
2453
2454 SetLocalDescriptionWithDataChannel();
2455 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
2456}
2457
2458TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
2459 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2460
2461 constraints_.reset(new FakeConstraints());
2462 constraints_->AddOptional(
2463 webrtc::MediaConstraintsInterface::kEnableSctpDataChannels, true);
2464 constraints_->AddOptional(
2465 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, true);
2466 Init();
2467
2468 SetLocalDescriptionWithDataChannel();
2469 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
2470}
2471// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
2472// currently fails because upon disconnection and reconnection OnIceComplete is
2473// called more than once without returning to IceGatheringGathering.