blob: 6d3a58131e13e558525795f5f57dcbc05f0f6d44 [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
1424 candidate.set_component(2);
1425 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1426 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
1427 ASSERT_EQ(3u, candidates->count());
1428
1429 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1430 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1431}
1432
1433// Test that a remote candidate is added to the remote session description and
1434// that it is retained if the remote session description is changed.
1435TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001436 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001437 cricket::Candidate candidate1;
1438 candidate1.set_component(1);
1439 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1440 candidate1);
1441 mediastream_signaling_.SendAudioVideoStream1();
1442 CreateAndSetRemoteOfferAndLocalAnswer();
1443
1444 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1445 const SessionDescriptionInterface* remote_desc =
1446 session_->remote_description();
1447 ASSERT_TRUE(remote_desc != NULL);
1448 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1449 const IceCandidateCollection* candidates =
1450 remote_desc->candidates(kMediaContentIndex0);
1451 ASSERT_EQ(1u, candidates->count());
1452 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1453
1454 // Update the RemoteSessionDescription with a new session description and
1455 // a candidate and check that the new remote session description contains both
1456 // candidates.
1457 SessionDescriptionInterface* offer = CreateRemoteOffer();
1458 cricket::Candidate candidate2;
1459 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1460 candidate2);
1461 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1462 SetRemoteDescriptionWithoutError(offer);
1463
1464 remote_desc = session_->remote_description();
1465 ASSERT_TRUE(remote_desc != NULL);
1466 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1467 candidates = remote_desc->candidates(kMediaContentIndex0);
1468 ASSERT_EQ(2u, candidates->count());
1469 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1470 // Username and password have be updated with the TransportInfo of the
1471 // SessionDescription, won't be equal to the original one.
1472 candidate2.set_username(candidates->at(0)->candidate().username());
1473 candidate2.set_password(candidates->at(0)->candidate().password());
1474 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1475 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1476 // No need to verify the username and password.
1477 candidate1.set_username(candidates->at(1)->candidate().username());
1478 candidate1.set_password(candidates->at(1)->candidate().password());
1479 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1480
1481 // Test that the candidate is ignored if we can add the same candidate again.
1482 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1483}
1484
1485// Test that local candidates are added to the local session description and
1486// that they are retained if the local session description is changed.
1487TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001488 AddInterface(talk_base::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001489 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001490 mediastream_signaling_.SendAudioVideoStream1();
1491 CreateAndSetRemoteOfferAndLocalAnswer();
1492
1493 const SessionDescriptionInterface* local_desc = session_->local_description();
1494 const IceCandidateCollection* candidates =
1495 local_desc->candidates(kMediaContentIndex0);
1496 ASSERT_TRUE(candidates != NULL);
1497 EXPECT_EQ(0u, candidates->count());
1498
1499 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1500
1501 local_desc = session_->local_description();
1502 candidates = local_desc->candidates(kMediaContentIndex0);
1503 ASSERT_TRUE(candidates != NULL);
1504 EXPECT_LT(0u, candidates->count());
1505 candidates = local_desc->candidates(1);
1506 ASSERT_TRUE(candidates != NULL);
1507 EXPECT_LT(0u, candidates->count());
1508
1509 // Update the session descriptions.
1510 mediastream_signaling_.SendAudioVideoStream1();
1511 CreateAndSetRemoteOfferAndLocalAnswer();
1512
1513 local_desc = session_->local_description();
1514 candidates = local_desc->candidates(kMediaContentIndex0);
1515 ASSERT_TRUE(candidates != NULL);
1516 EXPECT_LT(0u, candidates->count());
1517 candidates = local_desc->candidates(1);
1518 ASSERT_TRUE(candidates != NULL);
1519 EXPECT_LT(0u, candidates->count());
1520}
1521
1522// Test that we can set a remote session description with remote candidates.
1523TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001524 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525
1526 cricket::Candidate candidate1;
1527 candidate1.set_component(1);
1528 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
1529 candidate1);
1530 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001531 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001532
1533 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
1534 SetRemoteDescriptionWithoutError(offer);
1535
1536 const SessionDescriptionInterface* remote_desc =
1537 session_->remote_description();
1538 ASSERT_TRUE(remote_desc != NULL);
1539 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1540 const IceCandidateCollection* candidates =
1541 remote_desc->candidates(kMediaContentIndex0);
1542 ASSERT_EQ(1u, candidates->count());
1543 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1544
wu@webrtc.org91053e72013-08-10 07:18:04 +00001545 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001546 SetLocalDescriptionWithoutError(answer);
1547}
1548
1549// Test that offers and answers contains ice candidates when Ice candidates have
1550// been gathered.
1551TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001552 AddInterface(talk_base::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001553 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554 mediastream_signaling_.SendAudioVideoStream1();
1555 // Ice is started but candidates are not provided until SetLocalDescription
1556 // is called.
1557 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1558 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1559 CreateAndSetRemoteOfferAndLocalAnswer();
1560 // Wait until at least one local candidate has been collected.
1561 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
1562 kIceCandidatesTimeout);
1563 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
1564 kIceCandidatesTimeout);
1565
1566 talk_base::scoped_ptr<SessionDescriptionInterface> local_offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001567 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
1569 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
1570 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
1571 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
1572
1573 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
1574 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001575 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
1577 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
1578 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
1579 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
1580 SetLocalDescriptionWithoutError(answer);
1581}
1582
1583// Verifies TransportProxy and media channels are created with content names
1584// present in the SessionDescription.
1585TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001586 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 mediastream_signaling_.SendAudioVideoStream1();
1588 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001589 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590
1591 // CreateOffer creates session description with the content names "audio" and
1592 // "video". Goal is to modify these content names and verify transport channel
1593 // proxy in the BaseSession, as proxies are created with the content names
1594 // present in SDP.
1595 std::string sdp;
1596 EXPECT_TRUE(offer->ToString(&sdp));
1597 const std::string kAudioMid = "a=mid:audio";
1598 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
1599 const std::string kVideoMid = "a=mid:video";
1600 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
1601
1602 // Replacing |audio| with |audio_content_name|.
1603 talk_base::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
1604 kAudioMidReplaceStr.c_str(),
1605 kAudioMidReplaceStr.length(),
1606 &sdp);
1607 // Replacing |video| with |video_content_name|.
1608 talk_base::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
1609 kVideoMidReplaceStr.c_str(),
1610 kVideoMidReplaceStr.length(),
1611 &sdp);
1612
1613 SessionDescriptionInterface* modified_offer =
1614 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
1615
1616 SetRemoteDescriptionWithoutError(modified_offer);
1617
1618 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00001619 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001620 SetLocalDescriptionWithoutError(answer);
1621
1622 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
1623 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
1624 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
1625 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
1626}
1627
1628// Test that an offer contains the correct media content descriptions based on
1629// the send streams when no constraints have been set.
1630TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001631 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001633 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634 ASSERT_TRUE(offer != NULL);
1635 const cricket::ContentInfo* content =
1636 cricket::GetFirstAudioContent(offer->description());
1637 EXPECT_TRUE(content != NULL);
1638 content = cricket::GetFirstVideoContent(offer->description());
1639 EXPECT_TRUE(content == NULL);
1640}
1641
1642// Test that an offer contains the correct media content descriptions based on
1643// the send streams when no constraints have been set.
1644TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001645 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001646 // Test Audio only offer.
1647 mediastream_signaling_.UseOptionsAudioOnly();
1648 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001649 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650 const cricket::ContentInfo* content =
1651 cricket::GetFirstAudioContent(offer->description());
1652 EXPECT_TRUE(content != NULL);
1653 content = cricket::GetFirstVideoContent(offer->description());
1654 EXPECT_TRUE(content == NULL);
1655
1656 // Test Audio / Video offer.
1657 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001658 offer.reset(CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 content = cricket::GetFirstAudioContent(offer->description());
1660 EXPECT_TRUE(content != NULL);
1661 content = cricket::GetFirstVideoContent(offer->description());
1662 EXPECT_TRUE(content != NULL);
1663}
1664
1665// Test that an offer contains no media content descriptions if
1666// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
1667TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001668 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001669 webrtc::FakeConstraints constraints_no_receive;
1670 constraints_no_receive.SetMandatoryReceiveAudio(false);
1671 constraints_no_receive.SetMandatoryReceiveVideo(false);
1672
1673 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001674 CreateOffer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 ASSERT_TRUE(offer != NULL);
1676 const cricket::ContentInfo* content =
1677 cricket::GetFirstAudioContent(offer->description());
1678 EXPECT_TRUE(content == NULL);
1679 content = cricket::GetFirstVideoContent(offer->description());
1680 EXPECT_TRUE(content == NULL);
1681}
1682
1683// Test that an offer contains only audio media content descriptions if
1684// kOfferToReceiveAudio constraints are set to true.
1685TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001686 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687 webrtc::FakeConstraints constraints_audio_only;
1688 constraints_audio_only.SetMandatoryReceiveAudio(true);
1689 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001690 CreateOffer(&constraints_audio_only));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001691
1692 const cricket::ContentInfo* content =
1693 cricket::GetFirstAudioContent(offer->description());
1694 EXPECT_TRUE(content != NULL);
1695 content = cricket::GetFirstVideoContent(offer->description());
1696 EXPECT_TRUE(content == NULL);
1697}
1698
1699// Test that an offer contains audio and video media content descriptions if
1700// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
1701TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001702 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 // Test Audio / Video offer.
1704 webrtc::FakeConstraints constraints_audio_video;
1705 constraints_audio_video.SetMandatoryReceiveAudio(true);
1706 constraints_audio_video.SetMandatoryReceiveVideo(true);
1707 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001708 CreateOffer(&constraints_audio_video));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001709 const cricket::ContentInfo* content =
1710 cricket::GetFirstAudioContent(offer->description());
1711
1712 EXPECT_TRUE(content != NULL);
1713 content = cricket::GetFirstVideoContent(offer->description());
1714 EXPECT_TRUE(content != NULL);
1715
1716 // TODO(perkj): Should the direction be set to SEND_ONLY if
1717 // The constraints is set to not receive audio or video but a track is added?
1718}
1719
1720// Test that an answer can not be created if the last remote description is not
1721// an offer.
1722TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001723 Init(NULL);
1724 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 SetLocalDescriptionWithoutError(offer);
1726 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
1727 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001728 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729}
1730
1731// Test that an answer contains the correct media content descriptions when no
1732// constraints have been set.
1733TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001734 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735 // Create a remote offer with audio and video content.
1736 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1737 SetRemoteDescriptionWithoutError(offer.release());
1738 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001739 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 const cricket::ContentInfo* content =
1741 cricket::GetFirstAudioContent(answer->description());
1742 ASSERT_TRUE(content != NULL);
1743 EXPECT_FALSE(content->rejected);
1744
1745 content = cricket::GetFirstVideoContent(answer->description());
1746 ASSERT_TRUE(content != NULL);
1747 EXPECT_FALSE(content->rejected);
1748}
1749
1750// Test that an answer contains the correct media content descriptions when no
1751// constraints have been set and the offer only contain audio.
1752TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001753 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754 // Create a remote offer with audio only.
1755 cricket::MediaSessionOptions options;
1756 options.has_audio = true;
1757 options.has_video = false;
1758 talk_base::scoped_ptr<JsepSessionDescription> offer(
1759 CreateRemoteOffer(options));
1760 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
1761 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
1762
1763 SetRemoteDescriptionWithoutError(offer.release());
1764 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001765 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 const cricket::ContentInfo* content =
1767 cricket::GetFirstAudioContent(answer->description());
1768 ASSERT_TRUE(content != NULL);
1769 EXPECT_FALSE(content->rejected);
1770
1771 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
1772}
1773
1774// Test that an answer contains the correct media content descriptions when no
1775// constraints have been set.
1776TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001777 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 // Create a remote offer with audio and video content.
1779 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1780 SetRemoteDescriptionWithoutError(offer.release());
1781 // Test with a stream with tracks.
1782 mediastream_signaling_.SendAudioVideoStream1();
1783 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001784 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 const cricket::ContentInfo* content =
1786 cricket::GetFirstAudioContent(answer->description());
1787 ASSERT_TRUE(content != NULL);
1788 EXPECT_FALSE(content->rejected);
1789
1790 content = cricket::GetFirstVideoContent(answer->description());
1791 ASSERT_TRUE(content != NULL);
1792 EXPECT_FALSE(content->rejected);
1793}
1794
1795// Test that an answer contains the correct media content descriptions when
1796// constraints have been set but no stream is sent.
1797TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001798 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 // Create a remote offer with audio and video content.
1800 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1801 SetRemoteDescriptionWithoutError(offer.release());
1802
1803 webrtc::FakeConstraints constraints_no_receive;
1804 constraints_no_receive.SetMandatoryReceiveAudio(false);
1805 constraints_no_receive.SetMandatoryReceiveVideo(false);
1806
1807 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001808 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 const cricket::ContentInfo* content =
1810 cricket::GetFirstAudioContent(answer->description());
1811 ASSERT_TRUE(content != NULL);
1812 EXPECT_TRUE(content->rejected);
1813
1814 content = cricket::GetFirstVideoContent(answer->description());
1815 ASSERT_TRUE(content != NULL);
1816 EXPECT_TRUE(content->rejected);
1817}
1818
1819// Test that an answer contains the correct media content descriptions when
1820// constraints have been set and streams are sent.
1821TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001822 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 // Create a remote offer with audio and video content.
1824 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1825 SetRemoteDescriptionWithoutError(offer.release());
1826
1827 webrtc::FakeConstraints constraints_no_receive;
1828 constraints_no_receive.SetMandatoryReceiveAudio(false);
1829 constraints_no_receive.SetMandatoryReceiveVideo(false);
1830
1831 // Test with a stream with tracks.
1832 mediastream_signaling_.SendAudioVideoStream1();
1833 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001834 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835
1836 // TODO(perkj): Should the direction be set to SEND_ONLY?
1837 const cricket::ContentInfo* content =
1838 cricket::GetFirstAudioContent(answer->description());
1839 ASSERT_TRUE(content != NULL);
1840 EXPECT_FALSE(content->rejected);
1841
1842 // TODO(perkj): Should the direction be set to SEND_ONLY?
1843 content = cricket::GetFirstVideoContent(answer->description());
1844 ASSERT_TRUE(content != NULL);
1845 EXPECT_FALSE(content->rejected);
1846}
1847
1848TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
1849 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001850 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001851 webrtc::FakeConstraints constraints;
1852 constraints.SetOptionalVAD(false);
1853 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001854 CreateOffer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855 const cricket::ContentInfo* content =
1856 cricket::GetFirstAudioContent(offer->description());
1857 EXPECT_TRUE(content != NULL);
1858 EXPECT_TRUE(VerifyNoCNCodecs(content));
1859}
1860
1861TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
1862 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001863 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864 // Create a remote offer with audio and video content.
1865 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1866 SetRemoteDescriptionWithoutError(offer.release());
1867
1868 webrtc::FakeConstraints constraints;
1869 constraints.SetOptionalVAD(false);
1870 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001871 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001872 const cricket::ContentInfo* content =
1873 cricket::GetFirstAudioContent(answer->description());
1874 ASSERT_TRUE(content != NULL);
1875 EXPECT_TRUE(VerifyNoCNCodecs(content));
1876}
1877
1878// This test verifies the call setup when remote answer with audio only and
1879// later updates with video.
1880TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001881 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
1883 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
1884
1885 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001886 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887
1888 cricket::MediaSessionOptions options;
1889 options.has_video = false;
1890 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
1891
1892 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1893 // and answer;
1894 SetLocalDescriptionWithoutError(offer);
1895 SetRemoteDescriptionWithoutError(answer);
1896
1897 video_channel_ = media_engine_->GetVideoChannel(0);
1898 voice_channel_ = media_engine_->GetVoiceChannel(0);
1899
1900 ASSERT_TRUE(video_channel_ == NULL);
1901
1902 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
1903 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1904 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
1905
1906 // Let the remote end update the session descriptions, with Audio and Video.
1907 mediastream_signaling_.SendAudioVideoStream2();
1908 CreateAndSetRemoteOfferAndLocalAnswer();
1909
1910 video_channel_ = media_engine_->GetVideoChannel(0);
1911 voice_channel_ = media_engine_->GetVoiceChannel(0);
1912
1913 ASSERT_TRUE(video_channel_ != NULL);
1914 ASSERT_TRUE(voice_channel_ != NULL);
1915
1916 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1917 ASSERT_EQ(1u, video_channel_->send_streams().size());
1918 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
1919 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
1920 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1921 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1922 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
1923 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
1924
1925 // Change session back to audio only.
1926 mediastream_signaling_.UseOptionsAudioOnly();
1927 CreateAndSetRemoteOfferAndLocalAnswer();
1928
1929 EXPECT_EQ(0u, video_channel_->recv_streams().size());
1930 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1931 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
1932 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1933 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
1934}
1935
1936// This test verifies the call setup when remote answer with video only and
1937// later updates with audio.
1938TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001939 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001940 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
1941 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
1942 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001943 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001944
1945 cricket::MediaSessionOptions options;
1946 options.has_audio = false;
1947 options.has_video = true;
1948 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1949 offer, options, cricket::SEC_ENABLED);
1950
1951 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1952 // and answer.
1953 SetLocalDescriptionWithoutError(offer);
1954 SetRemoteDescriptionWithoutError(answer);
1955
1956 video_channel_ = media_engine_->GetVideoChannel(0);
1957 voice_channel_ = media_engine_->GetVoiceChannel(0);
1958
1959 ASSERT_TRUE(voice_channel_ == NULL);
1960 ASSERT_TRUE(video_channel_ != NULL);
1961
1962 EXPECT_EQ(0u, video_channel_->recv_streams().size());
1963 ASSERT_EQ(1u, video_channel_->send_streams().size());
1964 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
1965
1966 // Update the session descriptions, with Audio and Video.
1967 mediastream_signaling_.SendAudioVideoStream2();
1968 CreateAndSetRemoteOfferAndLocalAnswer();
1969
1970 voice_channel_ = media_engine_->GetVoiceChannel(0);
1971 ASSERT_TRUE(voice_channel_ != NULL);
1972
1973 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1974 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1975 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
1976 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
1977
1978 // Change session back to video only.
1979 mediastream_signaling_.UseOptionsVideoOnly();
1980 CreateAndSetRemoteOfferAndLocalAnswer();
1981
1982 video_channel_ = media_engine_->GetVideoChannel(0);
1983 voice_channel_ = media_engine_->GetVoiceChannel(0);
1984
1985 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1986 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
1987 ASSERT_EQ(1u, video_channel_->send_streams().size());
1988 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
1989}
1990
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001992 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001993 mediastream_signaling_.SendAudioVideoStream1();
1994 scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001995 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 VerifyCryptoParams(offer->description());
1997 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001998 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 VerifyCryptoParams(answer->description());
2000}
2001
2002TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002003 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002004 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 mediastream_signaling_.SendAudioVideoStream1();
2006 scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002007 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008 VerifyNoCryptoParams(offer->description(), false);
2009}
2010
2011TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002012 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013 VerifyAnswerFromNonCryptoOffer();
2014}
2015
2016TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002017 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018 VerifyAnswerFromCryptoOffer();
2019}
2020
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002021// This test verifies that setLocalDescription fails if
2022// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2023TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
2024 Init(NULL);
2025 mediastream_signaling_.SendAudioVideoStream1();
2026 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
2027 std::string sdp;
2028 RemoveIceUfragPwdLines(offer.get(), &sdp);
2029 SessionDescriptionInterface* modified_offer =
2030 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002031 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002032}
2033
2034// This test verifies that setRemoteDescription fails if
2035// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2036TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
2037 Init(NULL);
2038 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2039 std::string sdp;
2040 RemoveIceUfragPwdLines(offer.get(), &sdp);
2041 SessionDescriptionInterface* modified_offer =
2042 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002043 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002044}
2045
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) {
2047 // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in
2048 // local description is removed by the application, BUNDLE flag should be
2049 // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc.
wu@webrtc.org91053e72013-08-10 07:18:04 +00002050 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) ==
2052 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
2053 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002054 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055 cricket::SessionDescription* offer_copy =
2056 offer->description()->Copy();
2057 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2058 JsepSessionDescription* modified_offer =
2059 new JsepSessionDescription(JsepSessionDescription::kOffer);
2060 modified_offer->Initialize(offer_copy, "1", "1");
2061
2062 SetLocalDescriptionWithoutError(modified_offer);
2063 EXPECT_FALSE(allocator_.flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE);
2064}
2065
2066TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002067 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068 mediastream_signaling_.SendAudioVideoStream1();
2069 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) ==
2070 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
2071 FakeConstraints constraints;
2072 constraints.SetMandatoryUseRtpMux(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002073 SessionDescriptionInterface* offer = CreateOffer(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074 SetLocalDescriptionWithoutError(offer);
2075 mediastream_signaling_.SendAudioVideoStream2();
2076 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
2077 CreateRemoteAnswer(session_->local_description()));
2078 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2079 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2080 JsepSessionDescription* modified_answer =
2081 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2082 modified_answer->Initialize(answer_copy, "1", "1");
2083 SetRemoteDescriptionWithoutError(modified_answer);
2084 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) ==
2085 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
2086
2087 video_channel_ = media_engine_->GetVideoChannel(0);
2088 voice_channel_ = media_engine_->GetVoiceChannel(0);
2089
2090 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2091 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
2092
2093 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2094 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
2095
2096 ASSERT_EQ(1u, video_channel_->send_streams().size());
2097 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
2098 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2099 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
2100}
2101
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002102// This test verifies that SetLocalDescription and SetRemoteDescription fails
2103// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2104TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002105 WebRtcSessionTest::Init(NULL);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002106 mediastream_signaling_.SendAudioVideoStream1();
2107 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) ==
2108 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
2109 FakeConstraints constraints;
2110 constraints.SetMandatoryUseRtpMux(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002111 SessionDescriptionInterface* offer = CreateOffer(&constraints);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002112 std::string offer_str;
2113 offer->ToString(&offer_str);
2114 // Disable rtcp-mux
2115 const std::string rtcp_mux = "rtcp-mux";
2116 const std::string xrtcp_mux = "xrtcp-mux";
2117 talk_base::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
2118 xrtcp_mux.c_str(), xrtcp_mux.length(),
2119 &offer_str);
2120 JsepSessionDescription *local_offer =
2121 new JsepSessionDescription(JsepSessionDescription::kOffer);
2122 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002123 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002124 JsepSessionDescription *remote_offer =
2125 new JsepSessionDescription(JsepSessionDescription::kOffer);
2126 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002127 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002128 // Trying unmodified SDP.
2129 SetLocalDescriptionWithoutError(offer);
2130}
2131
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002132TEST_F(WebRtcSessionTest, SetAudioPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002133 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 mediastream_signaling_.SendAudioVideoStream1();
2135 CreateAndSetRemoteOfferAndLocalAnswer();
2136 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2137 ASSERT_TRUE(channel != NULL);
2138 ASSERT_EQ(1u, channel->recv_streams().size());
2139 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2140 double left_vol, right_vol;
2141 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2142 EXPECT_EQ(1, left_vol);
2143 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002144 talk_base::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
2145 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2147 EXPECT_EQ(0, left_vol);
2148 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002149 EXPECT_EQ(0, renderer->channel_id());
2150 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2152 EXPECT_EQ(1, left_vol);
2153 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002154 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155}
2156
2157TEST_F(WebRtcSessionTest, SetAudioSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002158 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 mediastream_signaling_.SendAudioVideoStream1();
2160 CreateAndSetRemoteOfferAndLocalAnswer();
2161 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2162 ASSERT_TRUE(channel != NULL);
2163 ASSERT_EQ(1u, channel->send_streams().size());
2164 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2165 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2166
2167 cricket::AudioOptions options;
2168 options.echo_cancellation.Set(true);
2169
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002170 talk_base::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
2171 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002172 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2173 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002174 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002176 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2178 bool value;
2179 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2180 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002181 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002182}
2183
2184TEST_F(WebRtcSessionTest, SetVideoPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002185 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002186 mediastream_signaling_.SendAudioVideoStream1();
2187 CreateAndSetRemoteOfferAndLocalAnswer();
2188 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2189 ASSERT_TRUE(channel != NULL);
2190 ASSERT_LT(0u, channel->renderers().size());
2191 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2192 ASSERT_EQ(1u, channel->recv_streams().size());
2193 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2194 cricket::FakeVideoRenderer renderer;
2195 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2196 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2197 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2198 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2199}
2200
2201TEST_F(WebRtcSessionTest, SetVideoSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002202 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203 mediastream_signaling_.SendAudioVideoStream1();
2204 CreateAndSetRemoteOfferAndLocalAnswer();
2205 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2206 ASSERT_TRUE(channel != NULL);
2207 ASSERT_EQ(1u, channel->send_streams().size());
2208 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2209 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2210 cricket::VideoOptions* options = NULL;
2211 session_->SetVideoSend(send_ssrc, false, options);
2212 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2213 session_->SetVideoSend(send_ssrc, true, options);
2214 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2215}
2216
2217TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2218 TestCanInsertDtmf(false);
2219}
2220
2221TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2222 TestCanInsertDtmf(true);
2223}
2224
2225TEST_F(WebRtcSessionTest, InsertDtmf) {
2226 // Setup
wu@webrtc.org91053e72013-08-10 07:18:04 +00002227 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228 mediastream_signaling_.SendAudioVideoStream1();
2229 CreateAndSetRemoteOfferAndLocalAnswer();
2230 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2231 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2232
2233 // Insert DTMF
2234 const int expected_flags = DF_SEND;
2235 const int expected_duration = 90;
2236 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2237 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2238 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2239
2240 // Verify
2241 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2242 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2243 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2244 expected_duration, expected_flags));
2245 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2246 expected_duration, expected_flags));
2247 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2248 expected_duration, expected_flags));
2249}
2250
2251// This test verifies the |initiator| flag when session initiates the call.
2252TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002253 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002254 EXPECT_FALSE(session_->initiator());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002255 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2257 SetLocalDescriptionWithoutError(offer);
2258 EXPECT_TRUE(session_->initiator());
2259 SetRemoteDescriptionWithoutError(answer);
2260 EXPECT_TRUE(session_->initiator());
2261}
2262
2263// This test verifies the |initiator| flag when session receives the call.
2264TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002265 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 EXPECT_FALSE(session_->initiator());
2267 SessionDescriptionInterface* offer = CreateRemoteOffer();
2268 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002269 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002270
2271 EXPECT_FALSE(session_->initiator());
2272 SetLocalDescriptionWithoutError(answer);
2273 EXPECT_FALSE(session_->initiator());
2274}
2275
2276// This test verifies the ice protocol type at initiator of the call
2277// if |a=ice-options:google-ice| is present in answer.
2278TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002279 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002281 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org723d6832013-07-12 16:04:50 +00002282 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002283 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284 SetLocalDescriptionWithoutError(offer);
2285 std::string sdp;
2286 EXPECT_TRUE(answer->ToString(&sdp));
2287 // Adding ice-options to the session level.
2288 InjectAfter("t=0 0\r\n",
2289 "a=ice-options:google-ice\r\n",
2290 &sdp);
2291 SessionDescriptionInterface* answer_with_gice =
2292 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2293 SetRemoteDescriptionWithoutError(answer_with_gice);
2294 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2295 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2296}
2297
2298// This test verifies the ice protocol type at initiator of the call
2299// if ICE RFC5245 is supported in answer.
2300TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002301 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002303 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002304 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2305 SetLocalDescriptionWithoutError(offer);
2306
2307 SetRemoteDescriptionWithoutError(answer);
2308 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2309 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2310}
2311
2312// This test verifies the ice protocol type at receiver side of the call if
2313// receiver decides to use google-ice.
2314TEST_F(WebRtcSessionTest, TestReceiverGIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002315 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002317 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.org723d6832013-07-12 16:04:50 +00002319 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002320 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002321 std::string sdp;
2322 EXPECT_TRUE(answer->ToString(&sdp));
2323 // Adding ice-options to the session level.
2324 InjectAfter("t=0 0\r\n",
2325 "a=ice-options:google-ice\r\n",
2326 &sdp);
2327 SessionDescriptionInterface* answer_with_gice =
2328 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2329 SetLocalDescriptionWithoutError(answer_with_gice);
2330 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2331 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2332}
2333
2334// This test verifies the ice protocol type at receiver side of the call if
2335// receiver decides to use ice RFC 5245.
2336TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002337 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002339 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002340 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002341 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342 SetLocalDescriptionWithoutError(answer);
2343 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2344 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2345}
2346
2347// This test verifies the session state when ICE RFC5245 in offer and
2348// ICE google-ice in answer.
2349TEST_F(WebRtcSessionTest, TestIceOfferGIceOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002350 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351 mediastream_signaling_.SendAudioVideoStream1();
2352 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002353 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354 std::string offer_str;
2355 offer->ToString(&offer_str);
2356 // Disable google-ice
2357 const std::string gice_option = "google-ice";
2358 const std::string xgoogle_xice = "xgoogle-xice";
2359 talk_base::replace_substrs(gice_option.c_str(), gice_option.length(),
2360 xgoogle_xice.c_str(), xgoogle_xice.length(),
2361 &offer_str);
2362 JsepSessionDescription *ice_only_offer =
2363 new JsepSessionDescription(JsepSessionDescription::kOffer);
2364 EXPECT_TRUE((ice_only_offer)->Initialize(offer_str, NULL));
2365 SetLocalDescriptionWithoutError(ice_only_offer);
2366 std::string original_offer_sdp;
2367 EXPECT_TRUE(offer->ToString(&original_offer_sdp));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002368 SessionDescriptionInterface* pranswer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 CreateSessionDescription(JsepSessionDescription::kPrAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002370 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002371 SetRemoteDescriptionPranswerExpectError(kPushDownTDFailed,
2372 pranswer_with_gice);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002373 SessionDescriptionInterface* answer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374 CreateSessionDescription(JsepSessionDescription::kAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002375 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002376 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed,
2377 answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378}
2379
2380// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2381TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002382 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002383 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002384 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002385 SetLocalDescriptionWithoutError(offer);
2386 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
2387 CreateRemoteAnswer(session_->local_description()));
2388
2389 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2390 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002391 JsepSessionDescription* modified_answer =
2392 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002393
2394 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2395 answer->session_id(),
2396 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002397 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398
2399 // Modifying content names.
2400 std::string sdp;
2401 EXPECT_TRUE(answer->ToString(&sdp));
2402 const std::string kAudioMid = "a=mid:audio";
2403 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2404
2405 // Replacing |audio| with |audio_content_name|.
2406 talk_base::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
2407 kAudioMidReplaceStr.c_str(),
2408 kAudioMidReplaceStr.length(),
2409 &sdp);
2410
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002411 SessionDescriptionInterface* modified_answer1 =
2412 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002413 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002414
2415 SetRemoteDescriptionWithoutError(answer.release());
2416}
2417
2418// Verifying remote offer and local answer have matching m-lines as per
2419// RFC 3264.
2420TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002421 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002422 mediastream_signaling_.SendAudioVideoStream1();
2423 SessionDescriptionInterface* offer = CreateRemoteOffer();
2424 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002425 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426
2427 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2428 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002429 JsepSessionDescription* modified_answer =
2430 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431
2432 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2433 answer->session_id(),
2434 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002435 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436 SetLocalDescriptionWithoutError(answer);
2437}
2438
2439// This test verifies that WebRtcSession does not start candidate allocation
2440// before SetLocalDescription is called.
2441TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002442 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002443 mediastream_signaling_.SendAudioVideoStream1();
2444 SessionDescriptionInterface* offer = CreateRemoteOffer();
2445 cricket::Candidate candidate;
2446 candidate.set_component(1);
2447 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2448 candidate);
2449 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2450 cricket::Candidate candidate1;
2451 candidate1.set_component(1);
2452 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2453 candidate1);
2454 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2455 SetRemoteDescriptionWithoutError(offer);
2456 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
2457 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
2458
2459 // Pump for 1 second and verify that no candidates are generated.
2460 talk_base::Thread::Current()->ProcessMessages(1000);
2461 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
2462 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
2463
wu@webrtc.org91053e72013-08-10 07:18:04 +00002464 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465 SetLocalDescriptionWithoutError(answer);
2466 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
2467 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
2468 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2469}
2470
2471// This test verifies that crypto parameter is updated in local session
2472// description as per security policy set in MediaSessionDescriptionFactory.
2473TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002474 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475 mediastream_signaling_.SendAudioVideoStream1();
2476 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002477 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478
2479 // Making sure SetLocalDescription correctly sets crypto value in
2480 // SessionDescription object after de-serialization of sdp string. The value
2481 // will be set as per MediaSessionDescriptionFactory.
2482 std::string offer_str;
2483 offer->ToString(&offer_str);
2484 SessionDescriptionInterface* jsep_offer_str =
2485 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2486 SetLocalDescriptionWithoutError(jsep_offer_str);
2487 EXPECT_TRUE(session_->voice_channel()->secure_required());
2488 EXPECT_TRUE(session_->video_channel()->secure_required());
2489}
2490
2491// This test verifies the crypto parameter when security is disabled.
2492TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002493 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002494 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002496 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002497 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002498
2499 // Making sure SetLocalDescription correctly sets crypto value in
2500 // SessionDescription object after de-serialization of sdp string. The value
2501 // will be set as per MediaSessionDescriptionFactory.
2502 std::string offer_str;
2503 offer->ToString(&offer_str);
2504 SessionDescriptionInterface *jsep_offer_str =
2505 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2506 SetLocalDescriptionWithoutError(jsep_offer_str);
2507 EXPECT_FALSE(session_->voice_channel()->secure_required());
2508 EXPECT_FALSE(session_->video_channel()->secure_required());
2509}
2510
2511// This test verifies that an answer contains new ufrag and password if an offer
2512// with new ufrag and password is received.
2513TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002514 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 cricket::MediaSessionOptions options;
2516 options.has_audio = true;
2517 options.has_video = true;
2518 talk_base::scoped_ptr<JsepSessionDescription> offer(
2519 CreateRemoteOffer(options));
2520 SetRemoteDescriptionWithoutError(offer.release());
2521
2522 mediastream_signaling_.SendAudioVideoStream1();
2523 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002524 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525 SetLocalDescriptionWithoutError(answer.release());
2526
2527 // Receive an offer with new ufrag and password.
2528 options.transport_options.ice_restart = true;
2529 talk_base::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002530 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002531 SetRemoteDescriptionWithoutError(updated_offer1.release());
2532
2533 talk_base::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002534 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002535
2536 CompareIceUfragAndPassword(updated_answer1->description(),
2537 session_->local_description()->description(),
2538 false);
2539
2540 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002541}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542
wu@webrtc.org91053e72013-08-10 07:18:04 +00002543// This test verifies that an answer contains old ufrag and password if an offer
2544// with old ufrag and password is received.
2545TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
2546 Init(NULL);
2547 cricket::MediaSessionOptions options;
2548 options.has_audio = true;
2549 options.has_video = true;
2550 talk_base::scoped_ptr<JsepSessionDescription> offer(
2551 CreateRemoteOffer(options));
2552 SetRemoteDescriptionWithoutError(offer.release());
2553
2554 mediastream_signaling_.SendAudioVideoStream1();
2555 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
2556 CreateAnswer(NULL));
2557 SetLocalDescriptionWithoutError(answer.release());
2558
2559 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002560 options.transport_options.ice_restart = false;
2561 talk_base::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002562 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002563 SetRemoteDescriptionWithoutError(updated_offer2.release());
2564
2565 talk_base::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002566 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002567
2568 CompareIceUfragAndPassword(updated_answer2->description(),
2569 session_->local_description()->description(),
2570 true);
2571
2572 SetLocalDescriptionWithoutError(updated_answer2.release());
2573}
2574
2575TEST_F(WebRtcSessionTest, TestSessionContentError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002576 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002577 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002578 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579 const std::string session_id_orig = offer->session_id();
2580 const std::string session_version_orig = offer->session_version();
2581 SetLocalDescriptionWithoutError(offer);
2582
2583 video_channel_ = media_engine_->GetVideoChannel(0);
2584 video_channel_->set_fail_set_send_codecs(true);
2585
2586 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002587 SessionDescriptionInterface* answer =
2588 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002589 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002590}
2591
2592// Runs the loopback call test with BUNDLE and STUN disabled.
2593TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
2594 // Lets try with only UDP ports.
2595 allocator_.set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
2596 cricket::PORTALLOCATOR_DISABLE_TCP |
2597 cricket::PORTALLOCATOR_DISABLE_STUN |
2598 cricket::PORTALLOCATOR_DISABLE_RELAY);
2599 TestLoopbackCall();
2600}
2601
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002602TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002603 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002604 cricket::MediaSessionOptions options;
2605 options.has_audio = true;
2606 options.has_video = true;
2607
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002608 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
2609 std::string error_code_str = "ERROR_CONTENT";
2610 std::string error_desc = "Fake session error description.";
2611 session_->SetError(error_code, error_desc);
2612
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002613 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
2614 SessionDescriptionInterface* answer =
2615 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002616
2617 std::string action;
2618 std::ostringstream session_error_msg;
2619 session_error_msg << kSessionError << error_code_str << ". ";
2620 session_error_msg << kSessionErrorDesc << error_desc << ".";
2621 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
2622 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002623}
2624
2625TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
2626 constraints_.reset(new FakeConstraints());
2627 constraints_->AddOptional(
2628 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002629 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002630
2631 SetLocalDescriptionWithDataChannel();
2632 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
2633}
2634
2635TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
2636 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2637
2638 constraints_.reset(new FakeConstraints());
2639 constraints_->AddOptional(
2640 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00002641 options_.disable_sctp_data_channels = false;
2642
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002643 InitWithDtls(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002644
2645 SetLocalDescriptionWithDataChannel();
2646 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
2647}
2648
wu@webrtc.org967bfff2013-09-19 05:49:50 +00002649TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
2650 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2651
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002652 InitWithDtls(false);
2653
2654 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
2655 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00002656 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
2657}
2658
2659TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
2660 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2661 SetFactoryDtlsSrtp();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00002662 InitWithDtls(false);
2663
2664 // Create remote offer with SCTP.
2665 cricket::MediaSessionOptions options;
2666 options.data_channel_type = cricket::DCT_SCTP;
2667 JsepSessionDescription* offer =
2668 CreateRemoteOffer(options, cricket::SEC_ENABLED);
2669 SetRemoteDescriptionWithoutError(offer);
2670
2671 // Verifies the answer contains SCTP.
2672 talk_base::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
2673 EXPECT_TRUE(answer != NULL);
2674 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
2675 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002676}
2677
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002678TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
2679 constraints_.reset(new FakeConstraints());
2680 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002681 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
2682 InitWithDtls(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002683
2684 SetLocalDescriptionWithDataChannel();
2685 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
2686}
2687
2688TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
2689 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2690
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002691 InitWithDtls(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002692
2693 SetLocalDescriptionWithDataChannel();
2694 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
2695}
wu@webrtc.org91053e72013-08-10 07:18:04 +00002696
wu@webrtc.org97077a32013-10-25 21:18:33 +00002697TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
2698 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2699 options_.disable_sctp_data_channels = true;
2700 InitWithDtls(false);
2701
2702 SetLocalDescriptionWithDataChannel();
2703 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
2704}
2705
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002706TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
2707 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2708 const int new_send_port = 9998;
2709 const int new_recv_port = 7775;
2710
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002711 InitWithDtls(false);
2712 SetFactoryDtlsSrtp();
2713
2714 // By default, don't actually add the codecs to desc_factory_; they don't
2715 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
2716 // let the session description get parsed. That'll get the proper codecs
2717 // into the stream.
2718 cricket::MediaSessionOptions options;
2719 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
2720 "stream1", new_send_port, options);
2721
2722 // SetRemoteDescription will take the ownership of the offer.
2723 SetRemoteDescriptionWithoutError(offer);
2724
2725 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
2726 new_recv_port, CreateAnswer(NULL));
2727 ASSERT_TRUE(answer != NULL);
2728
2729 // Now set the local description, which'll take ownership of the answer.
2730 SetLocalDescriptionWithoutError(answer);
2731
2732 // TEST PLAN: Set the port number to something new, set it in the SDP,
2733 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002734 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002735 dci.reliable = true;
2736 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
2737 talk_base::scoped_refptr<webrtc::DataChannel> dc =
2738 session_->CreateDataChannel("datachannel", &dci);
2739
2740 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
2741 int portnum = -1;
2742 ASSERT_TRUE(ch != NULL);
2743 ASSERT_EQ(1UL, ch->send_codecs().size());
2744 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
2745 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
2746 ch->send_codecs()[0].name.c_str()));
2747 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
2748 &portnum));
2749 EXPECT_EQ(new_send_port, portnum);
2750
2751 ASSERT_EQ(1UL, ch->recv_codecs().size());
2752 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
2753 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
2754 ch->recv_codecs()[0].name.c_str()));
2755 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
2756 &portnum));
2757 EXPECT_EQ(new_recv_port, portnum);
2758}
2759
wu@webrtc.org91053e72013-08-10 07:18:04 +00002760// Verifies that CreateOffer succeeds when CreateOffer is called before async
2761// identity generation is finished.
2762TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
2763 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00002764 InitWithDtls(false);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002765
2766 EXPECT_TRUE(session_->waiting_for_identity());
2767 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
2768 EXPECT_TRUE(offer != NULL);
2769}
2770
2771// Verifies that CreateAnswer succeeds when CreateOffer is called before async
2772// identity generation is finished.
2773TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
2774 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00002775 InitWithDtls(false);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002776
2777 cricket::MediaSessionOptions options;
2778 scoped_ptr<JsepSessionDescription> offer(
2779 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
2780 ASSERT_TRUE(offer.get() != NULL);
2781 SetRemoteDescriptionWithoutError(offer.release());
2782
2783 talk_base::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
2784 EXPECT_TRUE(answer != NULL);
2785}
2786
2787// Verifies that CreateOffer succeeds when CreateOffer is called after async
2788// identity generation is finished.
2789TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
2790 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00002791 InitWithDtls(false);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002792
2793 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
2794 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
2795 EXPECT_TRUE(offer != NULL);
2796}
2797
2798// Verifies that CreateOffer fails when CreateOffer is called after async
2799// identity generation fails.
2800TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
2801 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00002802 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002803
2804 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
2805 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
2806 EXPECT_TRUE(offer == NULL);
2807}
2808
2809// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
2810// before async identity generation is finished.
2811TEST_F(WebRtcSessionTest,
2812 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
2813 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2814 VerifyMultipleAsyncCreateDescription(
2815 true, CreateSessionDescriptionRequest::kOffer);
2816}
2817
2818// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
2819// before async identity generation fails.
2820TEST_F(WebRtcSessionTest,
2821 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
2822 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2823 VerifyMultipleAsyncCreateDescription(
2824 false, CreateSessionDescriptionRequest::kOffer);
2825}
2826
2827// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
2828// before async identity generation is finished.
2829TEST_F(WebRtcSessionTest,
2830 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
2831 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2832 VerifyMultipleAsyncCreateDescription(
2833 true, CreateSessionDescriptionRequest::kAnswer);
2834}
2835
2836// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
2837// before async identity generation fails.
2838TEST_F(WebRtcSessionTest,
2839 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
2840 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2841 VerifyMultipleAsyncCreateDescription(
2842 false, CreateSessionDescriptionRequest::kAnswer);
2843}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002844
2845// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
2846// offer has no SDES crypto but only DTLS fingerprint.
2847TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
2848 // Init without DTLS.
2849 Init(NULL);
2850 // Create a remote offer with secured transport disabled.
2851 cricket::MediaSessionOptions options;
2852 JsepSessionDescription* offer(CreateRemoteOffer(
2853 options, cricket::SEC_DISABLED));
2854 // Adds a DTLS fingerprint to the remote offer.
2855 cricket::SessionDescription* sdp = offer->description();
2856 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
2857 ASSERT_TRUE(audio != NULL);
2858 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
2859 audio->description.identity_fingerprint.reset(
2860 talk_base::SSLFingerprint::CreateFromRfc4572(
2861 talk_base::DIGEST_SHA_256, kFakeDtlsFingerprint));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002862 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesAndDtlsDisabled,
2863 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002864}
2865
wu@webrtc.orgde305012013-10-31 15:40:38 +00002866// This test verifies DSCP is properly applied on the media channels.
2867TEST_F(WebRtcSessionTest, TestDscpConstraint) {
2868 constraints_.reset(new FakeConstraints());
2869 constraints_->AddOptional(
2870 webrtc::MediaConstraintsInterface::kEnableDscp, true);
2871 Init(NULL);
2872 mediastream_signaling_.SendAudioVideoStream1();
2873 SessionDescriptionInterface* offer = CreateOffer(NULL);
2874
2875 SetLocalDescriptionWithoutError(offer);
2876
2877 video_channel_ = media_engine_->GetVideoChannel(0);
2878 voice_channel_ = media_engine_->GetVoiceChannel(0);
2879
2880 ASSERT_TRUE(video_channel_ != NULL);
2881 ASSERT_TRUE(voice_channel_ != NULL);
2882 cricket::AudioOptions audio_options;
2883 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
2884 cricket::VideoOptions video_options;
2885 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
2886 EXPECT_TRUE(audio_options.dscp.IsSet());
2887 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
2888 EXPECT_TRUE(video_options.dscp.IsSet());
2889 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
2890}
2891
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002892// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
2893// currently fails because upon disconnection and reconnection OnIceComplete is
2894// called more than once without returning to IceGatheringGathering.