blob: ba58936e399c21b9afe50c8e48480279439220a8 [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"
wu@webrtc.org91053e72013-08-10 07:18:04 +000035#include "talk/app/webrtc/test/fakedtlsidentityservice.h"
36#include "talk/app/webrtc/test/fakemediastreamsignaling.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000038#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039#include "talk/base/fakenetwork.h"
40#include "talk/base/firewallsocketserver.h"
41#include "talk/base/gunit.h"
42#include "talk/base/logging.h"
43#include "talk/base/network.h"
44#include "talk/base/physicalsocketserver.h"
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000045#include "talk/base/ssladapter.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046#include "talk/base/sslstreamadapter.h"
47#include "talk/base/stringutils.h"
48#include "talk/base/thread.h"
49#include "talk/base/virtualsocketserver.h"
50#include "talk/media/base/fakemediaengine.h"
51#include "talk/media/base/fakevideorenderer.h"
52#include "talk/media/base/mediachannel.h"
53#include "talk/media/devices/fakedevicemanager.h"
54#include "talk/p2p/base/stunserver.h"
55#include "talk/p2p/base/teststunserver.h"
56#include "talk/p2p/client/basicportallocator.h"
57#include "talk/session/media/channelmanager.h"
58#include "talk/session/media/mediasession.h"
59
60#define MAYBE_SKIP_TEST(feature) \
61 if (!(feature())) { \
62 LOG(LS_INFO) << "Feature disabled... skipping"; \
63 return; \
64 }
65
66using cricket::BaseSession;
67using cricket::DF_PLAY;
68using cricket::DF_SEND;
69using cricket::FakeVoiceMediaChannel;
70using cricket::NS_GINGLE_P2P;
71using cricket::NS_JINGLE_ICE_UDP;
72using cricket::TransportInfo;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073using talk_base::SocketAddress;
74using talk_base::scoped_ptr;
75using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000076using webrtc::CreateSessionDescriptionObserver;
77using webrtc::CreateSessionDescriptionRequest;
78using webrtc::DTLSIdentityRequestObserver;
79using webrtc::DTLSIdentityServiceInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080using webrtc::FakeConstraints;
81using webrtc::IceCandidateCollection;
82using webrtc::JsepIceCandidate;
83using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000084using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085using webrtc::PeerConnectionInterface;
86using webrtc::SessionDescriptionInterface;
87using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000088using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000089using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000090using webrtc::kCreateChannelFailed;
91using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000093using webrtc::kPushDownTDFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094using webrtc::kSdpWithoutCrypto;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000095using webrtc::kSdpWithoutIceUfragPwd;
wu@webrtc.org364f2042013-11-20 21:49:41 +000096using webrtc::kSdpWithoutSdesAndDtlsDisabled;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000098using webrtc::kSessionErrorDesc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099
wu@webrtc.org364f2042013-11-20 21:49:41 +0000100static const int kClientAddrPort = 0;
101static const char kClientAddrHost1[] = "11.11.11.11";
102static const char kClientAddrHost2[] = "22.22.22.22";
103static const char kStunAddrHost[] = "99.99.99.1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104
105static const char kSessionVersion[] = "1";
106
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107// Media index of candidates belonging to the first media content.
108static const int kMediaContentIndex0 = 0;
109static const char kMediaContentName0[] = "audio";
110
111// Media index of candidates belonging to the second media content.
112static const int kMediaContentIndex1 = 1;
113static const char kMediaContentName1[] = "video";
114
115static const int kIceCandidatesTimeout = 10000;
116
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000117static const char kFakeDtlsFingerprint[] =
118 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
119 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
120
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121// Add some extra |newlines| to the |message| after |line|.
122static void InjectAfter(const std::string& line,
123 const std::string& newlines,
124 std::string* message) {
125 const std::string tmp = line + newlines;
126 talk_base::replace_substrs(line.c_str(), line.length(),
127 tmp.c_str(), tmp.length(), message);
128}
129
130class MockIceObserver : public webrtc::IceObserver {
131 public:
132 MockIceObserver()
133 : oncandidatesready_(false),
134 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
135 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
136 }
137
138 virtual void OnIceConnectionChange(
139 PeerConnectionInterface::IceConnectionState new_state) {
140 ice_connection_state_ = new_state;
141 }
142 virtual void OnIceGatheringChange(
143 PeerConnectionInterface::IceGatheringState new_state) {
144 // We can never transition back to "new".
145 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
146 ice_gathering_state_ = new_state;
147
148 // oncandidatesready_ really means "ICE gathering is complete".
149 // This if statement ensures that this value remains correct when we
150 // transition from kIceGatheringComplete to kIceGatheringGathering.
151 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
152 oncandidatesready_ = false;
153 }
154 }
155
156 // Found a new candidate.
157 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000158 switch (candidate->sdp_mline_index()) {
159 case kMediaContentIndex0:
160 mline_0_candidates_.push_back(candidate->candidate());
161 break;
162 case kMediaContentIndex1:
163 mline_1_candidates_.push_back(candidate->candidate());
164 break;
165 default:
166 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000168
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 // The ICE gathering state should always be Gathering when a candidate is
170 // received (or possibly Completed in the case of the final candidate).
171 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
172 }
173
174 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
175 virtual void OnIceComplete() {
176 EXPECT_FALSE(oncandidatesready_);
177 oncandidatesready_ = true;
178
179 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
180 // be called approximately simultaneously. For ease of testing, this
181 // check additionally requires that they be called in the above order.
182 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
183 ice_gathering_state_);
184 }
185
186 bool oncandidatesready_;
187 std::vector<cricket::Candidate> mline_0_candidates_;
188 std::vector<cricket::Candidate> mline_1_candidates_;
189 PeerConnectionInterface::IceConnectionState ice_connection_state_;
190 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
191};
192
193class WebRtcSessionForTest : public webrtc::WebRtcSession {
194 public:
195 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
196 talk_base::Thread* signaling_thread,
197 talk_base::Thread* worker_thread,
198 cricket::PortAllocator* port_allocator,
199 webrtc::IceObserver* ice_observer,
200 webrtc::MediaStreamSignaling* mediastream_signaling)
201 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
202 mediastream_signaling) {
203 RegisterIceObserver(ice_observer);
204 }
205 virtual ~WebRtcSessionForTest() {}
206
207 using cricket::BaseSession::GetTransportProxy;
208 using webrtc::WebRtcSession::SetAudioPlayout;
209 using webrtc::WebRtcSession::SetAudioSend;
210 using webrtc::WebRtcSession::SetCaptureDevice;
211 using webrtc::WebRtcSession::SetVideoPlayout;
212 using webrtc::WebRtcSession::SetVideoSend;
213};
214
wu@webrtc.org91053e72013-08-10 07:18:04 +0000215class WebRtcSessionCreateSDPObserverForTest
216 : public talk_base::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000218 enum State {
219 kInit,
220 kFailed,
221 kSucceeded,
222 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000223 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000224
225 // CreateSessionDescriptionObserver implementation.
226 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000227 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000228 state_ = kSucceeded;
229 }
230 virtual void OnFailure(const std::string& error) {
231 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 }
233
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000234 SessionDescriptionInterface* description() { return description_.get(); }
235
236 SessionDescriptionInterface* ReleaseDescription() {
237 return description_.release();
238 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239
wu@webrtc.org91053e72013-08-10 07:18:04 +0000240 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241
wu@webrtc.org91053e72013-08-10 07:18:04 +0000242 protected:
243 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244
245 private:
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000246 talk_base::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000247 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248};
249
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000250class FakeAudioRenderer : public cricket::AudioRenderer {
251 public:
252 FakeAudioRenderer() : channel_id_(-1) {}
253
254 virtual void AddChannel(int channel_id) OVERRIDE {
255 ASSERT(channel_id_ == -1);
256 channel_id_ = channel_id;
257 }
258 virtual void RemoveChannel(int channel_id) OVERRIDE {
259 ASSERT(channel_id == channel_id_);
260 channel_id_ = -1;
261 }
262
263 int channel_id() const { return channel_id_; }
264 private:
265 int channel_id_;
266};
267
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268class WebRtcSessionTest : public testing::Test {
269 protected:
270 // TODO Investigate why ChannelManager crashes, if it's created
271 // after stun_server.
272 WebRtcSessionTest()
273 : media_engine_(new cricket::FakeMediaEngine()),
274 data_engine_(new cricket::FakeDataEngine()),
275 device_manager_(new cricket::FakeDeviceManager()),
276 channel_manager_(new cricket::ChannelManager(
277 media_engine_, data_engine_, device_manager_,
278 new cricket::CaptureManager(), talk_base::Thread::Current())),
279 tdesc_factory_(new cricket::TransportDescriptionFactory()),
280 desc_factory_(new cricket::MediaSessionDescriptionFactory(
281 channel_manager_.get(), tdesc_factory_.get())),
282 pss_(new talk_base::PhysicalSocketServer),
283 vss_(new talk_base::VirtualSocketServer(pss_.get())),
284 fss_(new talk_base::FirewallSocketServer(vss_.get())),
285 ss_scope_(fss_.get()),
wu@webrtc.org364f2042013-11-20 21:49:41 +0000286 stun_socket_addr_(talk_base::SocketAddress(kStunAddrHost,
287 cricket::STUN_SERVER_PORT)),
288 stun_server_(talk_base::Thread::Current(), stun_socket_addr_),
289 allocator_(&network_manager_, stun_socket_addr_,
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000290 SocketAddress(), SocketAddress(), SocketAddress()),
291 mediastream_signaling_(channel_manager_.get()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
293 allocator_.set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
294 cricket::PORTALLOCATOR_DISABLE_RELAY |
295 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
296 EXPECT_TRUE(channel_manager_->Init());
297 desc_factory_->set_add_legacy_streams(false);
298 }
299
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000300 static void SetUpTestCase() {
301 talk_base::InitializeSSL();
302 }
303
304 static void TearDownTestCase() {
305 talk_base::CleanupSSL();
306 }
307
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 void AddInterface(const SocketAddress& addr) {
309 network_manager_.AddInterface(addr);
310 }
311
wu@webrtc.org91053e72013-08-10 07:18:04 +0000312 void Init(DTLSIdentityServiceInterface* identity_service) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 ASSERT_TRUE(session_.get() == NULL);
314 session_.reset(new WebRtcSessionForTest(
315 channel_manager_.get(), talk_base::Thread::Current(),
316 talk_base::Thread::Current(), &allocator_,
317 &observer_,
318 &mediastream_signaling_));
319
320 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
321 observer_.ice_connection_state_);
322 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
323 observer_.ice_gathering_state_);
324
wu@webrtc.org97077a32013-10-25 21:18:33 +0000325 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
326 identity_service));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 }
328
329 void InitWithDtmfCodec() {
330 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000331 const cricket::AudioCodec kTelephoneEventCodec(
332 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333 std::vector<cricket::AudioCodec> codecs;
334 codecs.push_back(kTelephoneEventCodec);
335 media_engine_->SetAudioCodecs(codecs);
336 desc_factory_->set_audio_codecs(codecs);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000337 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 }
339
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000340 void InitWithDtls(bool identity_request_should_fail = false) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000341 FakeIdentityService* identity_service = new FakeIdentityService();
342 identity_service->set_should_fail(identity_request_should_fail);
343 Init(identity_service);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 }
345
346 // Creates a local offer and applies it. Starts ice.
347 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
348 // to decide which streams to create.
349 void InitiateCall() {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000350 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 SetLocalDescriptionWithoutError(offer);
352 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
353 observer_.ice_gathering_state_,
354 kIceCandidatesTimeout);
355 }
356
wu@webrtc.org91053e72013-08-10 07:18:04 +0000357 SessionDescriptionInterface* CreateOffer(
358 const webrtc::MediaConstraintsInterface* constraints) {
359 talk_base::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
360 observer = new WebRtcSessionCreateSDPObserverForTest();
361 session_->CreateOffer(observer, constraints);
362 EXPECT_TRUE_WAIT(
363 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000364 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000365 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000366 }
367
368 SessionDescriptionInterface* CreateAnswer(
369 const webrtc::MediaConstraintsInterface* constraints) {
370 talk_base::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
371 = new WebRtcSessionCreateSDPObserverForTest();
372 session_->CreateAnswer(observer, constraints);
373 EXPECT_TRUE_WAIT(
374 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000375 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000376 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000377 }
378
wu@webrtc.org364f2042013-11-20 21:49:41 +0000379 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 return (session_->voice_channel() != NULL &&
381 session_->video_channel() != NULL);
382 }
383
wu@webrtc.org364f2042013-11-20 21:49:41 +0000384 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
386 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
387 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
388 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
389 }
390
391 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
392 ASSERT_TRUE(session_.get() != NULL);
393 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
394 ASSERT_TRUE(content != NULL);
395 const cricket::AudioContentDescription* audio_content =
396 static_cast<const cricket::AudioContentDescription*>(
397 content->description);
398 ASSERT_TRUE(audio_content != NULL);
399 ASSERT_EQ(1U, audio_content->cryptos().size());
400 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
401 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
402 audio_content->cryptos()[0].cipher_suite);
403 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
404 audio_content->protocol());
405
406 content = cricket::GetFirstVideoContent(sdp);
407 ASSERT_TRUE(content != NULL);
408 const cricket::VideoContentDescription* video_content =
409 static_cast<const cricket::VideoContentDescription*>(
410 content->description);
411 ASSERT_TRUE(video_content != NULL);
412 ASSERT_EQ(1U, video_content->cryptos().size());
413 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
414 video_content->cryptos()[0].cipher_suite);
415 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
416 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
417 video_content->protocol());
418 }
419
420 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
421 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
422 ASSERT_TRUE(content != NULL);
423 const cricket::AudioContentDescription* audio_content =
424 static_cast<const cricket::AudioContentDescription*>(
425 content->description);
426 ASSERT_TRUE(audio_content != NULL);
427 ASSERT_EQ(0U, audio_content->cryptos().size());
428
429 content = cricket::GetFirstVideoContent(sdp);
430 ASSERT_TRUE(content != NULL);
431 const cricket::VideoContentDescription* video_content =
432 static_cast<const cricket::VideoContentDescription*>(
433 content->description);
434 ASSERT_TRUE(video_content != NULL);
435 ASSERT_EQ(0U, video_content->cryptos().size());
436
437 if (dtls) {
438 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
439 audio_content->protocol());
440 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
441 video_content->protocol());
442 } else {
443 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
444 audio_content->protocol());
445 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
446 video_content->protocol());
447 }
448 }
449
450 // Set the internal fake description factories to do DTLS-SRTP.
451 void SetFactoryDtlsSrtp() {
452 desc_factory_->set_secure(cricket::SEC_ENABLED);
453 std::string identity_name = "WebRTC" +
454 talk_base::ToString(talk_base::CreateRandomId());
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000455 identity_.reset(talk_base::SSLIdentity::Generate(identity_name));
456 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
458 }
459
460 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
461 bool expected) {
462 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
463 ASSERT_TRUE(audio != NULL);
464 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465 const TransportInfo* video = sdp->GetTransportInfoByName("video");
466 ASSERT_TRUE(video != NULL);
467 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 }
469
470 void VerifyAnswerFromNonCryptoOffer() {
471 // Create a SDP without Crypto.
472 cricket::MediaSessionOptions options;
473 options.has_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000474 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000476 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000477 VerifyNoCryptoParams(offer->description(), false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000478 SetRemoteDescriptionOfferExpectError(
479 "Called with a SDP without crypto enabled", offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000480 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000481 // Answer should be NULL as no crypto params in offer.
482 ASSERT_TRUE(answer == NULL);
483 }
484
485 void VerifyAnswerFromCryptoOffer() {
486 cricket::MediaSessionOptions options;
487 options.has_video = true;
488 options.bundle_enabled = true;
489 scoped_ptr<JsepSessionDescription> offer(
490 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
491 ASSERT_TRUE(offer.get() != NULL);
492 VerifyCryptoParams(offer->description());
493 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000494 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000495 ASSERT_TRUE(answer.get() != NULL);
496 VerifyCryptoParams(answer->description());
497 }
498
499 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
500 const cricket::SessionDescription* desc2,
501 bool expect_equal) {
502 if (desc1->contents().size() != desc2->contents().size()) {
503 EXPECT_FALSE(expect_equal);
504 return;
505 }
506
507 const cricket::ContentInfos& contents = desc1->contents();
508 cricket::ContentInfos::const_iterator it = contents.begin();
509
510 for (; it != contents.end(); ++it) {
511 const cricket::TransportDescription* transport_desc1 =
512 desc1->GetTransportDescriptionByName(it->name);
513 const cricket::TransportDescription* transport_desc2 =
514 desc2->GetTransportDescriptionByName(it->name);
515 if (!transport_desc1 || !transport_desc2) {
516 EXPECT_FALSE(expect_equal);
517 return;
518 }
519 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
520 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
521 EXPECT_FALSE(expect_equal);
522 return;
523 }
524 }
525 EXPECT_TRUE(expect_equal);
526 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000527
528 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
529 std::string *sdp) {
530 const cricket::SessionDescription* desc = current_desc->description();
531 EXPECT_TRUE(current_desc->ToString(sdp));
532
533 const cricket::ContentInfos& contents = desc->contents();
534 cricket::ContentInfos::const_iterator it = contents.begin();
535 // Replace ufrag and pwd lines with empty strings.
536 for (; it != contents.end(); ++it) {
537 const cricket::TransportDescription* transport_desc =
538 desc->GetTransportDescriptionByName(it->name);
539 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
540 + "\r\n";
541 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
542 + "\r\n";
543 talk_base::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
544 "", 0,
545 sdp);
546 talk_base::replace_substrs(pwd_line.c_str(), pwd_line.length(),
547 "", 0,
548 sdp);
549 }
550 }
551
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000552 // Creates a remote offer and and applies it as a remote description,
553 // creates a local answer and applies is as a local description.
554 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
555 // to decide which local and remote streams to create.
556 void CreateAndSetRemoteOfferAndLocalAnswer() {
557 SessionDescriptionInterface* offer = CreateRemoteOffer();
558 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000559 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 SetLocalDescriptionWithoutError(answer);
561 }
562 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
563 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
564 }
565 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
566 BaseSession::State expected_state) {
567 SetLocalDescriptionWithoutError(desc);
568 EXPECT_EQ(expected_state, session_->state());
569 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000570 void SetLocalDescriptionExpectError(const std::string& action,
571 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 SessionDescriptionInterface* desc) {
573 std::string error;
574 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000575 std::string sdp_type = "local ";
576 sdp_type.append(action);
577 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 EXPECT_NE(std::string::npos, error.find(expected_error));
579 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000580 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
581 SessionDescriptionInterface* desc) {
582 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
583 expected_error, desc);
584 }
585 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
586 SessionDescriptionInterface* desc) {
587 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
588 expected_error, desc);
589 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000590 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
591 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
592 }
593 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
594 BaseSession::State expected_state) {
595 SetRemoteDescriptionWithoutError(desc);
596 EXPECT_EQ(expected_state, session_->state());
597 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000598 void SetRemoteDescriptionExpectError(const std::string& action,
599 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000600 SessionDescriptionInterface* desc) {
601 std::string error;
602 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000603 std::string sdp_type = "remote ";
604 sdp_type.append(action);
605 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606 EXPECT_NE(std::string::npos, error.find(expected_error));
607 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000608 void SetRemoteDescriptionOfferExpectError(
609 const std::string& expected_error, SessionDescriptionInterface* desc) {
610 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
611 expected_error, desc);
612 }
613 void SetRemoteDescriptionPranswerExpectError(
614 const std::string& expected_error, SessionDescriptionInterface* desc) {
615 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
616 expected_error, desc);
617 }
618 void SetRemoteDescriptionAnswerExpectError(
619 const std::string& expected_error, SessionDescriptionInterface* desc) {
620 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
621 expected_error, desc);
622 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000623
624 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
625 SessionDescriptionInterface** nocrypto_answer) {
626 // Create a SDP without Crypto.
627 cricket::MediaSessionOptions options;
628 options.has_video = true;
629 options.bundle_enabled = true;
630 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
631 ASSERT_TRUE(*offer != NULL);
632 VerifyCryptoParams((*offer)->description());
633
634 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
635 cricket::SEC_DISABLED);
636 EXPECT_TRUE(*nocrypto_answer != NULL);
637 }
638
639 JsepSessionDescription* CreateRemoteOfferWithVersion(
640 cricket::MediaSessionOptions options,
641 cricket::SecurePolicy secure_policy,
642 const std::string& session_version,
643 const SessionDescriptionInterface* current_desc) {
644 std::string session_id = talk_base::ToString(talk_base::CreateRandomId64());
645 const cricket::SessionDescription* cricket_desc = NULL;
646 if (current_desc) {
647 cricket_desc = current_desc->description();
648 session_id = current_desc->session_id();
649 }
650
651 desc_factory_->set_secure(secure_policy);
652 JsepSessionDescription* offer(
653 new JsepSessionDescription(JsepSessionDescription::kOffer));
654 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
655 session_id, session_version)) {
656 delete offer;
657 offer = NULL;
658 }
659 return offer;
660 }
661 JsepSessionDescription* CreateRemoteOffer(
662 cricket::MediaSessionOptions options) {
663 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
664 kSessionVersion, NULL);
665 }
666 JsepSessionDescription* CreateRemoteOffer(
667 cricket::MediaSessionOptions options, cricket::SecurePolicy policy) {
668 return CreateRemoteOfferWithVersion(options, policy, kSessionVersion, NULL);
669 }
670 JsepSessionDescription* CreateRemoteOffer(
671 cricket::MediaSessionOptions options,
672 const SessionDescriptionInterface* current_desc) {
673 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
674 kSessionVersion, current_desc);
675 }
676
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000677 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
678 const char* sctp_stream_name, int new_port,
679 cricket::MediaSessionOptions options) {
680 options.data_channel_type = cricket::DCT_SCTP;
681 options.AddStream(cricket::MEDIA_TYPE_DATA, "datachannel",
682 sctp_stream_name);
683 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
684 }
685
686 // Takes ownership of offer_basis (and deletes it).
687 JsepSessionDescription* ChangeSDPSctpPort(
688 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
689 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
690 // SessionDescription from the mutated string.
691 const char* default_port_str = "5000";
692 char new_port_str[16];
693 talk_base::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
694 std::string offer_str;
695 offer_basis->ToString(&offer_str);
696 talk_base::replace_substrs(default_port_str, strlen(default_port_str),
697 new_port_str, strlen(new_port_str),
698 &offer_str);
699 JsepSessionDescription* offer = new JsepSessionDescription(
700 offer_basis->type());
701 delete offer_basis;
702 offer->Initialize(offer_str, NULL);
703 return offer;
704 }
705
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
707 // before this function to decide which streams to create.
708 JsepSessionDescription* CreateRemoteOffer() {
709 cricket::MediaSessionOptions options;
710 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
711 return CreateRemoteOffer(options, session_->remote_description());
712 }
713
714 JsepSessionDescription* CreateRemoteAnswer(
715 const SessionDescriptionInterface* offer,
716 cricket::MediaSessionOptions options,
717 cricket::SecurePolicy policy) {
718 desc_factory_->set_secure(policy);
719 const std::string session_id =
720 talk_base::ToString(talk_base::CreateRandomId64());
721 JsepSessionDescription* answer(
722 new JsepSessionDescription(JsepSessionDescription::kAnswer));
723 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
724 options, NULL),
725 session_id, kSessionVersion)) {
726 delete answer;
727 answer = NULL;
728 }
729 return answer;
730 }
731
732 JsepSessionDescription* CreateRemoteAnswer(
733 const SessionDescriptionInterface* offer,
734 cricket::MediaSessionOptions options) {
735 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
736 }
737
738 // Creates an answer session description with streams based on
739 // |mediastream_signaling_|. Call
740 // mediastream_signaling_.UseOptionsWithStreamX() before this function
741 // to decide which streams to create.
742 JsepSessionDescription* CreateRemoteAnswer(
743 const SessionDescriptionInterface* offer) {
744 cricket::MediaSessionOptions options;
745 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
746 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
747 }
748
749 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000750 AddInterface(talk_base::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000751 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 mediastream_signaling_.SendAudioVideoStream1();
753 FakeConstraints constraints;
754 constraints.SetMandatoryUseRtpMux(bundle);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000755 SessionDescriptionInterface* offer = CreateOffer(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
757 // and answer.
758 SetLocalDescriptionWithoutError(offer);
759
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000760 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
761 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762 std::string sdp;
763 EXPECT_TRUE(answer->ToString(&sdp));
764
765 size_t expected_candidate_num = 2;
766 if (!rtcp_mux) {
767 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
768 // for rtp and rtcp.
769 expected_candidate_num = 4;
770 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771 const std::string kRtcpMux = "a=rtcp-mux";
772 const std::string kXRtcpMux = "a=xrtcp-mux";
773 talk_base::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
774 kXRtcpMux.c_str(), kXRtcpMux.length(),
775 &sdp);
776 }
777
778 SessionDescriptionInterface* new_answer = CreateSessionDescription(
779 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780
781 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000782 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
784 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
785 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
786 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
787 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
788 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
789 if (bundle) {
790 EXPECT_TRUE(c0.IsEquivalent(c1));
791 } else {
792 EXPECT_FALSE(c0.IsEquivalent(c1));
793 }
794 }
795 }
796 // Tests that we can only send DTMF when the dtmf codec is supported.
797 void TestCanInsertDtmf(bool can) {
798 if (can) {
799 InitWithDtmfCodec();
800 } else {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000801 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 }
803 mediastream_signaling_.SendAudioVideoStream1();
804 CreateAndSetRemoteOfferAndLocalAnswer();
805 EXPECT_FALSE(session_->CanInsertDtmf(""));
806 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
807 }
808
809 // The method sets up a call from the session to itself, in a loopback
810 // arrangement. It also uses a firewall rule to create a temporary
811 // disconnection. This code is placed as a method so that it can be invoked
812 // by multiple tests with different allocators (e.g. with and without BUNDLE).
813 // While running the call, this method also checks if the session goes through
814 // the correct sequence of ICE states when a connection is established,
815 // broken, and re-established.
816 // The Connection state should go:
817 // New -> Checking -> Connected -> Disconnected -> Connected.
818 // The Gathering state should go: New -> Gathering -> Completed.
819 void TestLoopbackCall() {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000820 AddInterface(talk_base::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000821 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000823 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824
825 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
826 observer_.ice_gathering_state_);
827 SetLocalDescriptionWithoutError(offer);
828 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
829 observer_.ice_connection_state_);
830 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
831 observer_.ice_gathering_state_,
832 kIceCandidatesTimeout);
833 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
834 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
835 observer_.ice_gathering_state_,
836 kIceCandidatesTimeout);
837
838 std::string sdp;
839 offer->ToString(&sdp);
840 SessionDescriptionInterface* desc =
841 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
842 ASSERT_TRUE(desc != NULL);
843 SetRemoteDescriptionWithoutError(desc);
844
845 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
846 observer_.ice_connection_state_,
847 kIceCandidatesTimeout);
848 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionConnected,
849 observer_.ice_connection_state_,
850 kIceCandidatesTimeout);
851 // TODO(bemasc): EXPECT(Completed) once the details are standardized.
852
853 // Adding firewall rule to block ping requests, which should cause
854 // transport channel failure.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000855 fss_->AddRule(false,
856 talk_base::FP_ANY,
857 talk_base::FD_ANY,
858 talk_base::SocketAddress(kClientAddrHost1, kClientAddrPort));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
860 observer_.ice_connection_state_,
861 kIceCandidatesTimeout);
862
863 // Clearing the rules, session should move back to completed state.
864 fss_->ClearRules();
865 // Session is automatically calling OnSignalingReady after creation of
866 // new portallocator session which will allocate new set of candidates.
867
868 // TODO(bemasc): Change this to Completed once the details are standardized.
869 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionConnected,
870 observer_.ice_connection_state_,
871 kIceCandidatesTimeout);
872 }
873
874 void VerifyTransportType(const std::string& content_name,
875 cricket::TransportProtocol protocol) {
876 const cricket::Transport* transport = session_->GetTransport(content_name);
877 ASSERT_TRUE(transport != NULL);
878 EXPECT_EQ(protocol, transport->protocol());
879 }
880
881 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
882 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000883 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
884 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
885
886 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
888 codecs.push_back(kCNCodec1);
889 codecs.push_back(kCNCodec2);
890 media_engine_->SetAudioCodecs(codecs);
891 desc_factory_->set_audio_codecs(codecs);
892 }
893
894 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
895 const cricket::ContentDescription* description = content->description;
896 ASSERT(description != NULL);
897 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000898 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 ASSERT(audio_content_desc != NULL);
900 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
901 if (audio_content_desc->codecs()[i].name == "CN")
902 return false;
903 }
904 return true;
905 }
906
907 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000908 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 dci.reliable = false;
910 session_->CreateDataChannel("datachannel", &dci);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000911 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 SetLocalDescriptionWithoutError(offer);
913 }
914
wu@webrtc.org91053e72013-08-10 07:18:04 +0000915 void VerifyMultipleAsyncCreateDescription(
916 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000917 InitWithDtls(!success);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000918
919 if (type == CreateSessionDescriptionRequest::kAnswer) {
920 cricket::MediaSessionOptions options;
921 scoped_ptr<JsepSessionDescription> offer(
922 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
923 ASSERT_TRUE(offer.get() != NULL);
924 SetRemoteDescriptionWithoutError(offer.release());
925 }
926
927 const int kNumber = 3;
928 talk_base::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
929 observers[kNumber];
930 for (int i = 0; i < kNumber; ++i) {
931 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
932 if (type == CreateSessionDescriptionRequest::kOffer) {
933 session_->CreateOffer(observers[i], NULL);
934 } else {
935 session_->CreateAnswer(observers[i], NULL);
936 }
937 }
938
939 WebRtcSessionCreateSDPObserverForTest::State expected_state =
940 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
941 WebRtcSessionCreateSDPObserverForTest::kFailed;
942
943 for (int i = 0; i < kNumber; ++i) {
944 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
945 if (success) {
946 EXPECT_TRUE(observers[i]->description() != NULL);
947 } else {
948 EXPECT_TRUE(observers[i]->description() == NULL);
949 }
950 }
951 }
952
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 cricket::FakeMediaEngine* media_engine_;
954 cricket::FakeDataEngine* data_engine_;
955 cricket::FakeDeviceManager* device_manager_;
956 talk_base::scoped_ptr<cricket::ChannelManager> channel_manager_;
957 talk_base::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000958 talk_base::scoped_ptr<talk_base::SSLIdentity> identity_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 talk_base::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
960 talk_base::scoped_ptr<talk_base::PhysicalSocketServer> pss_;
961 talk_base::scoped_ptr<talk_base::VirtualSocketServer> vss_;
962 talk_base::scoped_ptr<talk_base::FirewallSocketServer> fss_;
963 talk_base::SocketServerScope ss_scope_;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000964 talk_base::SocketAddress stun_socket_addr_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000965 cricket::TestStunServer stun_server_;
966 talk_base::FakeNetworkManager network_manager_;
967 cricket::BasicPortAllocator allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000968 PeerConnectionFactoryInterface::Options options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 talk_base::scoped_ptr<FakeConstraints> constraints_;
970 FakeMediaStreamSignaling mediastream_signaling_;
971 talk_base::scoped_ptr<WebRtcSessionForTest> session_;
972 MockIceObserver observer_;
973 cricket::FakeVideoMediaChannel* video_channel_;
974 cricket::FakeVoiceMediaChannel* voice_channel_;
975};
976
977TEST_F(WebRtcSessionTest, TestInitialize) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000978 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979}
980
981TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
982 InitWithDtls();
983}
984
wu@webrtc.org91053e72013-08-10 07:18:04 +0000985// Verifies that WebRtcSession uses SEC_REQUIRED by default.
986TEST_F(WebRtcSessionTest, TestDefaultSetSecurePolicy) {
987 Init(NULL);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000988 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SecurePolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000989}
990
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991TEST_F(WebRtcSessionTest, TestSessionCandidates) {
992 TestSessionCandidatesWithBundleRtcpMux(false, false);
993}
994
995// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
996// with rtcp-mux and/or bundle.
997TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
998 TestSessionCandidatesWithBundleRtcpMux(false, true);
999}
1000
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1002 TestSessionCandidatesWithBundleRtcpMux(true, true);
1003}
1004
1005TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001006 AddInterface(talk_base::SocketAddress(kClientAddrHost1, kClientAddrPort));
1007 AddInterface(talk_base::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001008 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 mediastream_signaling_.SendAudioVideoStream1();
1010 InitiateCall();
1011 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1012 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1013 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1014}
1015
1016TEST_F(WebRtcSessionTest, TestStunError) {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001017 AddInterface(talk_base::SocketAddress(kClientAddrHost1, kClientAddrPort));
1018 AddInterface(talk_base::SocketAddress(kClientAddrHost2, kClientAddrPort));
1019 fss_->AddRule(false,
1020 talk_base::FP_UDP,
1021 talk_base::FD_ANY,
1022 talk_base::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001023 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001024 mediastream_signaling_.SendAudioVideoStream1();
1025 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001026 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001027 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1028 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1029 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1030}
1031
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001032TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
1033 Init(NULL);
1034 SessionDescriptionInterface* offer = NULL;
1035 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1036 std::string unknown_action;
1037 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1038 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1039}
1040
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041// Test creating offers and receive answers and make sure the
1042// media engine creates the expected send and receive streams.
1043TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001044 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001046 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047 const std::string session_id_orig = offer->session_id();
1048 const std::string session_version_orig = offer->session_version();
1049 SetLocalDescriptionWithoutError(offer);
1050
1051 mediastream_signaling_.SendAudioVideoStream2();
1052 SessionDescriptionInterface* answer =
1053 CreateRemoteAnswer(session_->local_description());
1054 SetRemoteDescriptionWithoutError(answer);
1055
1056 video_channel_ = media_engine_->GetVideoChannel(0);
1057 voice_channel_ = media_engine_->GetVoiceChannel(0);
1058
1059 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1060 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1061
1062 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1063 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1064
1065 ASSERT_EQ(1u, video_channel_->send_streams().size());
1066 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1067 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1068 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1069
1070 // Create new offer without send streams.
1071 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001072 offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073
1074 // Verify the session id is the same and the session version is
1075 // increased.
1076 EXPECT_EQ(session_id_orig, offer->session_id());
1077 EXPECT_LT(talk_base::FromString<uint64>(session_version_orig),
1078 talk_base::FromString<uint64>(offer->session_version()));
1079
1080 SetLocalDescriptionWithoutError(offer);
1081
1082 mediastream_signaling_.SendAudioVideoStream2();
1083 answer = CreateRemoteAnswer(session_->local_description());
1084 SetRemoteDescriptionWithoutError(answer);
1085
1086 EXPECT_EQ(0u, video_channel_->send_streams().size());
1087 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1088
1089 // Make sure the receive streams have not changed.
1090 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1091 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1092 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1093 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1094}
1095
1096// Test receiving offers and creating answers and make sure the
1097// media engine creates the expected send and receive streams.
1098TEST_F(WebRtcSessionTest, TestReceiveOfferCreateAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001099 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001101 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 SetRemoteDescriptionWithoutError(offer);
1103
1104 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001105 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 SetLocalDescriptionWithoutError(answer);
1107
1108 const std::string session_id_orig = answer->session_id();
1109 const std::string session_version_orig = answer->session_version();
1110
1111 video_channel_ = media_engine_->GetVideoChannel(0);
1112 voice_channel_ = media_engine_->GetVoiceChannel(0);
1113
1114 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1115 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1116
1117 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1118 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1119
1120 ASSERT_EQ(1u, video_channel_->send_streams().size());
1121 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1122 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1123 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1124
1125 mediastream_signaling_.SendAudioVideoStream1And2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001126 offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127 SetRemoteDescriptionWithoutError(offer);
1128
1129 // Answer by turning off all send streams.
1130 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001131 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001132
1133 // Verify the session id is the same and the session version is
1134 // increased.
1135 EXPECT_EQ(session_id_orig, answer->session_id());
1136 EXPECT_LT(talk_base::FromString<uint64>(session_version_orig),
1137 talk_base::FromString<uint64>(answer->session_version()));
1138 SetLocalDescriptionWithoutError(answer);
1139
1140 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1141 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1142 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1143 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1144 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1145 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1146
1147 // Make sure we have no send streams.
1148 EXPECT_EQ(0u, video_channel_->send_streams().size());
1149 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1150}
1151
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001152TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
1153 Init(NULL);
1154 media_engine_->set_fail_create_channel(true);
1155
1156 SessionDescriptionInterface* offer = CreateOffer(NULL);
1157 ASSERT_TRUE(offer != NULL);
1158 // SetRemoteDescription and SetLocalDescription will take the ownership of
1159 // the offer.
1160 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
1161 offer = CreateOffer(NULL);
1162 ASSERT_TRUE(offer != NULL);
1163 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1164}
1165
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001166// Test we will return fail when apply an offer that doesn't have
1167// crypto enabled.
1168TEST_F(WebRtcSessionTest, SetNonCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001169 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170 cricket::MediaSessionOptions options;
1171 options.has_video = true;
1172 JsepSessionDescription* offer = CreateRemoteOffer(
1173 options, cricket::SEC_DISABLED);
1174 ASSERT_TRUE(offer != NULL);
1175 VerifyNoCryptoParams(offer->description(), false);
1176 // SetRemoteDescription and SetLocalDescription will take the ownership of
1177 // the offer.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001178 SetRemoteDescriptionOfferExpectError(kSdpWithoutCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001179 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1180 ASSERT_TRUE(offer != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001181 SetLocalDescriptionOfferExpectError(kSdpWithoutCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001182}
1183
1184// Test we will return fail when apply an answer that doesn't have
1185// crypto enabled.
1186TEST_F(WebRtcSessionTest, SetLocalNonCryptoAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001187 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001188 SessionDescriptionInterface* offer = NULL;
1189 SessionDescriptionInterface* answer = NULL;
1190 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1191 // SetRemoteDescription and SetLocalDescription will take the ownership of
1192 // the offer.
1193 SetRemoteDescriptionWithoutError(offer);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001194 SetLocalDescriptionAnswerExpectError(kSdpWithoutCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001195}
1196
1197// Test we will return fail when apply an answer that doesn't have
1198// crypto enabled.
1199TEST_F(WebRtcSessionTest, SetRemoteNonCryptoAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001200 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001201 SessionDescriptionInterface* offer = NULL;
1202 SessionDescriptionInterface* answer = NULL;
1203 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1204 // SetRemoteDescription and SetLocalDescription will take the ownership of
1205 // the offer.
1206 SetLocalDescriptionWithoutError(offer);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001207 SetRemoteDescriptionAnswerExpectError(kSdpWithoutCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001208}
1209
1210// Test that we can create and set an offer with a DTLS fingerprint.
1211TEST_F(WebRtcSessionTest, CreateSetDtlsOffer) {
1212 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
1213 InitWithDtls();
1214 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001215 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001216 ASSERT_TRUE(offer != NULL);
1217 VerifyFingerprintStatus(offer->description(), true);
1218 // SetLocalDescription will take the ownership of the offer.
1219 SetLocalDescriptionWithoutError(offer);
1220}
1221
1222// Test that we can process an offer with a DTLS fingerprint
1223// and that we return an answer with a fingerprint.
1224TEST_F(WebRtcSessionTest, ReceiveDtlsOfferCreateAnswer) {
1225 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
1226 InitWithDtls();
1227 SetFactoryDtlsSrtp();
1228 cricket::MediaSessionOptions options;
1229 options.has_video = true;
1230 JsepSessionDescription* offer = CreateRemoteOffer(options);
1231 ASSERT_TRUE(offer != NULL);
1232 VerifyFingerprintStatus(offer->description(), true);
1233
1234 // SetRemoteDescription will take the ownership of the offer.
1235 SetRemoteDescriptionWithoutError(offer);
1236
1237 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001238 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001239 ASSERT_TRUE(answer != NULL);
1240 VerifyFingerprintStatus(answer->description(), true);
1241 // Check that we don't have an a=crypto line in the answer.
1242 VerifyNoCryptoParams(answer->description(), true);
1243
1244 // Now set the local description, which should work, even without a=crypto.
1245 SetLocalDescriptionWithoutError(answer);
1246}
1247
1248// Test that even if we support DTLS, if the other side didn't offer a
1249// fingerprint, we don't either.
1250TEST_F(WebRtcSessionTest, ReceiveNoDtlsOfferCreateAnswer) {
1251 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
1252 InitWithDtls();
1253 cricket::MediaSessionOptions options;
1254 options.has_video = true;
1255 JsepSessionDescription* offer = CreateRemoteOffer(
1256 options, cricket::SEC_REQUIRED);
1257 ASSERT_TRUE(offer != NULL);
1258 VerifyFingerprintStatus(offer->description(), false);
1259
1260 // SetRemoteDescription will take the ownership of
1261 // the offer.
1262 SetRemoteDescriptionWithoutError(offer);
1263
1264 // Verify that we don't get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001265 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001266 ASSERT_TRUE(answer != NULL);
1267 VerifyFingerprintStatus(answer->description(), false);
1268
1269 // Now set the local description.
1270 SetLocalDescriptionWithoutError(answer);
1271}
1272
1273TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001274 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 mediastream_signaling_.SendNothing();
1276 // SetLocalDescription take ownership of offer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001277 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278 SetLocalDescriptionWithoutError(offer);
1279
1280 // SetLocalDescription take ownership of offer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001281 SessionDescriptionInterface* offer2 = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001282 SetLocalDescriptionWithoutError(offer2);
1283}
1284
1285TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001286 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001287 mediastream_signaling_.SendNothing();
1288 // SetLocalDescription take ownership of offer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001289 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 SetRemoteDescriptionWithoutError(offer);
1291
wu@webrtc.org91053e72013-08-10 07:18:04 +00001292 SessionDescriptionInterface* offer2 = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001293 SetRemoteDescriptionWithoutError(offer2);
1294}
1295
1296TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001297 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001298 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001299 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 SetLocalDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001301 offer = CreateOffer(NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001302 SetRemoteDescriptionOfferExpectError(
1303 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304}
1305
1306TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001307 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001309 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001311 offer = CreateOffer(NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001312 SetLocalDescriptionOfferExpectError(
1313 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314}
1315
1316TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001317 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001318 mediastream_signaling_.SendNothing();
1319 SessionDescriptionInterface* offer = CreateRemoteOffer();
1320 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1321
1322 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001323 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1325 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1326
1327 mediastream_signaling_.SendAudioVideoStream1();
1328 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001329 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1331
1332 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1333
1334 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001335 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001336 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1337}
1338
1339TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001340 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001341 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001342 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1344
1345 JsepSessionDescription* pranswer =
1346 CreateRemoteAnswer(session_->local_description());
1347 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1348
1349 SetRemoteDescriptionExpectState(pranswer,
1350 BaseSession::STATE_RECEIVEDPRACCEPT);
1351
1352 mediastream_signaling_.SendAudioVideoStream1();
1353 JsepSessionDescription* pranswer2 =
1354 CreateRemoteAnswer(session_->local_description());
1355 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1356
1357 SetRemoteDescriptionExpectState(pranswer2,
1358 BaseSession::STATE_RECEIVEDPRACCEPT);
1359
1360 mediastream_signaling_.SendAudioVideoStream2();
1361 SessionDescriptionInterface* answer =
1362 CreateRemoteAnswer(session_->local_description());
1363 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1364}
1365
1366TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001367 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001368 mediastream_signaling_.SendNothing();
1369 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001370 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001371 SessionDescriptionInterface* answer =
1372 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001373 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1374 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001375}
1376
1377TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001378 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001379 mediastream_signaling_.SendNothing();
1380 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001381 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001382 SessionDescriptionInterface* answer =
1383 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001384 SetRemoteDescriptionAnswerExpectError(
1385 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001386}
1387
1388TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001389 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001390 mediastream_signaling_.SendAudioVideoStream1();
1391
1392 cricket::Candidate candidate;
1393 candidate.set_component(1);
1394 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1395
1396 // Fail since we have not set a offer description.
1397 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1398
wu@webrtc.org91053e72013-08-10 07:18:04 +00001399 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001400 SetLocalDescriptionWithoutError(offer);
1401 // Candidate should be allowed to add before remote description.
1402 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1403 candidate.set_component(2);
1404 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1405 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1406
1407 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1408 session_->local_description());
1409 SetRemoteDescriptionWithoutError(answer);
1410
1411 // Verifying the candidates are copied properly from internal vector.
1412 const SessionDescriptionInterface* remote_desc =
1413 session_->remote_description();
1414 ASSERT_TRUE(remote_desc != NULL);
1415 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1416 const IceCandidateCollection* candidates =
1417 remote_desc->candidates(kMediaContentIndex0);
1418 ASSERT_EQ(2u, candidates->count());
1419 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1420 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1421 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1422 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1423
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001424 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1425 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 candidate.set_component(2);
1427 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1428 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001429 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430
1431 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1432 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1433}
1434
1435// Test that a remote candidate is added to the remote session description and
1436// that it is retained if the remote session description is changed.
1437TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001438 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 cricket::Candidate candidate1;
1440 candidate1.set_component(1);
1441 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1442 candidate1);
1443 mediastream_signaling_.SendAudioVideoStream1();
1444 CreateAndSetRemoteOfferAndLocalAnswer();
1445
1446 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1447 const SessionDescriptionInterface* remote_desc =
1448 session_->remote_description();
1449 ASSERT_TRUE(remote_desc != NULL);
1450 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1451 const IceCandidateCollection* candidates =
1452 remote_desc->candidates(kMediaContentIndex0);
1453 ASSERT_EQ(1u, candidates->count());
1454 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1455
1456 // Update the RemoteSessionDescription with a new session description and
1457 // a candidate and check that the new remote session description contains both
1458 // candidates.
1459 SessionDescriptionInterface* offer = CreateRemoteOffer();
1460 cricket::Candidate candidate2;
1461 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1462 candidate2);
1463 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1464 SetRemoteDescriptionWithoutError(offer);
1465
1466 remote_desc = session_->remote_description();
1467 ASSERT_TRUE(remote_desc != NULL);
1468 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1469 candidates = remote_desc->candidates(kMediaContentIndex0);
1470 ASSERT_EQ(2u, candidates->count());
1471 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1472 // Username and password have be updated with the TransportInfo of the
1473 // SessionDescription, won't be equal to the original one.
1474 candidate2.set_username(candidates->at(0)->candidate().username());
1475 candidate2.set_password(candidates->at(0)->candidate().password());
1476 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1477 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1478 // No need to verify the username and password.
1479 candidate1.set_username(candidates->at(1)->candidate().username());
1480 candidate1.set_password(candidates->at(1)->candidate().password());
1481 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1482
1483 // Test that the candidate is ignored if we can add the same candidate again.
1484 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1485}
1486
1487// Test that local candidates are added to the local session description and
1488// that they are retained if the local session description is changed.
1489TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001490 AddInterface(talk_base::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001491 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001492 mediastream_signaling_.SendAudioVideoStream1();
1493 CreateAndSetRemoteOfferAndLocalAnswer();
1494
1495 const SessionDescriptionInterface* local_desc = session_->local_description();
1496 const IceCandidateCollection* candidates =
1497 local_desc->candidates(kMediaContentIndex0);
1498 ASSERT_TRUE(candidates != NULL);
1499 EXPECT_EQ(0u, candidates->count());
1500
1501 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1502
1503 local_desc = session_->local_description();
1504 candidates = local_desc->candidates(kMediaContentIndex0);
1505 ASSERT_TRUE(candidates != NULL);
1506 EXPECT_LT(0u, candidates->count());
1507 candidates = local_desc->candidates(1);
1508 ASSERT_TRUE(candidates != NULL);
1509 EXPECT_LT(0u, candidates->count());
1510
1511 // Update the session descriptions.
1512 mediastream_signaling_.SendAudioVideoStream1();
1513 CreateAndSetRemoteOfferAndLocalAnswer();
1514
1515 local_desc = session_->local_description();
1516 candidates = local_desc->candidates(kMediaContentIndex0);
1517 ASSERT_TRUE(candidates != NULL);
1518 EXPECT_LT(0u, candidates->count());
1519 candidates = local_desc->candidates(1);
1520 ASSERT_TRUE(candidates != NULL);
1521 EXPECT_LT(0u, candidates->count());
1522}
1523
1524// Test that we can set a remote session description with remote candidates.
1525TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001526 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527
1528 cricket::Candidate candidate1;
1529 candidate1.set_component(1);
1530 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
1531 candidate1);
1532 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001533 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001534
1535 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
1536 SetRemoteDescriptionWithoutError(offer);
1537
1538 const SessionDescriptionInterface* remote_desc =
1539 session_->remote_description();
1540 ASSERT_TRUE(remote_desc != NULL);
1541 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1542 const IceCandidateCollection* candidates =
1543 remote_desc->candidates(kMediaContentIndex0);
1544 ASSERT_EQ(1u, candidates->count());
1545 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1546
wu@webrtc.org91053e72013-08-10 07:18:04 +00001547 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001548 SetLocalDescriptionWithoutError(answer);
1549}
1550
1551// Test that offers and answers contains ice candidates when Ice candidates have
1552// been gathered.
1553TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001554 AddInterface(talk_base::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001555 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556 mediastream_signaling_.SendAudioVideoStream1();
1557 // Ice is started but candidates are not provided until SetLocalDescription
1558 // is called.
1559 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1560 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1561 CreateAndSetRemoteOfferAndLocalAnswer();
1562 // Wait until at least one local candidate has been collected.
1563 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
1564 kIceCandidatesTimeout);
1565 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
1566 kIceCandidatesTimeout);
1567
1568 talk_base::scoped_ptr<SessionDescriptionInterface> local_offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001569 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
1571 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
1572 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
1573 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
1574
1575 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
1576 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001577 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
1579 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
1580 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
1581 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
1582 SetLocalDescriptionWithoutError(answer);
1583}
1584
1585// Verifies TransportProxy and media channels are created with content names
1586// present in the SessionDescription.
1587TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001588 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 mediastream_signaling_.SendAudioVideoStream1();
1590 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001591 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592
1593 // CreateOffer creates session description with the content names "audio" and
1594 // "video". Goal is to modify these content names and verify transport channel
1595 // proxy in the BaseSession, as proxies are created with the content names
1596 // present in SDP.
1597 std::string sdp;
1598 EXPECT_TRUE(offer->ToString(&sdp));
1599 const std::string kAudioMid = "a=mid:audio";
1600 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
1601 const std::string kVideoMid = "a=mid:video";
1602 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
1603
1604 // Replacing |audio| with |audio_content_name|.
1605 talk_base::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
1606 kAudioMidReplaceStr.c_str(),
1607 kAudioMidReplaceStr.length(),
1608 &sdp);
1609 // Replacing |video| with |video_content_name|.
1610 talk_base::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
1611 kVideoMidReplaceStr.c_str(),
1612 kVideoMidReplaceStr.length(),
1613 &sdp);
1614
1615 SessionDescriptionInterface* modified_offer =
1616 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
1617
1618 SetRemoteDescriptionWithoutError(modified_offer);
1619
1620 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00001621 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622 SetLocalDescriptionWithoutError(answer);
1623
1624 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
1625 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
1626 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
1627 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
1628}
1629
1630// Test that an offer contains the correct media content descriptions based on
1631// the send streams when no constraints have been set.
1632TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001633 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001635 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 ASSERT_TRUE(offer != NULL);
1637 const cricket::ContentInfo* content =
1638 cricket::GetFirstAudioContent(offer->description());
1639 EXPECT_TRUE(content != NULL);
1640 content = cricket::GetFirstVideoContent(offer->description());
1641 EXPECT_TRUE(content == NULL);
1642}
1643
1644// Test that an offer contains the correct media content descriptions based on
1645// the send streams when no constraints have been set.
1646TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001647 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648 // Test Audio only offer.
1649 mediastream_signaling_.UseOptionsAudioOnly();
1650 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001651 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 const cricket::ContentInfo* content =
1653 cricket::GetFirstAudioContent(offer->description());
1654 EXPECT_TRUE(content != NULL);
1655 content = cricket::GetFirstVideoContent(offer->description());
1656 EXPECT_TRUE(content == NULL);
1657
1658 // Test Audio / Video offer.
1659 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001660 offer.reset(CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661 content = cricket::GetFirstAudioContent(offer->description());
1662 EXPECT_TRUE(content != NULL);
1663 content = cricket::GetFirstVideoContent(offer->description());
1664 EXPECT_TRUE(content != NULL);
1665}
1666
1667// Test that an offer contains no media content descriptions if
1668// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
1669TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001670 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001671 webrtc::FakeConstraints constraints_no_receive;
1672 constraints_no_receive.SetMandatoryReceiveAudio(false);
1673 constraints_no_receive.SetMandatoryReceiveVideo(false);
1674
1675 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001676 CreateOffer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677 ASSERT_TRUE(offer != NULL);
1678 const cricket::ContentInfo* content =
1679 cricket::GetFirstAudioContent(offer->description());
1680 EXPECT_TRUE(content == NULL);
1681 content = cricket::GetFirstVideoContent(offer->description());
1682 EXPECT_TRUE(content == NULL);
1683}
1684
1685// Test that an offer contains only audio media content descriptions if
1686// kOfferToReceiveAudio constraints are set to true.
1687TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001688 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 webrtc::FakeConstraints constraints_audio_only;
1690 constraints_audio_only.SetMandatoryReceiveAudio(true);
1691 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001692 CreateOffer(&constraints_audio_only));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693
1694 const cricket::ContentInfo* content =
1695 cricket::GetFirstAudioContent(offer->description());
1696 EXPECT_TRUE(content != NULL);
1697 content = cricket::GetFirstVideoContent(offer->description());
1698 EXPECT_TRUE(content == NULL);
1699}
1700
1701// Test that an offer contains audio and video media content descriptions if
1702// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
1703TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001704 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001705 // Test Audio / Video offer.
1706 webrtc::FakeConstraints constraints_audio_video;
1707 constraints_audio_video.SetMandatoryReceiveAudio(true);
1708 constraints_audio_video.SetMandatoryReceiveVideo(true);
1709 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001710 CreateOffer(&constraints_audio_video));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711 const cricket::ContentInfo* content =
1712 cricket::GetFirstAudioContent(offer->description());
1713
1714 EXPECT_TRUE(content != NULL);
1715 content = cricket::GetFirstVideoContent(offer->description());
1716 EXPECT_TRUE(content != NULL);
1717
1718 // TODO(perkj): Should the direction be set to SEND_ONLY if
1719 // The constraints is set to not receive audio or video but a track is added?
1720}
1721
1722// Test that an answer can not be created if the last remote description is not
1723// an offer.
1724TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001725 Init(NULL);
1726 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727 SetLocalDescriptionWithoutError(offer);
1728 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
1729 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001730 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731}
1732
1733// Test that an answer contains the correct media content descriptions when no
1734// constraints have been set.
1735TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001736 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 // Create a remote offer with audio and video content.
1738 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1739 SetRemoteDescriptionWithoutError(offer.release());
1740 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001741 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742 const cricket::ContentInfo* content =
1743 cricket::GetFirstAudioContent(answer->description());
1744 ASSERT_TRUE(content != NULL);
1745 EXPECT_FALSE(content->rejected);
1746
1747 content = cricket::GetFirstVideoContent(answer->description());
1748 ASSERT_TRUE(content != NULL);
1749 EXPECT_FALSE(content->rejected);
1750}
1751
1752// Test that an answer contains the correct media content descriptions when no
1753// constraints have been set and the offer only contain audio.
1754TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001755 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 // Create a remote offer with audio only.
1757 cricket::MediaSessionOptions options;
1758 options.has_audio = true;
1759 options.has_video = false;
1760 talk_base::scoped_ptr<JsepSessionDescription> offer(
1761 CreateRemoteOffer(options));
1762 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
1763 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
1764
1765 SetRemoteDescriptionWithoutError(offer.release());
1766 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001767 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 const cricket::ContentInfo* content =
1769 cricket::GetFirstAudioContent(answer->description());
1770 ASSERT_TRUE(content != NULL);
1771 EXPECT_FALSE(content->rejected);
1772
1773 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
1774}
1775
1776// Test that an answer contains the correct media content descriptions when no
1777// constraints have been set.
1778TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001779 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780 // Create a remote offer with audio and video content.
1781 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1782 SetRemoteDescriptionWithoutError(offer.release());
1783 // Test with a stream with tracks.
1784 mediastream_signaling_.SendAudioVideoStream1();
1785 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001786 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 const cricket::ContentInfo* content =
1788 cricket::GetFirstAudioContent(answer->description());
1789 ASSERT_TRUE(content != NULL);
1790 EXPECT_FALSE(content->rejected);
1791
1792 content = cricket::GetFirstVideoContent(answer->description());
1793 ASSERT_TRUE(content != NULL);
1794 EXPECT_FALSE(content->rejected);
1795}
1796
1797// Test that an answer contains the correct media content descriptions when
1798// constraints have been set but no stream is sent.
1799TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001800 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 // Create a remote offer with audio and video content.
1802 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1803 SetRemoteDescriptionWithoutError(offer.release());
1804
1805 webrtc::FakeConstraints constraints_no_receive;
1806 constraints_no_receive.SetMandatoryReceiveAudio(false);
1807 constraints_no_receive.SetMandatoryReceiveVideo(false);
1808
1809 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001810 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001811 const cricket::ContentInfo* content =
1812 cricket::GetFirstAudioContent(answer->description());
1813 ASSERT_TRUE(content != NULL);
1814 EXPECT_TRUE(content->rejected);
1815
1816 content = cricket::GetFirstVideoContent(answer->description());
1817 ASSERT_TRUE(content != NULL);
1818 EXPECT_TRUE(content->rejected);
1819}
1820
1821// Test that an answer contains the correct media content descriptions when
1822// constraints have been set and streams are sent.
1823TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001824 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 // Create a remote offer with audio and video content.
1826 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1827 SetRemoteDescriptionWithoutError(offer.release());
1828
1829 webrtc::FakeConstraints constraints_no_receive;
1830 constraints_no_receive.SetMandatoryReceiveAudio(false);
1831 constraints_no_receive.SetMandatoryReceiveVideo(false);
1832
1833 // Test with a stream with tracks.
1834 mediastream_signaling_.SendAudioVideoStream1();
1835 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001836 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837
1838 // TODO(perkj): Should the direction be set to SEND_ONLY?
1839 const cricket::ContentInfo* content =
1840 cricket::GetFirstAudioContent(answer->description());
1841 ASSERT_TRUE(content != NULL);
1842 EXPECT_FALSE(content->rejected);
1843
1844 // TODO(perkj): Should the direction be set to SEND_ONLY?
1845 content = cricket::GetFirstVideoContent(answer->description());
1846 ASSERT_TRUE(content != NULL);
1847 EXPECT_FALSE(content->rejected);
1848}
1849
1850TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
1851 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001852 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853 webrtc::FakeConstraints constraints;
1854 constraints.SetOptionalVAD(false);
1855 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001856 CreateOffer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 const cricket::ContentInfo* content =
1858 cricket::GetFirstAudioContent(offer->description());
1859 EXPECT_TRUE(content != NULL);
1860 EXPECT_TRUE(VerifyNoCNCodecs(content));
1861}
1862
1863TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
1864 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001865 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001866 // Create a remote offer with audio and video content.
1867 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1868 SetRemoteDescriptionWithoutError(offer.release());
1869
1870 webrtc::FakeConstraints constraints;
1871 constraints.SetOptionalVAD(false);
1872 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001873 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001874 const cricket::ContentInfo* content =
1875 cricket::GetFirstAudioContent(answer->description());
1876 ASSERT_TRUE(content != NULL);
1877 EXPECT_TRUE(VerifyNoCNCodecs(content));
1878}
1879
1880// This test verifies the call setup when remote answer with audio only and
1881// later updates with video.
1882TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001883 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
1885 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
1886
1887 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001888 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001889
1890 cricket::MediaSessionOptions options;
1891 options.has_video = false;
1892 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
1893
1894 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1895 // and answer;
1896 SetLocalDescriptionWithoutError(offer);
1897 SetRemoteDescriptionWithoutError(answer);
1898
1899 video_channel_ = media_engine_->GetVideoChannel(0);
1900 voice_channel_ = media_engine_->GetVoiceChannel(0);
1901
1902 ASSERT_TRUE(video_channel_ == NULL);
1903
1904 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
1905 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1906 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
1907
1908 // Let the remote end update the session descriptions, with Audio and Video.
1909 mediastream_signaling_.SendAudioVideoStream2();
1910 CreateAndSetRemoteOfferAndLocalAnswer();
1911
1912 video_channel_ = media_engine_->GetVideoChannel(0);
1913 voice_channel_ = media_engine_->GetVoiceChannel(0);
1914
1915 ASSERT_TRUE(video_channel_ != NULL);
1916 ASSERT_TRUE(voice_channel_ != NULL);
1917
1918 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1919 ASSERT_EQ(1u, video_channel_->send_streams().size());
1920 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
1921 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
1922 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1923 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1924 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
1925 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
1926
1927 // Change session back to audio only.
1928 mediastream_signaling_.UseOptionsAudioOnly();
1929 CreateAndSetRemoteOfferAndLocalAnswer();
1930
1931 EXPECT_EQ(0u, video_channel_->recv_streams().size());
1932 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1933 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
1934 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1935 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
1936}
1937
1938// This test verifies the call setup when remote answer with video only and
1939// later updates with audio.
1940TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001941 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001942 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
1943 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
1944 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001945 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946
1947 cricket::MediaSessionOptions options;
1948 options.has_audio = false;
1949 options.has_video = true;
1950 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1951 offer, options, cricket::SEC_ENABLED);
1952
1953 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1954 // and answer.
1955 SetLocalDescriptionWithoutError(offer);
1956 SetRemoteDescriptionWithoutError(answer);
1957
1958 video_channel_ = media_engine_->GetVideoChannel(0);
1959 voice_channel_ = media_engine_->GetVoiceChannel(0);
1960
1961 ASSERT_TRUE(voice_channel_ == NULL);
1962 ASSERT_TRUE(video_channel_ != NULL);
1963
1964 EXPECT_EQ(0u, video_channel_->recv_streams().size());
1965 ASSERT_EQ(1u, video_channel_->send_streams().size());
1966 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
1967
1968 // Update the session descriptions, with Audio and Video.
1969 mediastream_signaling_.SendAudioVideoStream2();
1970 CreateAndSetRemoteOfferAndLocalAnswer();
1971
1972 voice_channel_ = media_engine_->GetVoiceChannel(0);
1973 ASSERT_TRUE(voice_channel_ != NULL);
1974
1975 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1976 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1977 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
1978 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
1979
1980 // Change session back to video only.
1981 mediastream_signaling_.UseOptionsVideoOnly();
1982 CreateAndSetRemoteOfferAndLocalAnswer();
1983
1984 video_channel_ = media_engine_->GetVideoChannel(0);
1985 voice_channel_ = media_engine_->GetVoiceChannel(0);
1986
1987 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1988 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
1989 ASSERT_EQ(1u, video_channel_->send_streams().size());
1990 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
1991}
1992
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001993TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001994 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995 mediastream_signaling_.SendAudioVideoStream1();
1996 scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001997 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 VerifyCryptoParams(offer->description());
1999 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002000 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 VerifyCryptoParams(answer->description());
2002}
2003
2004TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002005 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002006 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002007 mediastream_signaling_.SendAudioVideoStream1();
2008 scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002009 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010 VerifyNoCryptoParams(offer->description(), false);
2011}
2012
2013TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002014 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015 VerifyAnswerFromNonCryptoOffer();
2016}
2017
2018TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002019 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 VerifyAnswerFromCryptoOffer();
2021}
2022
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002023// This test verifies that setLocalDescription fails if
2024// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2025TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
2026 Init(NULL);
2027 mediastream_signaling_.SendAudioVideoStream1();
2028 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
2029 std::string sdp;
2030 RemoveIceUfragPwdLines(offer.get(), &sdp);
2031 SessionDescriptionInterface* modified_offer =
2032 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002033 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002034}
2035
2036// This test verifies that setRemoteDescription fails if
2037// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2038TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
2039 Init(NULL);
2040 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2041 std::string sdp;
2042 RemoveIceUfragPwdLines(offer.get(), &sdp);
2043 SessionDescriptionInterface* modified_offer =
2044 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002045 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002046}
2047
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) {
2049 // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in
2050 // local description is removed by the application, BUNDLE flag should be
2051 // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc.
wu@webrtc.org91053e72013-08-10 07:18:04 +00002052 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) ==
2054 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
2055 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002056 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057 cricket::SessionDescription* offer_copy =
2058 offer->description()->Copy();
2059 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2060 JsepSessionDescription* modified_offer =
2061 new JsepSessionDescription(JsepSessionDescription::kOffer);
2062 modified_offer->Initialize(offer_copy, "1", "1");
2063
2064 SetLocalDescriptionWithoutError(modified_offer);
2065 EXPECT_FALSE(allocator_.flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE);
2066}
2067
2068TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002069 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070 mediastream_signaling_.SendAudioVideoStream1();
2071 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) ==
2072 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
2073 FakeConstraints constraints;
2074 constraints.SetMandatoryUseRtpMux(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002075 SessionDescriptionInterface* offer = CreateOffer(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002076 SetLocalDescriptionWithoutError(offer);
2077 mediastream_signaling_.SendAudioVideoStream2();
2078 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
2079 CreateRemoteAnswer(session_->local_description()));
2080 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2081 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2082 JsepSessionDescription* modified_answer =
2083 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2084 modified_answer->Initialize(answer_copy, "1", "1");
2085 SetRemoteDescriptionWithoutError(modified_answer);
2086 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) ==
2087 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
2088
2089 video_channel_ = media_engine_->GetVideoChannel(0);
2090 voice_channel_ = media_engine_->GetVoiceChannel(0);
2091
2092 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2093 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
2094
2095 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2096 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
2097
2098 ASSERT_EQ(1u, video_channel_->send_streams().size());
2099 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
2100 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2101 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
2102}
2103
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002104// This test verifies that SetLocalDescription and SetRemoteDescription fails
2105// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2106TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002107 WebRtcSessionTest::Init(NULL);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002108 mediastream_signaling_.SendAudioVideoStream1();
2109 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) ==
2110 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
2111 FakeConstraints constraints;
2112 constraints.SetMandatoryUseRtpMux(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002113 SessionDescriptionInterface* offer = CreateOffer(&constraints);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002114 std::string offer_str;
2115 offer->ToString(&offer_str);
2116 // Disable rtcp-mux
2117 const std::string rtcp_mux = "rtcp-mux";
2118 const std::string xrtcp_mux = "xrtcp-mux";
2119 talk_base::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
2120 xrtcp_mux.c_str(), xrtcp_mux.length(),
2121 &offer_str);
2122 JsepSessionDescription *local_offer =
2123 new JsepSessionDescription(JsepSessionDescription::kOffer);
2124 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002125 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002126 JsepSessionDescription *remote_offer =
2127 new JsepSessionDescription(JsepSessionDescription::kOffer);
2128 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002129 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002130 // Trying unmodified SDP.
2131 SetLocalDescriptionWithoutError(offer);
2132}
2133
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134TEST_F(WebRtcSessionTest, SetAudioPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002135 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136 mediastream_signaling_.SendAudioVideoStream1();
2137 CreateAndSetRemoteOfferAndLocalAnswer();
2138 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2139 ASSERT_TRUE(channel != NULL);
2140 ASSERT_EQ(1u, channel->recv_streams().size());
2141 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2142 double left_vol, right_vol;
2143 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2144 EXPECT_EQ(1, left_vol);
2145 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002146 talk_base::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
2147 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2149 EXPECT_EQ(0, left_vol);
2150 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002151 EXPECT_EQ(0, renderer->channel_id());
2152 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2154 EXPECT_EQ(1, left_vol);
2155 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002156 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157}
2158
2159TEST_F(WebRtcSessionTest, SetAudioSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002160 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161 mediastream_signaling_.SendAudioVideoStream1();
2162 CreateAndSetRemoteOfferAndLocalAnswer();
2163 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2164 ASSERT_TRUE(channel != NULL);
2165 ASSERT_EQ(1u, channel->send_streams().size());
2166 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2167 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2168
2169 cricket::AudioOptions options;
2170 options.echo_cancellation.Set(true);
2171
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002172 talk_base::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
2173 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002174 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2175 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002176 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002178 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2180 bool value;
2181 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2182 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002183 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002184}
2185
2186TEST_F(WebRtcSessionTest, SetVideoPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002187 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002188 mediastream_signaling_.SendAudioVideoStream1();
2189 CreateAndSetRemoteOfferAndLocalAnswer();
2190 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2191 ASSERT_TRUE(channel != NULL);
2192 ASSERT_LT(0u, channel->renderers().size());
2193 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2194 ASSERT_EQ(1u, channel->recv_streams().size());
2195 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2196 cricket::FakeVideoRenderer renderer;
2197 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2198 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2199 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2200 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2201}
2202
2203TEST_F(WebRtcSessionTest, SetVideoSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002204 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002205 mediastream_signaling_.SendAudioVideoStream1();
2206 CreateAndSetRemoteOfferAndLocalAnswer();
2207 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2208 ASSERT_TRUE(channel != NULL);
2209 ASSERT_EQ(1u, channel->send_streams().size());
2210 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2211 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2212 cricket::VideoOptions* options = NULL;
2213 session_->SetVideoSend(send_ssrc, false, options);
2214 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2215 session_->SetVideoSend(send_ssrc, true, options);
2216 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2217}
2218
2219TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2220 TestCanInsertDtmf(false);
2221}
2222
2223TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2224 TestCanInsertDtmf(true);
2225}
2226
2227TEST_F(WebRtcSessionTest, InsertDtmf) {
2228 // Setup
wu@webrtc.org91053e72013-08-10 07:18:04 +00002229 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230 mediastream_signaling_.SendAudioVideoStream1();
2231 CreateAndSetRemoteOfferAndLocalAnswer();
2232 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2233 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2234
2235 // Insert DTMF
2236 const int expected_flags = DF_SEND;
2237 const int expected_duration = 90;
2238 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2239 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2240 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2241
2242 // Verify
2243 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2244 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2245 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2246 expected_duration, expected_flags));
2247 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2248 expected_duration, expected_flags));
2249 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2250 expected_duration, expected_flags));
2251}
2252
2253// This test verifies the |initiator| flag when session initiates the call.
2254TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002255 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256 EXPECT_FALSE(session_->initiator());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002257 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002258 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2259 SetLocalDescriptionWithoutError(offer);
2260 EXPECT_TRUE(session_->initiator());
2261 SetRemoteDescriptionWithoutError(answer);
2262 EXPECT_TRUE(session_->initiator());
2263}
2264
2265// This test verifies the |initiator| flag when session receives the call.
2266TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002267 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268 EXPECT_FALSE(session_->initiator());
2269 SessionDescriptionInterface* offer = CreateRemoteOffer();
2270 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002271 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272
2273 EXPECT_FALSE(session_->initiator());
2274 SetLocalDescriptionWithoutError(answer);
2275 EXPECT_FALSE(session_->initiator());
2276}
2277
2278// This test verifies the ice protocol type at initiator of the call
2279// if |a=ice-options:google-ice| is present in answer.
2280TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002281 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002282 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002283 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org723d6832013-07-12 16:04:50 +00002284 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002285 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286 SetLocalDescriptionWithoutError(offer);
2287 std::string sdp;
2288 EXPECT_TRUE(answer->ToString(&sdp));
2289 // Adding ice-options to the session level.
2290 InjectAfter("t=0 0\r\n",
2291 "a=ice-options:google-ice\r\n",
2292 &sdp);
2293 SessionDescriptionInterface* answer_with_gice =
2294 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2295 SetRemoteDescriptionWithoutError(answer_with_gice);
2296 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2297 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2298}
2299
2300// This test verifies the ice protocol type at initiator of the call
2301// if ICE RFC5245 is supported in answer.
2302TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002303 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002304 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002305 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2307 SetLocalDescriptionWithoutError(offer);
2308
2309 SetRemoteDescriptionWithoutError(answer);
2310 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2311 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2312}
2313
2314// This test verifies the ice protocol type at receiver side of the call if
2315// receiver decides to use google-ice.
2316TEST_F(WebRtcSessionTest, TestReceiverGIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002317 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002319 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002320 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.org723d6832013-07-12 16:04:50 +00002321 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002322 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323 std::string sdp;
2324 EXPECT_TRUE(answer->ToString(&sdp));
2325 // Adding ice-options to the session level.
2326 InjectAfter("t=0 0\r\n",
2327 "a=ice-options:google-ice\r\n",
2328 &sdp);
2329 SessionDescriptionInterface* answer_with_gice =
2330 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2331 SetLocalDescriptionWithoutError(answer_with_gice);
2332 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2333 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2334}
2335
2336// This test verifies the ice protocol type at receiver side of the call if
2337// receiver decides to use ice RFC 5245.
2338TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002339 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002340 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002341 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002343 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002344 SetLocalDescriptionWithoutError(answer);
2345 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2346 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2347}
2348
2349// This test verifies the session state when ICE RFC5245 in offer and
2350// ICE google-ice in answer.
2351TEST_F(WebRtcSessionTest, TestIceOfferGIceOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002352 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353 mediastream_signaling_.SendAudioVideoStream1();
2354 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002355 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002356 std::string offer_str;
2357 offer->ToString(&offer_str);
2358 // Disable google-ice
2359 const std::string gice_option = "google-ice";
2360 const std::string xgoogle_xice = "xgoogle-xice";
2361 talk_base::replace_substrs(gice_option.c_str(), gice_option.length(),
2362 xgoogle_xice.c_str(), xgoogle_xice.length(),
2363 &offer_str);
2364 JsepSessionDescription *ice_only_offer =
2365 new JsepSessionDescription(JsepSessionDescription::kOffer);
2366 EXPECT_TRUE((ice_only_offer)->Initialize(offer_str, NULL));
2367 SetLocalDescriptionWithoutError(ice_only_offer);
2368 std::string original_offer_sdp;
2369 EXPECT_TRUE(offer->ToString(&original_offer_sdp));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002370 SessionDescriptionInterface* pranswer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371 CreateSessionDescription(JsepSessionDescription::kPrAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002372 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002373 SetRemoteDescriptionPranswerExpectError(kPushDownTDFailed,
2374 pranswer_with_gice);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002375 SessionDescriptionInterface* answer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376 CreateSessionDescription(JsepSessionDescription::kAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002377 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002378 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed,
2379 answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380}
2381
2382// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2383TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002384 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002385 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002386 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387 SetLocalDescriptionWithoutError(offer);
2388 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
2389 CreateRemoteAnswer(session_->local_description()));
2390
2391 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2392 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002393 JsepSessionDescription* modified_answer =
2394 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002395
2396 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2397 answer->session_id(),
2398 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002399 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400
2401 // Modifying content names.
2402 std::string sdp;
2403 EXPECT_TRUE(answer->ToString(&sdp));
2404 const std::string kAudioMid = "a=mid:audio";
2405 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2406
2407 // Replacing |audio| with |audio_content_name|.
2408 talk_base::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
2409 kAudioMidReplaceStr.c_str(),
2410 kAudioMidReplaceStr.length(),
2411 &sdp);
2412
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002413 SessionDescriptionInterface* modified_answer1 =
2414 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002415 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416
2417 SetRemoteDescriptionWithoutError(answer.release());
2418}
2419
2420// Verifying remote offer and local answer have matching m-lines as per
2421// RFC 3264.
2422TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002423 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424 mediastream_signaling_.SendAudioVideoStream1();
2425 SessionDescriptionInterface* offer = CreateRemoteOffer();
2426 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002427 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002428
2429 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2430 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002431 JsepSessionDescription* modified_answer =
2432 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433
2434 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2435 answer->session_id(),
2436 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002437 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002438 SetLocalDescriptionWithoutError(answer);
2439}
2440
2441// This test verifies that WebRtcSession does not start candidate allocation
2442// before SetLocalDescription is called.
2443TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002444 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445 mediastream_signaling_.SendAudioVideoStream1();
2446 SessionDescriptionInterface* offer = CreateRemoteOffer();
2447 cricket::Candidate candidate;
2448 candidate.set_component(1);
2449 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2450 candidate);
2451 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2452 cricket::Candidate candidate1;
2453 candidate1.set_component(1);
2454 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2455 candidate1);
2456 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2457 SetRemoteDescriptionWithoutError(offer);
2458 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
2459 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
2460
2461 // Pump for 1 second and verify that no candidates are generated.
2462 talk_base::Thread::Current()->ProcessMessages(1000);
2463 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
2464 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
2465
wu@webrtc.org91053e72013-08-10 07:18:04 +00002466 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002467 SetLocalDescriptionWithoutError(answer);
2468 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
2469 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
2470 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2471}
2472
2473// This test verifies that crypto parameter is updated in local session
2474// description as per security policy set in MediaSessionDescriptionFactory.
2475TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002476 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477 mediastream_signaling_.SendAudioVideoStream1();
2478 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002479 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480
2481 // Making sure SetLocalDescription correctly sets crypto value in
2482 // SessionDescription object after de-serialization of sdp string. The value
2483 // will be set as per MediaSessionDescriptionFactory.
2484 std::string offer_str;
2485 offer->ToString(&offer_str);
2486 SessionDescriptionInterface* jsep_offer_str =
2487 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2488 SetLocalDescriptionWithoutError(jsep_offer_str);
2489 EXPECT_TRUE(session_->voice_channel()->secure_required());
2490 EXPECT_TRUE(session_->video_channel()->secure_required());
2491}
2492
2493// This test verifies the crypto parameter when security is disabled.
2494TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002495 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002496 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002498 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002499 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002500
2501 // Making sure SetLocalDescription correctly sets crypto value in
2502 // SessionDescription object after de-serialization of sdp string. The value
2503 // will be set as per MediaSessionDescriptionFactory.
2504 std::string offer_str;
2505 offer->ToString(&offer_str);
2506 SessionDescriptionInterface *jsep_offer_str =
2507 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2508 SetLocalDescriptionWithoutError(jsep_offer_str);
2509 EXPECT_FALSE(session_->voice_channel()->secure_required());
2510 EXPECT_FALSE(session_->video_channel()->secure_required());
2511}
2512
2513// This test verifies that an answer contains new ufrag and password if an offer
2514// with new ufrag and password is received.
2515TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002516 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002517 cricket::MediaSessionOptions options;
2518 options.has_audio = true;
2519 options.has_video = true;
2520 talk_base::scoped_ptr<JsepSessionDescription> offer(
2521 CreateRemoteOffer(options));
2522 SetRemoteDescriptionWithoutError(offer.release());
2523
2524 mediastream_signaling_.SendAudioVideoStream1();
2525 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002526 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002527 SetLocalDescriptionWithoutError(answer.release());
2528
2529 // Receive an offer with new ufrag and password.
2530 options.transport_options.ice_restart = true;
2531 talk_base::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002532 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002533 SetRemoteDescriptionWithoutError(updated_offer1.release());
2534
2535 talk_base::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002536 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002537
2538 CompareIceUfragAndPassword(updated_answer1->description(),
2539 session_->local_description()->description(),
2540 false);
2541
2542 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002543}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544
wu@webrtc.org91053e72013-08-10 07:18:04 +00002545// This test verifies that an answer contains old ufrag and password if an offer
2546// with old ufrag and password is received.
2547TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
2548 Init(NULL);
2549 cricket::MediaSessionOptions options;
2550 options.has_audio = true;
2551 options.has_video = true;
2552 talk_base::scoped_ptr<JsepSessionDescription> offer(
2553 CreateRemoteOffer(options));
2554 SetRemoteDescriptionWithoutError(offer.release());
2555
2556 mediastream_signaling_.SendAudioVideoStream1();
2557 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
2558 CreateAnswer(NULL));
2559 SetLocalDescriptionWithoutError(answer.release());
2560
2561 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002562 options.transport_options.ice_restart = false;
2563 talk_base::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002564 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002565 SetRemoteDescriptionWithoutError(updated_offer2.release());
2566
2567 talk_base::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002568 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002569
2570 CompareIceUfragAndPassword(updated_answer2->description(),
2571 session_->local_description()->description(),
2572 true);
2573
2574 SetLocalDescriptionWithoutError(updated_answer2.release());
2575}
2576
2577TEST_F(WebRtcSessionTest, TestSessionContentError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002578 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002580 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581 const std::string session_id_orig = offer->session_id();
2582 const std::string session_version_orig = offer->session_version();
2583 SetLocalDescriptionWithoutError(offer);
2584
2585 video_channel_ = media_engine_->GetVideoChannel(0);
2586 video_channel_->set_fail_set_send_codecs(true);
2587
2588 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002589 SessionDescriptionInterface* answer =
2590 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002591 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002592}
2593
2594// Runs the loopback call test with BUNDLE and STUN disabled.
2595TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
2596 // Lets try with only UDP ports.
2597 allocator_.set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
2598 cricket::PORTALLOCATOR_DISABLE_TCP |
2599 cricket::PORTALLOCATOR_DISABLE_STUN |
2600 cricket::PORTALLOCATOR_DISABLE_RELAY);
2601 TestLoopbackCall();
2602}
2603
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002604TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002605 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002606 cricket::MediaSessionOptions options;
2607 options.has_audio = true;
2608 options.has_video = true;
2609
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002610 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
2611 std::string error_code_str = "ERROR_CONTENT";
2612 std::string error_desc = "Fake session error description.";
2613 session_->SetError(error_code, error_desc);
2614
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002615 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
2616 SessionDescriptionInterface* answer =
2617 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002618
2619 std::string action;
2620 std::ostringstream session_error_msg;
2621 session_error_msg << kSessionError << error_code_str << ". ";
2622 session_error_msg << kSessionErrorDesc << error_desc << ".";
2623 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
2624 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002625}
2626
2627TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
2628 constraints_.reset(new FakeConstraints());
2629 constraints_->AddOptional(
2630 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002631 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002632
2633 SetLocalDescriptionWithDataChannel();
2634 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
2635}
2636
2637TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
2638 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2639
2640 constraints_.reset(new FakeConstraints());
2641 constraints_->AddOptional(
2642 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00002643 options_.disable_sctp_data_channels = false;
2644
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002645 InitWithDtls(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002646
2647 SetLocalDescriptionWithDataChannel();
2648 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
2649}
2650
wu@webrtc.org967bfff2013-09-19 05:49:50 +00002651TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
2652 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2653
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002654 InitWithDtls(false);
2655
2656 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
2657 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00002658 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
2659}
2660
2661TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
2662 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2663 SetFactoryDtlsSrtp();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00002664 InitWithDtls(false);
2665
2666 // Create remote offer with SCTP.
2667 cricket::MediaSessionOptions options;
2668 options.data_channel_type = cricket::DCT_SCTP;
2669 JsepSessionDescription* offer =
2670 CreateRemoteOffer(options, cricket::SEC_ENABLED);
2671 SetRemoteDescriptionWithoutError(offer);
2672
2673 // Verifies the answer contains SCTP.
2674 talk_base::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
2675 EXPECT_TRUE(answer != NULL);
2676 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
2677 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002678}
2679
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002680TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
2681 constraints_.reset(new FakeConstraints());
2682 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002683 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
2684 InitWithDtls(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002685
2686 SetLocalDescriptionWithDataChannel();
2687 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
2688}
2689
2690TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
2691 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2692
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002693 InitWithDtls(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002694
2695 SetLocalDescriptionWithDataChannel();
2696 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
2697}
wu@webrtc.org91053e72013-08-10 07:18:04 +00002698
wu@webrtc.org97077a32013-10-25 21:18:33 +00002699TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
2700 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2701 options_.disable_sctp_data_channels = true;
2702 InitWithDtls(false);
2703
2704 SetLocalDescriptionWithDataChannel();
2705 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
2706}
2707
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002708TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
2709 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2710 const int new_send_port = 9998;
2711 const int new_recv_port = 7775;
2712
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002713 InitWithDtls(false);
2714 SetFactoryDtlsSrtp();
2715
2716 // By default, don't actually add the codecs to desc_factory_; they don't
2717 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
2718 // let the session description get parsed. That'll get the proper codecs
2719 // into the stream.
2720 cricket::MediaSessionOptions options;
2721 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
2722 "stream1", new_send_port, options);
2723
2724 // SetRemoteDescription will take the ownership of the offer.
2725 SetRemoteDescriptionWithoutError(offer);
2726
2727 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
2728 new_recv_port, CreateAnswer(NULL));
2729 ASSERT_TRUE(answer != NULL);
2730
2731 // Now set the local description, which'll take ownership of the answer.
2732 SetLocalDescriptionWithoutError(answer);
2733
2734 // TEST PLAN: Set the port number to something new, set it in the SDP,
2735 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002736 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002737 dci.reliable = true;
2738 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
2739 talk_base::scoped_refptr<webrtc::DataChannel> dc =
2740 session_->CreateDataChannel("datachannel", &dci);
2741
2742 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
2743 int portnum = -1;
2744 ASSERT_TRUE(ch != NULL);
2745 ASSERT_EQ(1UL, ch->send_codecs().size());
2746 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
2747 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
2748 ch->send_codecs()[0].name.c_str()));
2749 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
2750 &portnum));
2751 EXPECT_EQ(new_send_port, portnum);
2752
2753 ASSERT_EQ(1UL, ch->recv_codecs().size());
2754 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
2755 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
2756 ch->recv_codecs()[0].name.c_str()));
2757 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
2758 &portnum));
2759 EXPECT_EQ(new_recv_port, portnum);
2760}
2761
wu@webrtc.org91053e72013-08-10 07:18:04 +00002762// Verifies that CreateOffer succeeds when CreateOffer is called before async
2763// identity generation is finished.
2764TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
2765 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00002766 InitWithDtls(false);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002767
2768 EXPECT_TRUE(session_->waiting_for_identity());
2769 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
2770 EXPECT_TRUE(offer != NULL);
2771}
2772
2773// Verifies that CreateAnswer succeeds when CreateOffer is called before async
2774// identity generation is finished.
2775TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
2776 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00002777 InitWithDtls(false);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002778
2779 cricket::MediaSessionOptions options;
2780 scoped_ptr<JsepSessionDescription> offer(
2781 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
2782 ASSERT_TRUE(offer.get() != NULL);
2783 SetRemoteDescriptionWithoutError(offer.release());
2784
2785 talk_base::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
2786 EXPECT_TRUE(answer != NULL);
2787}
2788
2789// Verifies that CreateOffer succeeds when CreateOffer is called after async
2790// identity generation is finished.
2791TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
2792 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00002793 InitWithDtls(false);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002794
2795 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
2796 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
2797 EXPECT_TRUE(offer != NULL);
2798}
2799
2800// Verifies that CreateOffer fails when CreateOffer is called after async
2801// identity generation fails.
2802TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
2803 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00002804 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002805
2806 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
2807 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
2808 EXPECT_TRUE(offer == NULL);
2809}
2810
2811// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
2812// before async identity generation is finished.
2813TEST_F(WebRtcSessionTest,
2814 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
2815 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2816 VerifyMultipleAsyncCreateDescription(
2817 true, CreateSessionDescriptionRequest::kOffer);
2818}
2819
2820// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
2821// before async identity generation fails.
2822TEST_F(WebRtcSessionTest,
2823 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
2824 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2825 VerifyMultipleAsyncCreateDescription(
2826 false, CreateSessionDescriptionRequest::kOffer);
2827}
2828
2829// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
2830// before async identity generation is finished.
2831TEST_F(WebRtcSessionTest,
2832 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
2833 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2834 VerifyMultipleAsyncCreateDescription(
2835 true, CreateSessionDescriptionRequest::kAnswer);
2836}
2837
2838// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
2839// before async identity generation fails.
2840TEST_F(WebRtcSessionTest,
2841 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
2842 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2843 VerifyMultipleAsyncCreateDescription(
2844 false, CreateSessionDescriptionRequest::kAnswer);
2845}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002846
2847// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
2848// offer has no SDES crypto but only DTLS fingerprint.
2849TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
2850 // Init without DTLS.
2851 Init(NULL);
2852 // Create a remote offer with secured transport disabled.
2853 cricket::MediaSessionOptions options;
2854 JsepSessionDescription* offer(CreateRemoteOffer(
2855 options, cricket::SEC_DISABLED));
2856 // Adds a DTLS fingerprint to the remote offer.
2857 cricket::SessionDescription* sdp = offer->description();
2858 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
2859 ASSERT_TRUE(audio != NULL);
2860 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
2861 audio->description.identity_fingerprint.reset(
2862 talk_base::SSLFingerprint::CreateFromRfc4572(
2863 talk_base::DIGEST_SHA_256, kFakeDtlsFingerprint));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002864 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesAndDtlsDisabled,
2865 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002866}
2867
wu@webrtc.orgde305012013-10-31 15:40:38 +00002868// This test verifies DSCP is properly applied on the media channels.
2869TEST_F(WebRtcSessionTest, TestDscpConstraint) {
2870 constraints_.reset(new FakeConstraints());
2871 constraints_->AddOptional(
2872 webrtc::MediaConstraintsInterface::kEnableDscp, true);
2873 Init(NULL);
2874 mediastream_signaling_.SendAudioVideoStream1();
2875 SessionDescriptionInterface* offer = CreateOffer(NULL);
2876
2877 SetLocalDescriptionWithoutError(offer);
2878
2879 video_channel_ = media_engine_->GetVideoChannel(0);
2880 voice_channel_ = media_engine_->GetVoiceChannel(0);
2881
2882 ASSERT_TRUE(video_channel_ != NULL);
2883 ASSERT_TRUE(voice_channel_ != NULL);
2884 cricket::AudioOptions audio_options;
2885 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
2886 cricket::VideoOptions video_options;
2887 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
2888 EXPECT_TRUE(audio_options.dscp.IsSet());
2889 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
2890 EXPECT_TRUE(video_options.dscp.IsSet());
2891 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
2892}
2893
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002894// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
2895// currently fails because upon disconnection and reconnection OnIceComplete is
2896// called more than once without returning to IceGatheringGathering.