blob: 0ddc16cf2f01bef76a9b44d436bd737fec70cd8f [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;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089using webrtc::kMlineMismatch;
90using webrtc::kSdpWithoutCrypto;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +000091using webrtc::kSdpWithoutSdesAndDtlsDisabled;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000092using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093using webrtc::kSessionError;
94using webrtc::kSetLocalSdpFailed;
95using webrtc::kSetRemoteSdpFailed;
96using webrtc::kPushDownAnswerTDFailed;
97using webrtc::kPushDownPranswerTDFailed;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +000098using webrtc::kBundleWithoutRtcpMux;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099
100static const SocketAddress kClientAddr1("11.11.11.11", 0);
101static const SocketAddress kClientAddr2("22.22.22.22", 0);
102static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT);
103
104static const char kSessionVersion[] = "1";
105
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106// Media index of candidates belonging to the first media content.
107static const int kMediaContentIndex0 = 0;
108static const char kMediaContentName0[] = "audio";
109
110// Media index of candidates belonging to the second media content.
111static const int kMediaContentIndex1 = 1;
112static const char kMediaContentName1[] = "video";
113
114static const int kIceCandidatesTimeout = 10000;
115
116static const cricket::AudioCodec
117 kTelephoneEventCodec(106, "telephone-event", 8000, 0, 1, 0);
118static const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
119static const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
120
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000121static const char kFakeDtlsFingerprint[] =
122 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
123 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
124
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125// Add some extra |newlines| to the |message| after |line|.
126static void InjectAfter(const std::string& line,
127 const std::string& newlines,
128 std::string* message) {
129 const std::string tmp = line + newlines;
130 talk_base::replace_substrs(line.c_str(), line.length(),
131 tmp.c_str(), tmp.length(), message);
132}
133
134class MockIceObserver : public webrtc::IceObserver {
135 public:
136 MockIceObserver()
137 : oncandidatesready_(false),
138 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
139 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
140 }
141
142 virtual void OnIceConnectionChange(
143 PeerConnectionInterface::IceConnectionState new_state) {
144 ice_connection_state_ = new_state;
145 }
146 virtual void OnIceGatheringChange(
147 PeerConnectionInterface::IceGatheringState new_state) {
148 // We can never transition back to "new".
149 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
150 ice_gathering_state_ = new_state;
151
152 // oncandidatesready_ really means "ICE gathering is complete".
153 // This if statement ensures that this value remains correct when we
154 // transition from kIceGatheringComplete to kIceGatheringGathering.
155 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
156 oncandidatesready_ = false;
157 }
158 }
159
160 // Found a new candidate.
161 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
162 if (candidate->sdp_mline_index() == kMediaContentIndex0) {
163 mline_0_candidates_.push_back(candidate->candidate());
164 } else if (candidate->sdp_mline_index() == kMediaContentIndex1) {
165 mline_1_candidates_.push_back(candidate->candidate());
166 }
167 // The ICE gathering state should always be Gathering when a candidate is
168 // received (or possibly Completed in the case of the final candidate).
169 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
170 }
171
172 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
173 virtual void OnIceComplete() {
174 EXPECT_FALSE(oncandidatesready_);
175 oncandidatesready_ = true;
176
177 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
178 // be called approximately simultaneously. For ease of testing, this
179 // check additionally requires that they be called in the above order.
180 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
181 ice_gathering_state_);
182 }
183
184 bool oncandidatesready_;
185 std::vector<cricket::Candidate> mline_0_candidates_;
186 std::vector<cricket::Candidate> mline_1_candidates_;
187 PeerConnectionInterface::IceConnectionState ice_connection_state_;
188 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
189};
190
191class WebRtcSessionForTest : public webrtc::WebRtcSession {
192 public:
193 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
194 talk_base::Thread* signaling_thread,
195 talk_base::Thread* worker_thread,
196 cricket::PortAllocator* port_allocator,
197 webrtc::IceObserver* ice_observer,
198 webrtc::MediaStreamSignaling* mediastream_signaling)
199 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
200 mediastream_signaling) {
201 RegisterIceObserver(ice_observer);
202 }
203 virtual ~WebRtcSessionForTest() {}
204
205 using cricket::BaseSession::GetTransportProxy;
206 using webrtc::WebRtcSession::SetAudioPlayout;
207 using webrtc::WebRtcSession::SetAudioSend;
208 using webrtc::WebRtcSession::SetCaptureDevice;
209 using webrtc::WebRtcSession::SetVideoPlayout;
210 using webrtc::WebRtcSession::SetVideoSend;
211};
212
wu@webrtc.org91053e72013-08-10 07:18:04 +0000213class WebRtcSessionCreateSDPObserverForTest
214 : public talk_base::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000216 enum State {
217 kInit,
218 kFailed,
219 kSucceeded,
220 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000221 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000222
223 // CreateSessionDescriptionObserver implementation.
224 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000225 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000226 state_ = kSucceeded;
227 }
228 virtual void OnFailure(const std::string& error) {
229 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 }
231
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000232 SessionDescriptionInterface* description() { return description_.get(); }
233
234 SessionDescriptionInterface* ReleaseDescription() {
235 return description_.release();
236 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237
wu@webrtc.org91053e72013-08-10 07:18:04 +0000238 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239
wu@webrtc.org91053e72013-08-10 07:18:04 +0000240 protected:
241 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242
243 private:
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000244 talk_base::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000245 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000246};
247
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000248class FakeAudioRenderer : public cricket::AudioRenderer {
249 public:
250 FakeAudioRenderer() : channel_id_(-1) {}
251
252 virtual void AddChannel(int channel_id) OVERRIDE {
253 ASSERT(channel_id_ == -1);
254 channel_id_ = channel_id;
255 }
256 virtual void RemoveChannel(int channel_id) OVERRIDE {
257 ASSERT(channel_id == channel_id_);
258 channel_id_ = -1;
259 }
260
261 int channel_id() const { return channel_id_; }
262 private:
263 int channel_id_;
264};
265
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000266class WebRtcSessionTest : public testing::Test {
267 protected:
268 // TODO Investigate why ChannelManager crashes, if it's created
269 // after stun_server.
270 WebRtcSessionTest()
271 : media_engine_(new cricket::FakeMediaEngine()),
272 data_engine_(new cricket::FakeDataEngine()),
273 device_manager_(new cricket::FakeDeviceManager()),
274 channel_manager_(new cricket::ChannelManager(
275 media_engine_, data_engine_, device_manager_,
276 new cricket::CaptureManager(), talk_base::Thread::Current())),
277 tdesc_factory_(new cricket::TransportDescriptionFactory()),
278 desc_factory_(new cricket::MediaSessionDescriptionFactory(
279 channel_manager_.get(), tdesc_factory_.get())),
280 pss_(new talk_base::PhysicalSocketServer),
281 vss_(new talk_base::VirtualSocketServer(pss_.get())),
282 fss_(new talk_base::FirewallSocketServer(vss_.get())),
283 ss_scope_(fss_.get()),
284 stun_server_(talk_base::Thread::Current(), kStunAddr),
285 allocator_(&network_manager_, kStunAddr,
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000286 SocketAddress(), SocketAddress(), SocketAddress()),
287 mediastream_signaling_(channel_manager_.get()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
289 allocator_.set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
290 cricket::PORTALLOCATOR_DISABLE_RELAY |
291 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
292 EXPECT_TRUE(channel_manager_->Init());
293 desc_factory_->set_add_legacy_streams(false);
294 }
295
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000296 static void SetUpTestCase() {
297 talk_base::InitializeSSL();
298 }
299
300 static void TearDownTestCase() {
301 talk_base::CleanupSSL();
302 }
303
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304 void AddInterface(const SocketAddress& addr) {
305 network_manager_.AddInterface(addr);
306 }
307
wu@webrtc.org91053e72013-08-10 07:18:04 +0000308 void Init(DTLSIdentityServiceInterface* identity_service) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 ASSERT_TRUE(session_.get() == NULL);
310 session_.reset(new WebRtcSessionForTest(
311 channel_manager_.get(), talk_base::Thread::Current(),
312 talk_base::Thread::Current(), &allocator_,
313 &observer_,
314 &mediastream_signaling_));
315
316 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
317 observer_.ice_connection_state_);
318 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
319 observer_.ice_gathering_state_);
320
wu@webrtc.org97077a32013-10-25 21:18:33 +0000321 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
322 identity_service));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323 }
324
325 void InitWithDtmfCodec() {
326 // Add kTelephoneEventCodec for dtmf test.
327 std::vector<cricket::AudioCodec> codecs;
328 codecs.push_back(kTelephoneEventCodec);
329 media_engine_->SetAudioCodecs(codecs);
330 desc_factory_->set_audio_codecs(codecs);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000331 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 }
333
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000334 void InitWithDtls(bool identity_request_should_fail = false) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000335 FakeIdentityService* identity_service = new FakeIdentityService();
336 identity_service->set_should_fail(identity_request_should_fail);
337 Init(identity_service);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 }
339
340 // Creates a local offer and applies it. Starts ice.
341 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
342 // to decide which streams to create.
343 void InitiateCall() {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000344 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 SetLocalDescriptionWithoutError(offer);
346 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
347 observer_.ice_gathering_state_,
348 kIceCandidatesTimeout);
349 }
350
wu@webrtc.org91053e72013-08-10 07:18:04 +0000351 SessionDescriptionInterface* CreateOffer(
352 const webrtc::MediaConstraintsInterface* constraints) {
353 talk_base::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
354 observer = new WebRtcSessionCreateSDPObserverForTest();
355 session_->CreateOffer(observer, constraints);
356 EXPECT_TRUE_WAIT(
357 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000358 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000359 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000360 }
361
362 SessionDescriptionInterface* CreateAnswer(
363 const webrtc::MediaConstraintsInterface* constraints) {
364 talk_base::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
365 = new WebRtcSessionCreateSDPObserverForTest();
366 session_->CreateAnswer(observer, constraints);
367 EXPECT_TRUE_WAIT(
368 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000369 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000370 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000371 }
372
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373 bool ChannelsExist() {
374 return (session_->voice_channel() != NULL &&
375 session_->video_channel() != NULL);
376 }
377
378 void CheckTransportChannels() {
379 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
380 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
381 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
382 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
383 }
384
385 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
386 ASSERT_TRUE(session_.get() != NULL);
387 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
388 ASSERT_TRUE(content != NULL);
389 const cricket::AudioContentDescription* audio_content =
390 static_cast<const cricket::AudioContentDescription*>(
391 content->description);
392 ASSERT_TRUE(audio_content != NULL);
393 ASSERT_EQ(1U, audio_content->cryptos().size());
394 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
395 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
396 audio_content->cryptos()[0].cipher_suite);
397 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
398 audio_content->protocol());
399
400 content = cricket::GetFirstVideoContent(sdp);
401 ASSERT_TRUE(content != NULL);
402 const cricket::VideoContentDescription* video_content =
403 static_cast<const cricket::VideoContentDescription*>(
404 content->description);
405 ASSERT_TRUE(video_content != NULL);
406 ASSERT_EQ(1U, video_content->cryptos().size());
407 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
408 video_content->cryptos()[0].cipher_suite);
409 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
410 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
411 video_content->protocol());
412 }
413
414 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
415 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
416 ASSERT_TRUE(content != NULL);
417 const cricket::AudioContentDescription* audio_content =
418 static_cast<const cricket::AudioContentDescription*>(
419 content->description);
420 ASSERT_TRUE(audio_content != NULL);
421 ASSERT_EQ(0U, audio_content->cryptos().size());
422
423 content = cricket::GetFirstVideoContent(sdp);
424 ASSERT_TRUE(content != NULL);
425 const cricket::VideoContentDescription* video_content =
426 static_cast<const cricket::VideoContentDescription*>(
427 content->description);
428 ASSERT_TRUE(video_content != NULL);
429 ASSERT_EQ(0U, video_content->cryptos().size());
430
431 if (dtls) {
432 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
433 audio_content->protocol());
434 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
435 video_content->protocol());
436 } else {
437 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
438 audio_content->protocol());
439 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
440 video_content->protocol());
441 }
442 }
443
444 // Set the internal fake description factories to do DTLS-SRTP.
445 void SetFactoryDtlsSrtp() {
446 desc_factory_->set_secure(cricket::SEC_ENABLED);
447 std::string identity_name = "WebRTC" +
448 talk_base::ToString(talk_base::CreateRandomId());
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000449 identity_.reset(talk_base::SSLIdentity::Generate(identity_name));
450 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
452 }
453
454 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
455 bool expected) {
456 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
457 ASSERT_TRUE(audio != NULL);
458 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 const TransportInfo* video = sdp->GetTransportInfoByName("video");
460 ASSERT_TRUE(video != NULL);
461 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 }
463
464 void VerifyAnswerFromNonCryptoOffer() {
465 // Create a SDP without Crypto.
466 cricket::MediaSessionOptions options;
467 options.has_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000468 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000470 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000471 VerifyNoCryptoParams(offer->description(), false);
472 SetRemoteDescriptionExpectError("Called with a SDP without crypto enabled",
wu@webrtc.org91053e72013-08-10 07:18:04 +0000473 offer);
474 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475 // Answer should be NULL as no crypto params in offer.
476 ASSERT_TRUE(answer == NULL);
477 }
478
479 void VerifyAnswerFromCryptoOffer() {
480 cricket::MediaSessionOptions options;
481 options.has_video = true;
482 options.bundle_enabled = true;
483 scoped_ptr<JsepSessionDescription> offer(
484 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
485 ASSERT_TRUE(offer.get() != NULL);
486 VerifyCryptoParams(offer->description());
487 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000488 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000489 ASSERT_TRUE(answer.get() != NULL);
490 VerifyCryptoParams(answer->description());
491 }
492
493 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
494 const cricket::SessionDescription* desc2,
495 bool expect_equal) {
496 if (desc1->contents().size() != desc2->contents().size()) {
497 EXPECT_FALSE(expect_equal);
498 return;
499 }
500
501 const cricket::ContentInfos& contents = desc1->contents();
502 cricket::ContentInfos::const_iterator it = contents.begin();
503
504 for (; it != contents.end(); ++it) {
505 const cricket::TransportDescription* transport_desc1 =
506 desc1->GetTransportDescriptionByName(it->name);
507 const cricket::TransportDescription* transport_desc2 =
508 desc2->GetTransportDescriptionByName(it->name);
509 if (!transport_desc1 || !transport_desc2) {
510 EXPECT_FALSE(expect_equal);
511 return;
512 }
513 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
514 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
515 EXPECT_FALSE(expect_equal);
516 return;
517 }
518 }
519 EXPECT_TRUE(expect_equal);
520 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000521
522 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
523 std::string *sdp) {
524 const cricket::SessionDescription* desc = current_desc->description();
525 EXPECT_TRUE(current_desc->ToString(sdp));
526
527 const cricket::ContentInfos& contents = desc->contents();
528 cricket::ContentInfos::const_iterator it = contents.begin();
529 // Replace ufrag and pwd lines with empty strings.
530 for (; it != contents.end(); ++it) {
531 const cricket::TransportDescription* transport_desc =
532 desc->GetTransportDescriptionByName(it->name);
533 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
534 + "\r\n";
535 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
536 + "\r\n";
537 talk_base::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
538 "", 0,
539 sdp);
540 talk_base::replace_substrs(pwd_line.c_str(), pwd_line.length(),
541 "", 0,
542 sdp);
543 }
544 }
545
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 // Creates a remote offer and and applies it as a remote description,
547 // creates a local answer and applies is as a local description.
548 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
549 // to decide which local and remote streams to create.
550 void CreateAndSetRemoteOfferAndLocalAnswer() {
551 SessionDescriptionInterface* offer = CreateRemoteOffer();
552 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000553 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000554 SetLocalDescriptionWithoutError(answer);
555 }
556 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
557 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
558 }
559 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
560 BaseSession::State expected_state) {
561 SetLocalDescriptionWithoutError(desc);
562 EXPECT_EQ(expected_state, session_->state());
563 }
564 void SetLocalDescriptionExpectError(const std::string& expected_error,
565 SessionDescriptionInterface* desc) {
566 std::string error;
567 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
568 EXPECT_NE(std::string::npos, error.find(kSetLocalSdpFailed));
569 EXPECT_NE(std::string::npos, error.find(expected_error));
570 }
571 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
572 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
573 }
574 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
575 BaseSession::State expected_state) {
576 SetRemoteDescriptionWithoutError(desc);
577 EXPECT_EQ(expected_state, session_->state());
578 }
579 void SetRemoteDescriptionExpectError(const std::string& expected_error,
580 SessionDescriptionInterface* desc) {
581 std::string error;
582 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
583 EXPECT_NE(std::string::npos, error.find(kSetRemoteSdpFailed));
584 EXPECT_NE(std::string::npos, error.find(expected_error));
585 }
586
587 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
588 SessionDescriptionInterface** nocrypto_answer) {
589 // Create a SDP without Crypto.
590 cricket::MediaSessionOptions options;
591 options.has_video = true;
592 options.bundle_enabled = true;
593 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
594 ASSERT_TRUE(*offer != NULL);
595 VerifyCryptoParams((*offer)->description());
596
597 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
598 cricket::SEC_DISABLED);
599 EXPECT_TRUE(*nocrypto_answer != NULL);
600 }
601
602 JsepSessionDescription* CreateRemoteOfferWithVersion(
603 cricket::MediaSessionOptions options,
604 cricket::SecurePolicy secure_policy,
605 const std::string& session_version,
606 const SessionDescriptionInterface* current_desc) {
607 std::string session_id = talk_base::ToString(talk_base::CreateRandomId64());
608 const cricket::SessionDescription* cricket_desc = NULL;
609 if (current_desc) {
610 cricket_desc = current_desc->description();
611 session_id = current_desc->session_id();
612 }
613
614 desc_factory_->set_secure(secure_policy);
615 JsepSessionDescription* offer(
616 new JsepSessionDescription(JsepSessionDescription::kOffer));
617 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
618 session_id, session_version)) {
619 delete offer;
620 offer = NULL;
621 }
622 return offer;
623 }
624 JsepSessionDescription* CreateRemoteOffer(
625 cricket::MediaSessionOptions options) {
626 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
627 kSessionVersion, NULL);
628 }
629 JsepSessionDescription* CreateRemoteOffer(
630 cricket::MediaSessionOptions options, cricket::SecurePolicy policy) {
631 return CreateRemoteOfferWithVersion(options, policy, kSessionVersion, NULL);
632 }
633 JsepSessionDescription* CreateRemoteOffer(
634 cricket::MediaSessionOptions options,
635 const SessionDescriptionInterface* current_desc) {
636 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
637 kSessionVersion, current_desc);
638 }
639
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000640 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
641 const char* sctp_stream_name, int new_port,
642 cricket::MediaSessionOptions options) {
643 options.data_channel_type = cricket::DCT_SCTP;
644 options.AddStream(cricket::MEDIA_TYPE_DATA, "datachannel",
645 sctp_stream_name);
646 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
647 }
648
649 // Takes ownership of offer_basis (and deletes it).
650 JsepSessionDescription* ChangeSDPSctpPort(
651 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
652 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
653 // SessionDescription from the mutated string.
654 const char* default_port_str = "5000";
655 char new_port_str[16];
656 talk_base::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
657 std::string offer_str;
658 offer_basis->ToString(&offer_str);
659 talk_base::replace_substrs(default_port_str, strlen(default_port_str),
660 new_port_str, strlen(new_port_str),
661 &offer_str);
662 JsepSessionDescription* offer = new JsepSessionDescription(
663 offer_basis->type());
664 delete offer_basis;
665 offer->Initialize(offer_str, NULL);
666 return offer;
667 }
668
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000669 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
670 // before this function to decide which streams to create.
671 JsepSessionDescription* CreateRemoteOffer() {
672 cricket::MediaSessionOptions options;
673 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
674 return CreateRemoteOffer(options, session_->remote_description());
675 }
676
677 JsepSessionDescription* CreateRemoteAnswer(
678 const SessionDescriptionInterface* offer,
679 cricket::MediaSessionOptions options,
680 cricket::SecurePolicy policy) {
681 desc_factory_->set_secure(policy);
682 const std::string session_id =
683 talk_base::ToString(talk_base::CreateRandomId64());
684 JsepSessionDescription* answer(
685 new JsepSessionDescription(JsepSessionDescription::kAnswer));
686 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
687 options, NULL),
688 session_id, kSessionVersion)) {
689 delete answer;
690 answer = NULL;
691 }
692 return answer;
693 }
694
695 JsepSessionDescription* CreateRemoteAnswer(
696 const SessionDescriptionInterface* offer,
697 cricket::MediaSessionOptions options) {
698 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
699 }
700
701 // Creates an answer session description with streams based on
702 // |mediastream_signaling_|. Call
703 // mediastream_signaling_.UseOptionsWithStreamX() before this function
704 // to decide which streams to create.
705 JsepSessionDescription* CreateRemoteAnswer(
706 const SessionDescriptionInterface* offer) {
707 cricket::MediaSessionOptions options;
708 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
709 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
710 }
711
712 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
713 AddInterface(kClientAddr1);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000714 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715 mediastream_signaling_.SendAudioVideoStream1();
716 FakeConstraints constraints;
717 constraints.SetMandatoryUseRtpMux(bundle);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000718 SessionDescriptionInterface* offer = CreateOffer(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
720 // and answer.
721 SetLocalDescriptionWithoutError(offer);
722
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000723 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
724 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 std::string sdp;
726 EXPECT_TRUE(answer->ToString(&sdp));
727
728 size_t expected_candidate_num = 2;
729 if (!rtcp_mux) {
730 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
731 // for rtp and rtcp.
732 expected_candidate_num = 4;
733 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734 const std::string kRtcpMux = "a=rtcp-mux";
735 const std::string kXRtcpMux = "a=xrtcp-mux";
736 talk_base::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
737 kXRtcpMux.c_str(), kXRtcpMux.length(),
738 &sdp);
739 }
740
741 SessionDescriptionInterface* new_answer = CreateSessionDescription(
742 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743
744 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000745 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000746 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
747 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
748 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
749 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
750 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
751 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
752 if (bundle) {
753 EXPECT_TRUE(c0.IsEquivalent(c1));
754 } else {
755 EXPECT_FALSE(c0.IsEquivalent(c1));
756 }
757 }
758 }
759 // Tests that we can only send DTMF when the dtmf codec is supported.
760 void TestCanInsertDtmf(bool can) {
761 if (can) {
762 InitWithDtmfCodec();
763 } else {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000764 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765 }
766 mediastream_signaling_.SendAudioVideoStream1();
767 CreateAndSetRemoteOfferAndLocalAnswer();
768 EXPECT_FALSE(session_->CanInsertDtmf(""));
769 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
770 }
771
772 // The method sets up a call from the session to itself, in a loopback
773 // arrangement. It also uses a firewall rule to create a temporary
774 // disconnection. This code is placed as a method so that it can be invoked
775 // by multiple tests with different allocators (e.g. with and without BUNDLE).
776 // While running the call, this method also checks if the session goes through
777 // the correct sequence of ICE states when a connection is established,
778 // broken, and re-established.
779 // The Connection state should go:
780 // New -> Checking -> Connected -> Disconnected -> Connected.
781 // The Gathering state should go: New -> Gathering -> Completed.
782 void TestLoopbackCall() {
783 AddInterface(kClientAddr1);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000784 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000786 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787
788 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
789 observer_.ice_gathering_state_);
790 SetLocalDescriptionWithoutError(offer);
791 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
792 observer_.ice_connection_state_);
793 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
794 observer_.ice_gathering_state_,
795 kIceCandidatesTimeout);
796 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
797 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
798 observer_.ice_gathering_state_,
799 kIceCandidatesTimeout);
800
801 std::string sdp;
802 offer->ToString(&sdp);
803 SessionDescriptionInterface* desc =
804 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
805 ASSERT_TRUE(desc != NULL);
806 SetRemoteDescriptionWithoutError(desc);
807
808 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
809 observer_.ice_connection_state_,
810 kIceCandidatesTimeout);
811 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionConnected,
812 observer_.ice_connection_state_,
813 kIceCandidatesTimeout);
814 // TODO(bemasc): EXPECT(Completed) once the details are standardized.
815
816 // Adding firewall rule to block ping requests, which should cause
817 // transport channel failure.
818 fss_->AddRule(false, talk_base::FP_ANY, talk_base::FD_ANY, kClientAddr1);
819 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
820 observer_.ice_connection_state_,
821 kIceCandidatesTimeout);
822
823 // Clearing the rules, session should move back to completed state.
824 fss_->ClearRules();
825 // Session is automatically calling OnSignalingReady after creation of
826 // new portallocator session which will allocate new set of candidates.
827
828 // TODO(bemasc): Change this to Completed once the details are standardized.
829 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionConnected,
830 observer_.ice_connection_state_,
831 kIceCandidatesTimeout);
832 }
833
834 void VerifyTransportType(const std::string& content_name,
835 cricket::TransportProtocol protocol) {
836 const cricket::Transport* transport = session_->GetTransport(content_name);
837 ASSERT_TRUE(transport != NULL);
838 EXPECT_EQ(protocol, transport->protocol());
839 }
840
841 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
842 void AddCNCodecs() {
843 // Add kTelephoneEventCodec for dtmf test.
844 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
845 codecs.push_back(kCNCodec1);
846 codecs.push_back(kCNCodec2);
847 media_engine_->SetAudioCodecs(codecs);
848 desc_factory_->set_audio_codecs(codecs);
849 }
850
851 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
852 const cricket::ContentDescription* description = content->description;
853 ASSERT(description != NULL);
854 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000855 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 ASSERT(audio_content_desc != NULL);
857 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
858 if (audio_content_desc->codecs()[i].name == "CN")
859 return false;
860 }
861 return true;
862 }
863
864 void SetLocalDescriptionWithDataChannel() {
865 webrtc::DataChannelInit dci;
866 dci.reliable = false;
867 session_->CreateDataChannel("datachannel", &dci);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000868 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 SetLocalDescriptionWithoutError(offer);
870 }
871
wu@webrtc.org91053e72013-08-10 07:18:04 +0000872 void VerifyMultipleAsyncCreateDescription(
873 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000874 InitWithDtls(!success);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000875
876 if (type == CreateSessionDescriptionRequest::kAnswer) {
877 cricket::MediaSessionOptions options;
878 scoped_ptr<JsepSessionDescription> offer(
879 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
880 ASSERT_TRUE(offer.get() != NULL);
881 SetRemoteDescriptionWithoutError(offer.release());
882 }
883
884 const int kNumber = 3;
885 talk_base::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
886 observers[kNumber];
887 for (int i = 0; i < kNumber; ++i) {
888 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
889 if (type == CreateSessionDescriptionRequest::kOffer) {
890 session_->CreateOffer(observers[i], NULL);
891 } else {
892 session_->CreateAnswer(observers[i], NULL);
893 }
894 }
895
896 WebRtcSessionCreateSDPObserverForTest::State expected_state =
897 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
898 WebRtcSessionCreateSDPObserverForTest::kFailed;
899
900 for (int i = 0; i < kNumber; ++i) {
901 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
902 if (success) {
903 EXPECT_TRUE(observers[i]->description() != NULL);
904 } else {
905 EXPECT_TRUE(observers[i]->description() == NULL);
906 }
907 }
908 }
909
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 cricket::FakeMediaEngine* media_engine_;
911 cricket::FakeDataEngine* data_engine_;
912 cricket::FakeDeviceManager* device_manager_;
913 talk_base::scoped_ptr<cricket::ChannelManager> channel_manager_;
914 talk_base::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000915 talk_base::scoped_ptr<talk_base::SSLIdentity> identity_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 talk_base::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
917 talk_base::scoped_ptr<talk_base::PhysicalSocketServer> pss_;
918 talk_base::scoped_ptr<talk_base::VirtualSocketServer> vss_;
919 talk_base::scoped_ptr<talk_base::FirewallSocketServer> fss_;
920 talk_base::SocketServerScope ss_scope_;
921 cricket::TestStunServer stun_server_;
922 talk_base::FakeNetworkManager network_manager_;
923 cricket::BasicPortAllocator allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000924 PeerConnectionFactoryInterface::Options options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 talk_base::scoped_ptr<FakeConstraints> constraints_;
926 FakeMediaStreamSignaling mediastream_signaling_;
927 talk_base::scoped_ptr<WebRtcSessionForTest> session_;
928 MockIceObserver observer_;
929 cricket::FakeVideoMediaChannel* video_channel_;
930 cricket::FakeVoiceMediaChannel* voice_channel_;
931};
932
933TEST_F(WebRtcSessionTest, TestInitialize) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000934 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935}
936
937TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
938 InitWithDtls();
939}
940
wu@webrtc.org91053e72013-08-10 07:18:04 +0000941// Verifies that WebRtcSession uses SEC_REQUIRED by default.
942TEST_F(WebRtcSessionTest, TestDefaultSetSecurePolicy) {
943 Init(NULL);
944 EXPECT_EQ(cricket::SEC_REQUIRED, session_->secure_policy());
945}
946
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947TEST_F(WebRtcSessionTest, TestSessionCandidates) {
948 TestSessionCandidatesWithBundleRtcpMux(false, false);
949}
950
951// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
952// with rtcp-mux and/or bundle.
953TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
954 TestSessionCandidatesWithBundleRtcpMux(false, true);
955}
956
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
958 TestSessionCandidatesWithBundleRtcpMux(true, true);
959}
960
961TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
962 AddInterface(kClientAddr1);
963 AddInterface(kClientAddr2);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000964 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000965 mediastream_signaling_.SendAudioVideoStream1();
966 InitiateCall();
967 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
968 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
969 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
970}
971
972TEST_F(WebRtcSessionTest, TestStunError) {
973 AddInterface(kClientAddr1);
974 AddInterface(kClientAddr2);
975 fss_->AddRule(false, talk_base::FP_UDP, talk_base::FD_ANY, kClientAddr1);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000976 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977 mediastream_signaling_.SendAudioVideoStream1();
978 InitiateCall();
979 // Since kClientAddr1 is blocked, not expecting stun candidates for it.
980 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
981 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
982 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
983}
984
985// Test creating offers and receive answers and make sure the
986// media engine creates the expected send and receive streams.
987TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000988 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000990 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 const std::string session_id_orig = offer->session_id();
992 const std::string session_version_orig = offer->session_version();
993 SetLocalDescriptionWithoutError(offer);
994
995 mediastream_signaling_.SendAudioVideoStream2();
996 SessionDescriptionInterface* answer =
997 CreateRemoteAnswer(session_->local_description());
998 SetRemoteDescriptionWithoutError(answer);
999
1000 video_channel_ = media_engine_->GetVideoChannel(0);
1001 voice_channel_ = media_engine_->GetVoiceChannel(0);
1002
1003 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1004 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1005
1006 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1007 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1008
1009 ASSERT_EQ(1u, video_channel_->send_streams().size());
1010 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1011 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1012 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1013
1014 // Create new offer without send streams.
1015 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001016 offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017
1018 // Verify the session id is the same and the session version is
1019 // increased.
1020 EXPECT_EQ(session_id_orig, offer->session_id());
1021 EXPECT_LT(talk_base::FromString<uint64>(session_version_orig),
1022 talk_base::FromString<uint64>(offer->session_version()));
1023
1024 SetLocalDescriptionWithoutError(offer);
1025
1026 mediastream_signaling_.SendAudioVideoStream2();
1027 answer = CreateRemoteAnswer(session_->local_description());
1028 SetRemoteDescriptionWithoutError(answer);
1029
1030 EXPECT_EQ(0u, video_channel_->send_streams().size());
1031 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1032
1033 // Make sure the receive streams have not changed.
1034 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1035 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1036 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1037 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1038}
1039
1040// Test receiving offers and creating answers and make sure the
1041// media engine creates the expected send and receive streams.
1042TEST_F(WebRtcSessionTest, TestReceiveOfferCreateAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001043 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001045 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001046 SetRemoteDescriptionWithoutError(offer);
1047
1048 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001049 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001050 SetLocalDescriptionWithoutError(answer);
1051
1052 const std::string session_id_orig = answer->session_id();
1053 const std::string session_version_orig = answer->session_version();
1054
1055 video_channel_ = media_engine_->GetVideoChannel(0);
1056 voice_channel_ = media_engine_->GetVoiceChannel(0);
1057
1058 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1059 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1060
1061 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1062 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1063
1064 ASSERT_EQ(1u, video_channel_->send_streams().size());
1065 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1066 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1067 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1068
1069 mediastream_signaling_.SendAudioVideoStream1And2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001070 offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001071 SetRemoteDescriptionWithoutError(offer);
1072
1073 // Answer by turning off all send streams.
1074 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001075 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076
1077 // Verify the session id is the same and the session version is
1078 // increased.
1079 EXPECT_EQ(session_id_orig, answer->session_id());
1080 EXPECT_LT(talk_base::FromString<uint64>(session_version_orig),
1081 talk_base::FromString<uint64>(answer->session_version()));
1082 SetLocalDescriptionWithoutError(answer);
1083
1084 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1085 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1086 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1087 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1088 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1089 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1090
1091 // Make sure we have no send streams.
1092 EXPECT_EQ(0u, video_channel_->send_streams().size());
1093 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1094}
1095
1096// Test we will return fail when apply an offer that doesn't have
1097// crypto enabled.
1098TEST_F(WebRtcSessionTest, SetNonCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001099 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 cricket::MediaSessionOptions options;
1101 options.has_video = true;
1102 JsepSessionDescription* offer = CreateRemoteOffer(
1103 options, cricket::SEC_DISABLED);
1104 ASSERT_TRUE(offer != NULL);
1105 VerifyNoCryptoParams(offer->description(), false);
1106 // SetRemoteDescription and SetLocalDescription will take the ownership of
1107 // the offer.
1108 SetRemoteDescriptionExpectError(kSdpWithoutCrypto, offer);
1109 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1110 ASSERT_TRUE(offer != NULL);
1111 SetLocalDescriptionExpectError(kSdpWithoutCrypto, offer);
1112}
1113
1114// Test we will return fail when apply an answer that doesn't have
1115// crypto enabled.
1116TEST_F(WebRtcSessionTest, SetLocalNonCryptoAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001117 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001118 SessionDescriptionInterface* offer = NULL;
1119 SessionDescriptionInterface* answer = NULL;
1120 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1121 // SetRemoteDescription and SetLocalDescription will take the ownership of
1122 // the offer.
1123 SetRemoteDescriptionWithoutError(offer);
1124 SetLocalDescriptionExpectError(kSdpWithoutCrypto, answer);
1125}
1126
1127// Test we will return fail when apply an answer that doesn't have
1128// crypto enabled.
1129TEST_F(WebRtcSessionTest, SetRemoteNonCryptoAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001130 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131 SessionDescriptionInterface* offer = NULL;
1132 SessionDescriptionInterface* answer = NULL;
1133 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1134 // SetRemoteDescription and SetLocalDescription will take the ownership of
1135 // the offer.
1136 SetLocalDescriptionWithoutError(offer);
1137 SetRemoteDescriptionExpectError(kSdpWithoutCrypto, answer);
1138}
1139
1140// Test that we can create and set an offer with a DTLS fingerprint.
1141TEST_F(WebRtcSessionTest, CreateSetDtlsOffer) {
1142 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
1143 InitWithDtls();
1144 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001145 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001146 ASSERT_TRUE(offer != NULL);
1147 VerifyFingerprintStatus(offer->description(), true);
1148 // SetLocalDescription will take the ownership of the offer.
1149 SetLocalDescriptionWithoutError(offer);
1150}
1151
1152// Test that we can process an offer with a DTLS fingerprint
1153// and that we return an answer with a fingerprint.
1154TEST_F(WebRtcSessionTest, ReceiveDtlsOfferCreateAnswer) {
1155 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
1156 InitWithDtls();
1157 SetFactoryDtlsSrtp();
1158 cricket::MediaSessionOptions options;
1159 options.has_video = true;
1160 JsepSessionDescription* offer = CreateRemoteOffer(options);
1161 ASSERT_TRUE(offer != NULL);
1162 VerifyFingerprintStatus(offer->description(), true);
1163
1164 // SetRemoteDescription will take the ownership of the offer.
1165 SetRemoteDescriptionWithoutError(offer);
1166
1167 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001168 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001169 ASSERT_TRUE(answer != NULL);
1170 VerifyFingerprintStatus(answer->description(), true);
1171 // Check that we don't have an a=crypto line in the answer.
1172 VerifyNoCryptoParams(answer->description(), true);
1173
1174 // Now set the local description, which should work, even without a=crypto.
1175 SetLocalDescriptionWithoutError(answer);
1176}
1177
1178// Test that even if we support DTLS, if the other side didn't offer a
1179// fingerprint, we don't either.
1180TEST_F(WebRtcSessionTest, ReceiveNoDtlsOfferCreateAnswer) {
1181 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
1182 InitWithDtls();
1183 cricket::MediaSessionOptions options;
1184 options.has_video = true;
1185 JsepSessionDescription* offer = CreateRemoteOffer(
1186 options, cricket::SEC_REQUIRED);
1187 ASSERT_TRUE(offer != NULL);
1188 VerifyFingerprintStatus(offer->description(), false);
1189
1190 // SetRemoteDescription will take the ownership of
1191 // the offer.
1192 SetRemoteDescriptionWithoutError(offer);
1193
1194 // Verify that we don't get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001195 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001196 ASSERT_TRUE(answer != NULL);
1197 VerifyFingerprintStatus(answer->description(), false);
1198
1199 // Now set the local description.
1200 SetLocalDescriptionWithoutError(answer);
1201}
1202
1203TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001204 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001205 mediastream_signaling_.SendNothing();
1206 // SetLocalDescription take ownership of offer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001207 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001208 SetLocalDescriptionWithoutError(offer);
1209
1210 // SetLocalDescription take ownership of offer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001211 SessionDescriptionInterface* offer2 = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001212 SetLocalDescriptionWithoutError(offer2);
1213}
1214
1215TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001216 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001217 mediastream_signaling_.SendNothing();
1218 // SetLocalDescription take ownership of offer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001219 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001220 SetRemoteDescriptionWithoutError(offer);
1221
wu@webrtc.org91053e72013-08-10 07:18:04 +00001222 SessionDescriptionInterface* offer2 = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001223 SetRemoteDescriptionWithoutError(offer2);
1224}
1225
1226TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001227 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001228 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001229 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001230 SetLocalDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001231 offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 SetRemoteDescriptionExpectError(
1233 "Called with type in wrong state, type: offer state: STATE_SENTINITIATE",
1234 offer);
1235}
1236
1237TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001238 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001239 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001240 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001241 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001242 offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001243 SetLocalDescriptionExpectError(
1244 "Called with type in wrong state, type: "
1245 "offer state: STATE_RECEIVEDINITIATE",
1246 offer);
1247}
1248
1249TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001250 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251 mediastream_signaling_.SendNothing();
1252 SessionDescriptionInterface* offer = CreateRemoteOffer();
1253 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1254
1255 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001256 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001257 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1258 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1259
1260 mediastream_signaling_.SendAudioVideoStream1();
1261 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001262 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1264
1265 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1266
1267 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001268 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001269 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1270}
1271
1272TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001273 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001274 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001275 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1277
1278 JsepSessionDescription* pranswer =
1279 CreateRemoteAnswer(session_->local_description());
1280 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1281
1282 SetRemoteDescriptionExpectState(pranswer,
1283 BaseSession::STATE_RECEIVEDPRACCEPT);
1284
1285 mediastream_signaling_.SendAudioVideoStream1();
1286 JsepSessionDescription* pranswer2 =
1287 CreateRemoteAnswer(session_->local_description());
1288 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1289
1290 SetRemoteDescriptionExpectState(pranswer2,
1291 BaseSession::STATE_RECEIVEDPRACCEPT);
1292
1293 mediastream_signaling_.SendAudioVideoStream2();
1294 SessionDescriptionInterface* answer =
1295 CreateRemoteAnswer(session_->local_description());
1296 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1297}
1298
1299TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001300 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301 mediastream_signaling_.SendNothing();
1302 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001303 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304 SessionDescriptionInterface* answer =
1305 CreateRemoteAnswer(offer.get());
1306 SetLocalDescriptionExpectError(
1307 "Called with type in wrong state, type: answer state: STATE_INIT",
1308 answer);
1309}
1310
1311TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001312 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001313 mediastream_signaling_.SendNothing();
1314 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001315 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001316 SessionDescriptionInterface* answer =
1317 CreateRemoteAnswer(offer.get());
1318 SetRemoteDescriptionExpectError(
1319 "Called with type in wrong state, type: answer state: STATE_INIT",
1320 answer);
1321}
1322
1323TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001324 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001325 mediastream_signaling_.SendAudioVideoStream1();
1326
1327 cricket::Candidate candidate;
1328 candidate.set_component(1);
1329 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1330
1331 // Fail since we have not set a offer description.
1332 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1333
wu@webrtc.org91053e72013-08-10 07:18:04 +00001334 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001335 SetLocalDescriptionWithoutError(offer);
1336 // Candidate should be allowed to add before remote description.
1337 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1338 candidate.set_component(2);
1339 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1340 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1341
1342 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1343 session_->local_description());
1344 SetRemoteDescriptionWithoutError(answer);
1345
1346 // Verifying the candidates are copied properly from internal vector.
1347 const SessionDescriptionInterface* remote_desc =
1348 session_->remote_description();
1349 ASSERT_TRUE(remote_desc != NULL);
1350 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1351 const IceCandidateCollection* candidates =
1352 remote_desc->candidates(kMediaContentIndex0);
1353 ASSERT_EQ(2u, candidates->count());
1354 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1355 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1356 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1357 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1358
1359 candidate.set_component(2);
1360 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1361 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
1362 ASSERT_EQ(3u, candidates->count());
1363
1364 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1365 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1366}
1367
1368// Test that a remote candidate is added to the remote session description and
1369// that it is retained if the remote session description is changed.
1370TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001371 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001372 cricket::Candidate candidate1;
1373 candidate1.set_component(1);
1374 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1375 candidate1);
1376 mediastream_signaling_.SendAudioVideoStream1();
1377 CreateAndSetRemoteOfferAndLocalAnswer();
1378
1379 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1380 const SessionDescriptionInterface* remote_desc =
1381 session_->remote_description();
1382 ASSERT_TRUE(remote_desc != NULL);
1383 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1384 const IceCandidateCollection* candidates =
1385 remote_desc->candidates(kMediaContentIndex0);
1386 ASSERT_EQ(1u, candidates->count());
1387 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1388
1389 // Update the RemoteSessionDescription with a new session description and
1390 // a candidate and check that the new remote session description contains both
1391 // candidates.
1392 SessionDescriptionInterface* offer = CreateRemoteOffer();
1393 cricket::Candidate candidate2;
1394 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1395 candidate2);
1396 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1397 SetRemoteDescriptionWithoutError(offer);
1398
1399 remote_desc = session_->remote_description();
1400 ASSERT_TRUE(remote_desc != NULL);
1401 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1402 candidates = remote_desc->candidates(kMediaContentIndex0);
1403 ASSERT_EQ(2u, candidates->count());
1404 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1405 // Username and password have be updated with the TransportInfo of the
1406 // SessionDescription, won't be equal to the original one.
1407 candidate2.set_username(candidates->at(0)->candidate().username());
1408 candidate2.set_password(candidates->at(0)->candidate().password());
1409 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1410 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1411 // No need to verify the username and password.
1412 candidate1.set_username(candidates->at(1)->candidate().username());
1413 candidate1.set_password(candidates->at(1)->candidate().password());
1414 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1415
1416 // Test that the candidate is ignored if we can add the same candidate again.
1417 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1418}
1419
1420// Test that local candidates are added to the local session description and
1421// that they are retained if the local session description is changed.
1422TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
1423 AddInterface(kClientAddr1);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001424 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001425 mediastream_signaling_.SendAudioVideoStream1();
1426 CreateAndSetRemoteOfferAndLocalAnswer();
1427
1428 const SessionDescriptionInterface* local_desc = session_->local_description();
1429 const IceCandidateCollection* candidates =
1430 local_desc->candidates(kMediaContentIndex0);
1431 ASSERT_TRUE(candidates != NULL);
1432 EXPECT_EQ(0u, candidates->count());
1433
1434 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1435
1436 local_desc = session_->local_description();
1437 candidates = local_desc->candidates(kMediaContentIndex0);
1438 ASSERT_TRUE(candidates != NULL);
1439 EXPECT_LT(0u, candidates->count());
1440 candidates = local_desc->candidates(1);
1441 ASSERT_TRUE(candidates != NULL);
1442 EXPECT_LT(0u, candidates->count());
1443
1444 // Update the session descriptions.
1445 mediastream_signaling_.SendAudioVideoStream1();
1446 CreateAndSetRemoteOfferAndLocalAnswer();
1447
1448 local_desc = session_->local_description();
1449 candidates = local_desc->candidates(kMediaContentIndex0);
1450 ASSERT_TRUE(candidates != NULL);
1451 EXPECT_LT(0u, candidates->count());
1452 candidates = local_desc->candidates(1);
1453 ASSERT_TRUE(candidates != NULL);
1454 EXPECT_LT(0u, candidates->count());
1455}
1456
1457// Test that we can set a remote session description with remote candidates.
1458TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001459 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001460
1461 cricket::Candidate candidate1;
1462 candidate1.set_component(1);
1463 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
1464 candidate1);
1465 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001466 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467
1468 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
1469 SetRemoteDescriptionWithoutError(offer);
1470
1471 const SessionDescriptionInterface* remote_desc =
1472 session_->remote_description();
1473 ASSERT_TRUE(remote_desc != NULL);
1474 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1475 const IceCandidateCollection* candidates =
1476 remote_desc->candidates(kMediaContentIndex0);
1477 ASSERT_EQ(1u, candidates->count());
1478 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1479
wu@webrtc.org91053e72013-08-10 07:18:04 +00001480 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481 SetLocalDescriptionWithoutError(answer);
1482}
1483
1484// Test that offers and answers contains ice candidates when Ice candidates have
1485// been gathered.
1486TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
1487 AddInterface(kClientAddr1);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001488 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001489 mediastream_signaling_.SendAudioVideoStream1();
1490 // Ice is started but candidates are not provided until SetLocalDescription
1491 // is called.
1492 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1493 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1494 CreateAndSetRemoteOfferAndLocalAnswer();
1495 // Wait until at least one local candidate has been collected.
1496 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
1497 kIceCandidatesTimeout);
1498 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
1499 kIceCandidatesTimeout);
1500
1501 talk_base::scoped_ptr<SessionDescriptionInterface> local_offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001502 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
1504 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
1505 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
1506 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
1507
1508 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
1509 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001510 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001511 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
1512 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
1513 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
1514 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
1515 SetLocalDescriptionWithoutError(answer);
1516}
1517
1518// Verifies TransportProxy and media channels are created with content names
1519// present in the SessionDescription.
1520TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001521 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001522 mediastream_signaling_.SendAudioVideoStream1();
1523 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001524 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525
1526 // CreateOffer creates session description with the content names "audio" and
1527 // "video". Goal is to modify these content names and verify transport channel
1528 // proxy in the BaseSession, as proxies are created with the content names
1529 // present in SDP.
1530 std::string sdp;
1531 EXPECT_TRUE(offer->ToString(&sdp));
1532 const std::string kAudioMid = "a=mid:audio";
1533 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
1534 const std::string kVideoMid = "a=mid:video";
1535 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
1536
1537 // Replacing |audio| with |audio_content_name|.
1538 talk_base::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
1539 kAudioMidReplaceStr.c_str(),
1540 kAudioMidReplaceStr.length(),
1541 &sdp);
1542 // Replacing |video| with |video_content_name|.
1543 talk_base::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
1544 kVideoMidReplaceStr.c_str(),
1545 kVideoMidReplaceStr.length(),
1546 &sdp);
1547
1548 SessionDescriptionInterface* modified_offer =
1549 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
1550
1551 SetRemoteDescriptionWithoutError(modified_offer);
1552
1553 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00001554 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555 SetLocalDescriptionWithoutError(answer);
1556
1557 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
1558 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
1559 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
1560 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
1561}
1562
1563// Test that an offer contains the correct media content descriptions based on
1564// the send streams when no constraints have been set.
1565TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001566 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001567 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001568 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569 ASSERT_TRUE(offer != NULL);
1570 const cricket::ContentInfo* content =
1571 cricket::GetFirstAudioContent(offer->description());
1572 EXPECT_TRUE(content != NULL);
1573 content = cricket::GetFirstVideoContent(offer->description());
1574 EXPECT_TRUE(content == NULL);
1575}
1576
1577// Test that an offer contains the correct media content descriptions based on
1578// the send streams when no constraints have been set.
1579TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001580 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 // Test Audio only offer.
1582 mediastream_signaling_.UseOptionsAudioOnly();
1583 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001584 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585 const cricket::ContentInfo* content =
1586 cricket::GetFirstAudioContent(offer->description());
1587 EXPECT_TRUE(content != NULL);
1588 content = cricket::GetFirstVideoContent(offer->description());
1589 EXPECT_TRUE(content == NULL);
1590
1591 // Test Audio / Video offer.
1592 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001593 offer.reset(CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594 content = cricket::GetFirstAudioContent(offer->description());
1595 EXPECT_TRUE(content != NULL);
1596 content = cricket::GetFirstVideoContent(offer->description());
1597 EXPECT_TRUE(content != NULL);
1598}
1599
1600// Test that an offer contains no media content descriptions if
1601// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
1602TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001603 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 webrtc::FakeConstraints constraints_no_receive;
1605 constraints_no_receive.SetMandatoryReceiveAudio(false);
1606 constraints_no_receive.SetMandatoryReceiveVideo(false);
1607
1608 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001609 CreateOffer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 ASSERT_TRUE(offer != NULL);
1611 const cricket::ContentInfo* content =
1612 cricket::GetFirstAudioContent(offer->description());
1613 EXPECT_TRUE(content == NULL);
1614 content = cricket::GetFirstVideoContent(offer->description());
1615 EXPECT_TRUE(content == NULL);
1616}
1617
1618// Test that an offer contains only audio media content descriptions if
1619// kOfferToReceiveAudio constraints are set to true.
1620TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001621 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622 webrtc::FakeConstraints constraints_audio_only;
1623 constraints_audio_only.SetMandatoryReceiveAudio(true);
1624 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001625 CreateOffer(&constraints_audio_only));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626
1627 const cricket::ContentInfo* content =
1628 cricket::GetFirstAudioContent(offer->description());
1629 EXPECT_TRUE(content != NULL);
1630 content = cricket::GetFirstVideoContent(offer->description());
1631 EXPECT_TRUE(content == NULL);
1632}
1633
1634// Test that an offer contains audio and video media content descriptions if
1635// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
1636TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001637 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638 // Test Audio / Video offer.
1639 webrtc::FakeConstraints constraints_audio_video;
1640 constraints_audio_video.SetMandatoryReceiveAudio(true);
1641 constraints_audio_video.SetMandatoryReceiveVideo(true);
1642 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001643 CreateOffer(&constraints_audio_video));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001644 const cricket::ContentInfo* content =
1645 cricket::GetFirstAudioContent(offer->description());
1646
1647 EXPECT_TRUE(content != NULL);
1648 content = cricket::GetFirstVideoContent(offer->description());
1649 EXPECT_TRUE(content != NULL);
1650
1651 // TODO(perkj): Should the direction be set to SEND_ONLY if
1652 // The constraints is set to not receive audio or video but a track is added?
1653}
1654
1655// Test that an answer can not be created if the last remote description is not
1656// an offer.
1657TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001658 Init(NULL);
1659 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660 SetLocalDescriptionWithoutError(offer);
1661 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
1662 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001663 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001664}
1665
1666// Test that an answer contains the correct media content descriptions when no
1667// constraints have been set.
1668TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001669 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670 // Create a remote offer with audio and video content.
1671 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1672 SetRemoteDescriptionWithoutError(offer.release());
1673 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001674 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 const cricket::ContentInfo* content =
1676 cricket::GetFirstAudioContent(answer->description());
1677 ASSERT_TRUE(content != NULL);
1678 EXPECT_FALSE(content->rejected);
1679
1680 content = cricket::GetFirstVideoContent(answer->description());
1681 ASSERT_TRUE(content != NULL);
1682 EXPECT_FALSE(content->rejected);
1683}
1684
1685// Test that an answer contains the correct media content descriptions when no
1686// constraints have been set and the offer only contain audio.
1687TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001688 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 // Create a remote offer with audio only.
1690 cricket::MediaSessionOptions options;
1691 options.has_audio = true;
1692 options.has_video = false;
1693 talk_base::scoped_ptr<JsepSessionDescription> offer(
1694 CreateRemoteOffer(options));
1695 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
1696 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
1697
1698 SetRemoteDescriptionWithoutError(offer.release());
1699 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001700 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001701 const cricket::ContentInfo* content =
1702 cricket::GetFirstAudioContent(answer->description());
1703 ASSERT_TRUE(content != NULL);
1704 EXPECT_FALSE(content->rejected);
1705
1706 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
1707}
1708
1709// Test that an answer contains the correct media content descriptions when no
1710// constraints have been set.
1711TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001712 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713 // Create a remote offer with audio and video content.
1714 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1715 SetRemoteDescriptionWithoutError(offer.release());
1716 // Test with a stream with tracks.
1717 mediastream_signaling_.SendAudioVideoStream1();
1718 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001719 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001720 const cricket::ContentInfo* content =
1721 cricket::GetFirstAudioContent(answer->description());
1722 ASSERT_TRUE(content != NULL);
1723 EXPECT_FALSE(content->rejected);
1724
1725 content = cricket::GetFirstVideoContent(answer->description());
1726 ASSERT_TRUE(content != NULL);
1727 EXPECT_FALSE(content->rejected);
1728}
1729
1730// Test that an answer contains the correct media content descriptions when
1731// constraints have been set but no stream is sent.
1732TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001733 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001734 // Create a remote offer with audio and video content.
1735 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1736 SetRemoteDescriptionWithoutError(offer.release());
1737
1738 webrtc::FakeConstraints constraints_no_receive;
1739 constraints_no_receive.SetMandatoryReceiveAudio(false);
1740 constraints_no_receive.SetMandatoryReceiveVideo(false);
1741
1742 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001743 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744 const cricket::ContentInfo* content =
1745 cricket::GetFirstAudioContent(answer->description());
1746 ASSERT_TRUE(content != NULL);
1747 EXPECT_TRUE(content->rejected);
1748
1749 content = cricket::GetFirstVideoContent(answer->description());
1750 ASSERT_TRUE(content != NULL);
1751 EXPECT_TRUE(content->rejected);
1752}
1753
1754// Test that an answer contains the correct media content descriptions when
1755// constraints have been set and streams are sent.
1756TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001757 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 // Create a remote offer with audio and video content.
1759 talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
1760 SetRemoteDescriptionWithoutError(offer.release());
1761
1762 webrtc::FakeConstraints constraints_no_receive;
1763 constraints_no_receive.SetMandatoryReceiveAudio(false);
1764 constraints_no_receive.SetMandatoryReceiveVideo(false);
1765
1766 // Test with a stream with tracks.
1767 mediastream_signaling_.SendAudioVideoStream1();
1768 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001769 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770
1771 // TODO(perkj): Should the direction be set to SEND_ONLY?
1772 const cricket::ContentInfo* content =
1773 cricket::GetFirstAudioContent(answer->description());
1774 ASSERT_TRUE(content != NULL);
1775 EXPECT_FALSE(content->rejected);
1776
1777 // TODO(perkj): Should the direction be set to SEND_ONLY?
1778 content = cricket::GetFirstVideoContent(answer->description());
1779 ASSERT_TRUE(content != NULL);
1780 EXPECT_FALSE(content->rejected);
1781}
1782
1783TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
1784 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001785 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 webrtc::FakeConstraints constraints;
1787 constraints.SetOptionalVAD(false);
1788 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001789 CreateOffer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 const cricket::ContentInfo* content =
1791 cricket::GetFirstAudioContent(offer->description());
1792 EXPECT_TRUE(content != NULL);
1793 EXPECT_TRUE(VerifyNoCNCodecs(content));
1794}
1795
1796TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
1797 AddCNCodecs();
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;
1804 constraints.SetOptionalVAD(false);
1805 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001806 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 const cricket::ContentInfo* content =
1808 cricket::GetFirstAudioContent(answer->description());
1809 ASSERT_TRUE(content != NULL);
1810 EXPECT_TRUE(VerifyNoCNCodecs(content));
1811}
1812
1813// This test verifies the call setup when remote answer with audio only and
1814// later updates with video.
1815TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001816 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
1818 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
1819
1820 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001821 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822
1823 cricket::MediaSessionOptions options;
1824 options.has_video = false;
1825 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
1826
1827 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1828 // and answer;
1829 SetLocalDescriptionWithoutError(offer);
1830 SetRemoteDescriptionWithoutError(answer);
1831
1832 video_channel_ = media_engine_->GetVideoChannel(0);
1833 voice_channel_ = media_engine_->GetVoiceChannel(0);
1834
1835 ASSERT_TRUE(video_channel_ == NULL);
1836
1837 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
1838 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1839 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
1840
1841 // Let the remote end update the session descriptions, with Audio and Video.
1842 mediastream_signaling_.SendAudioVideoStream2();
1843 CreateAndSetRemoteOfferAndLocalAnswer();
1844
1845 video_channel_ = media_engine_->GetVideoChannel(0);
1846 voice_channel_ = media_engine_->GetVoiceChannel(0);
1847
1848 ASSERT_TRUE(video_channel_ != NULL);
1849 ASSERT_TRUE(voice_channel_ != NULL);
1850
1851 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1852 ASSERT_EQ(1u, video_channel_->send_streams().size());
1853 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
1854 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
1855 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1856 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1857 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
1858 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
1859
1860 // Change session back to audio only.
1861 mediastream_signaling_.UseOptionsAudioOnly();
1862 CreateAndSetRemoteOfferAndLocalAnswer();
1863
1864 EXPECT_EQ(0u, video_channel_->recv_streams().size());
1865 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1866 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
1867 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1868 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
1869}
1870
1871// This test verifies the call setup when remote answer with video only and
1872// later updates with audio.
1873TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001874 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
1876 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
1877 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001878 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879
1880 cricket::MediaSessionOptions options;
1881 options.has_audio = false;
1882 options.has_video = true;
1883 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1884 offer, options, cricket::SEC_ENABLED);
1885
1886 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1887 // and answer.
1888 SetLocalDescriptionWithoutError(offer);
1889 SetRemoteDescriptionWithoutError(answer);
1890
1891 video_channel_ = media_engine_->GetVideoChannel(0);
1892 voice_channel_ = media_engine_->GetVoiceChannel(0);
1893
1894 ASSERT_TRUE(voice_channel_ == NULL);
1895 ASSERT_TRUE(video_channel_ != NULL);
1896
1897 EXPECT_EQ(0u, video_channel_->recv_streams().size());
1898 ASSERT_EQ(1u, video_channel_->send_streams().size());
1899 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
1900
1901 // Update the session descriptions, with Audio and Video.
1902 mediastream_signaling_.SendAudioVideoStream2();
1903 CreateAndSetRemoteOfferAndLocalAnswer();
1904
1905 voice_channel_ = media_engine_->GetVoiceChannel(0);
1906 ASSERT_TRUE(voice_channel_ != NULL);
1907
1908 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1909 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1910 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
1911 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
1912
1913 // Change session back to video only.
1914 mediastream_signaling_.UseOptionsVideoOnly();
1915 CreateAndSetRemoteOfferAndLocalAnswer();
1916
1917 video_channel_ = media_engine_->GetVideoChannel(0);
1918 voice_channel_ = media_engine_->GetVoiceChannel(0);
1919
1920 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1921 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
1922 ASSERT_EQ(1u, video_channel_->send_streams().size());
1923 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
1924}
1925
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001926TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001927 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928 mediastream_signaling_.SendAudioVideoStream1();
1929 scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001930 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001931 VerifyCryptoParams(offer->description());
1932 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001933 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001934 VerifyCryptoParams(answer->description());
1935}
1936
1937TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00001938 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001939 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001940 mediastream_signaling_.SendAudioVideoStream1();
1941 scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001942 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001943 VerifyNoCryptoParams(offer->description(), false);
1944}
1945
1946TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001947 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001948 VerifyAnswerFromNonCryptoOffer();
1949}
1950
1951TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001952 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001953 VerifyAnswerFromCryptoOffer();
1954}
1955
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001956// This test verifies that setLocalDescription fails if
1957// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
1958TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
1959 Init(NULL);
1960 mediastream_signaling_.SendAudioVideoStream1();
1961 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
1962 std::string sdp;
1963 RemoveIceUfragPwdLines(offer.get(), &sdp);
1964 SessionDescriptionInterface* modified_offer =
1965 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
1966 SetLocalDescriptionExpectError(kSdpWithoutIceUfragPwd, modified_offer);
1967}
1968
1969// This test verifies that setRemoteDescription fails if
1970// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
1971TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
1972 Init(NULL);
1973 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
1974 std::string sdp;
1975 RemoveIceUfragPwdLines(offer.get(), &sdp);
1976 SessionDescriptionInterface* modified_offer =
1977 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
1978 SetRemoteDescriptionExpectError(kSdpWithoutIceUfragPwd, modified_offer);
1979}
1980
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) {
1982 // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in
1983 // local description is removed by the application, BUNDLE flag should be
1984 // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001985 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) ==
1987 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
1988 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001989 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990 cricket::SessionDescription* offer_copy =
1991 offer->description()->Copy();
1992 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
1993 JsepSessionDescription* modified_offer =
1994 new JsepSessionDescription(JsepSessionDescription::kOffer);
1995 modified_offer->Initialize(offer_copy, "1", "1");
1996
1997 SetLocalDescriptionWithoutError(modified_offer);
1998 EXPECT_FALSE(allocator_.flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE);
1999}
2000
2001TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002002 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003 mediastream_signaling_.SendAudioVideoStream1();
2004 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) ==
2005 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
2006 FakeConstraints constraints;
2007 constraints.SetMandatoryUseRtpMux(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002008 SessionDescriptionInterface* offer = CreateOffer(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009 SetLocalDescriptionWithoutError(offer);
2010 mediastream_signaling_.SendAudioVideoStream2();
2011 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
2012 CreateRemoteAnswer(session_->local_description()));
2013 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2014 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2015 JsepSessionDescription* modified_answer =
2016 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2017 modified_answer->Initialize(answer_copy, "1", "1");
2018 SetRemoteDescriptionWithoutError(modified_answer);
2019 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) ==
2020 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
2021
2022 video_channel_ = media_engine_->GetVideoChannel(0);
2023 voice_channel_ = media_engine_->GetVoiceChannel(0);
2024
2025 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2026 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
2027
2028 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2029 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
2030
2031 ASSERT_EQ(1u, video_channel_->send_streams().size());
2032 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
2033 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2034 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
2035}
2036
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002037// This test verifies that SetLocalDescription and SetRemoteDescription fails
2038// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2039TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002040 WebRtcSessionTest::Init(NULL);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002041 mediastream_signaling_.SendAudioVideoStream1();
2042 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) ==
2043 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
2044 FakeConstraints constraints;
2045 constraints.SetMandatoryUseRtpMux(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002046 SessionDescriptionInterface* offer = CreateOffer(&constraints);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002047 std::string offer_str;
2048 offer->ToString(&offer_str);
2049 // Disable rtcp-mux
2050 const std::string rtcp_mux = "rtcp-mux";
2051 const std::string xrtcp_mux = "xrtcp-mux";
2052 talk_base::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
2053 xrtcp_mux.c_str(), xrtcp_mux.length(),
2054 &offer_str);
2055 JsepSessionDescription *local_offer =
2056 new JsepSessionDescription(JsepSessionDescription::kOffer);
2057 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
2058 SetLocalDescriptionExpectError(kBundleWithoutRtcpMux, local_offer);
2059 JsepSessionDescription *remote_offer =
2060 new JsepSessionDescription(JsepSessionDescription::kOffer);
2061 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
2062 SetRemoteDescriptionExpectError(kBundleWithoutRtcpMux, remote_offer);
2063 // Trying unmodified SDP.
2064 SetLocalDescriptionWithoutError(offer);
2065}
2066
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067TEST_F(WebRtcSessionTest, SetAudioPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002068 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069 mediastream_signaling_.SendAudioVideoStream1();
2070 CreateAndSetRemoteOfferAndLocalAnswer();
2071 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2072 ASSERT_TRUE(channel != NULL);
2073 ASSERT_EQ(1u, channel->recv_streams().size());
2074 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2075 double left_vol, right_vol;
2076 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2077 EXPECT_EQ(1, left_vol);
2078 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002079 talk_base::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
2080 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002081 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2082 EXPECT_EQ(0, left_vol);
2083 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002084 EXPECT_EQ(0, renderer->channel_id());
2085 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002086 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2087 EXPECT_EQ(1, left_vol);
2088 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002089 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090}
2091
2092TEST_F(WebRtcSessionTest, SetAudioSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002093 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094 mediastream_signaling_.SendAudioVideoStream1();
2095 CreateAndSetRemoteOfferAndLocalAnswer();
2096 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2097 ASSERT_TRUE(channel != NULL);
2098 ASSERT_EQ(1u, channel->send_streams().size());
2099 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2100 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2101
2102 cricket::AudioOptions options;
2103 options.echo_cancellation.Set(true);
2104
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002105 talk_base::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
2106 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2108 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002109 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002111 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2113 bool value;
2114 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2115 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002116 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117}
2118
2119TEST_F(WebRtcSessionTest, SetVideoPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002120 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121 mediastream_signaling_.SendAudioVideoStream1();
2122 CreateAndSetRemoteOfferAndLocalAnswer();
2123 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2124 ASSERT_TRUE(channel != NULL);
2125 ASSERT_LT(0u, channel->renderers().size());
2126 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2127 ASSERT_EQ(1u, channel->recv_streams().size());
2128 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2129 cricket::FakeVideoRenderer renderer;
2130 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2131 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2132 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2133 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2134}
2135
2136TEST_F(WebRtcSessionTest, SetVideoSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002137 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 mediastream_signaling_.SendAudioVideoStream1();
2139 CreateAndSetRemoteOfferAndLocalAnswer();
2140 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2141 ASSERT_TRUE(channel != NULL);
2142 ASSERT_EQ(1u, channel->send_streams().size());
2143 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2144 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2145 cricket::VideoOptions* options = NULL;
2146 session_->SetVideoSend(send_ssrc, false, options);
2147 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2148 session_->SetVideoSend(send_ssrc, true, options);
2149 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2150}
2151
2152TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2153 TestCanInsertDtmf(false);
2154}
2155
2156TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2157 TestCanInsertDtmf(true);
2158}
2159
2160TEST_F(WebRtcSessionTest, InsertDtmf) {
2161 // Setup
wu@webrtc.org91053e72013-08-10 07:18:04 +00002162 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 mediastream_signaling_.SendAudioVideoStream1();
2164 CreateAndSetRemoteOfferAndLocalAnswer();
2165 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2166 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2167
2168 // Insert DTMF
2169 const int expected_flags = DF_SEND;
2170 const int expected_duration = 90;
2171 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2172 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2173 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2174
2175 // Verify
2176 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2177 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2178 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2179 expected_duration, expected_flags));
2180 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2181 expected_duration, expected_flags));
2182 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2183 expected_duration, expected_flags));
2184}
2185
2186// This test verifies the |initiator| flag when session initiates the call.
2187TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002188 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189 EXPECT_FALSE(session_->initiator());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002190 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2192 SetLocalDescriptionWithoutError(offer);
2193 EXPECT_TRUE(session_->initiator());
2194 SetRemoteDescriptionWithoutError(answer);
2195 EXPECT_TRUE(session_->initiator());
2196}
2197
2198// This test verifies the |initiator| flag when session receives the call.
2199TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002200 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201 EXPECT_FALSE(session_->initiator());
2202 SessionDescriptionInterface* offer = CreateRemoteOffer();
2203 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002204 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002205
2206 EXPECT_FALSE(session_->initiator());
2207 SetLocalDescriptionWithoutError(answer);
2208 EXPECT_FALSE(session_->initiator());
2209}
2210
2211// This test verifies the ice protocol type at initiator of the call
2212// if |a=ice-options:google-ice| is present in answer.
2213TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002214 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002216 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org723d6832013-07-12 16:04:50 +00002217 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002218 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219 SetLocalDescriptionWithoutError(offer);
2220 std::string sdp;
2221 EXPECT_TRUE(answer->ToString(&sdp));
2222 // Adding ice-options to the session level.
2223 InjectAfter("t=0 0\r\n",
2224 "a=ice-options:google-ice\r\n",
2225 &sdp);
2226 SessionDescriptionInterface* answer_with_gice =
2227 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2228 SetRemoteDescriptionWithoutError(answer_with_gice);
2229 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2230 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2231}
2232
2233// This test verifies the ice protocol type at initiator of the call
2234// if ICE RFC5245 is supported in answer.
2235TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002236 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002238 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2240 SetLocalDescriptionWithoutError(offer);
2241
2242 SetRemoteDescriptionWithoutError(answer);
2243 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2244 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2245}
2246
2247// This test verifies the ice protocol type at receiver side of the call if
2248// receiver decides to use google-ice.
2249TEST_F(WebRtcSessionTest, TestReceiverGIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002250 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002252 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.org723d6832013-07-12 16:04:50 +00002254 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002255 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256 std::string sdp;
2257 EXPECT_TRUE(answer->ToString(&sdp));
2258 // Adding ice-options to the session level.
2259 InjectAfter("t=0 0\r\n",
2260 "a=ice-options:google-ice\r\n",
2261 &sdp);
2262 SessionDescriptionInterface* answer_with_gice =
2263 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2264 SetLocalDescriptionWithoutError(answer_with_gice);
2265 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2266 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2267}
2268
2269// This test verifies the ice protocol type at receiver side of the call if
2270// receiver decides to use ice RFC 5245.
2271TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002272 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002273 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002274 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002276 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277 SetLocalDescriptionWithoutError(answer);
2278 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2279 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2280}
2281
2282// This test verifies the session state when ICE RFC5245 in offer and
2283// ICE google-ice in answer.
2284TEST_F(WebRtcSessionTest, TestIceOfferGIceOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002285 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286 mediastream_signaling_.SendAudioVideoStream1();
2287 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002288 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289 std::string offer_str;
2290 offer->ToString(&offer_str);
2291 // Disable google-ice
2292 const std::string gice_option = "google-ice";
2293 const std::string xgoogle_xice = "xgoogle-xice";
2294 talk_base::replace_substrs(gice_option.c_str(), gice_option.length(),
2295 xgoogle_xice.c_str(), xgoogle_xice.length(),
2296 &offer_str);
2297 JsepSessionDescription *ice_only_offer =
2298 new JsepSessionDescription(JsepSessionDescription::kOffer);
2299 EXPECT_TRUE((ice_only_offer)->Initialize(offer_str, NULL));
2300 SetLocalDescriptionWithoutError(ice_only_offer);
2301 std::string original_offer_sdp;
2302 EXPECT_TRUE(offer->ToString(&original_offer_sdp));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002303 SessionDescriptionInterface* pranswer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002304 CreateSessionDescription(JsepSessionDescription::kPrAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002305 original_offer_sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306 SetRemoteDescriptionExpectError(kPushDownPranswerTDFailed,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002307 pranswer_with_gice);
2308 SessionDescriptionInterface* answer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002309 CreateSessionDescription(JsepSessionDescription::kAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002310 original_offer_sdp, NULL);
henrike@webrtc.org723d6832013-07-12 16:04:50 +00002311 SetRemoteDescriptionExpectError(kPushDownAnswerTDFailed,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002312 answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002313}
2314
2315// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2316TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002317 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002319 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002320 SetLocalDescriptionWithoutError(offer);
2321 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
2322 CreateRemoteAnswer(session_->local_description()));
2323
2324 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2325 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002326 JsepSessionDescription* modified_answer =
2327 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328
2329 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2330 answer->session_id(),
2331 answer->session_version()));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002332 SetRemoteDescriptionExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333
2334 // Modifying content names.
2335 std::string sdp;
2336 EXPECT_TRUE(answer->ToString(&sdp));
2337 const std::string kAudioMid = "a=mid:audio";
2338 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2339
2340 // Replacing |audio| with |audio_content_name|.
2341 talk_base::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
2342 kAudioMidReplaceStr.c_str(),
2343 kAudioMidReplaceStr.length(),
2344 &sdp);
2345
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002346 SessionDescriptionInterface* modified_answer1 =
2347 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2348 SetRemoteDescriptionExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349
2350 SetRemoteDescriptionWithoutError(answer.release());
2351}
2352
2353// Verifying remote offer and local answer have matching m-lines as per
2354// RFC 3264.
2355TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002356 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357 mediastream_signaling_.SendAudioVideoStream1();
2358 SessionDescriptionInterface* offer = CreateRemoteOffer();
2359 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002360 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361
2362 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2363 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002364 JsepSessionDescription* modified_answer =
2365 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002366
2367 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2368 answer->session_id(),
2369 answer->session_version()));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002370 SetLocalDescriptionExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371 SetLocalDescriptionWithoutError(answer);
2372}
2373
2374// This test verifies that WebRtcSession does not start candidate allocation
2375// before SetLocalDescription is called.
2376TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002377 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 mediastream_signaling_.SendAudioVideoStream1();
2379 SessionDescriptionInterface* offer = CreateRemoteOffer();
2380 cricket::Candidate candidate;
2381 candidate.set_component(1);
2382 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2383 candidate);
2384 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2385 cricket::Candidate candidate1;
2386 candidate1.set_component(1);
2387 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2388 candidate1);
2389 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2390 SetRemoteDescriptionWithoutError(offer);
2391 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
2392 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
2393
2394 // Pump for 1 second and verify that no candidates are generated.
2395 talk_base::Thread::Current()->ProcessMessages(1000);
2396 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
2397 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
2398
wu@webrtc.org91053e72013-08-10 07:18:04 +00002399 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400 SetLocalDescriptionWithoutError(answer);
2401 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
2402 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
2403 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2404}
2405
2406// This test verifies that crypto parameter is updated in local session
2407// description as per security policy set in MediaSessionDescriptionFactory.
2408TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002409 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002410 mediastream_signaling_.SendAudioVideoStream1();
2411 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002412 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413
2414 // Making sure SetLocalDescription correctly sets crypto value in
2415 // SessionDescription object after de-serialization of sdp string. The value
2416 // will be set as per MediaSessionDescriptionFactory.
2417 std::string offer_str;
2418 offer->ToString(&offer_str);
2419 SessionDescriptionInterface* jsep_offer_str =
2420 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2421 SetLocalDescriptionWithoutError(jsep_offer_str);
2422 EXPECT_TRUE(session_->voice_channel()->secure_required());
2423 EXPECT_TRUE(session_->video_channel()->secure_required());
2424}
2425
2426// This test verifies the crypto parameter when security is disabled.
2427TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002428 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002429 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431 talk_base::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002432 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433
2434 // Making sure SetLocalDescription correctly sets crypto value in
2435 // SessionDescription object after de-serialization of sdp string. The value
2436 // will be set as per MediaSessionDescriptionFactory.
2437 std::string offer_str;
2438 offer->ToString(&offer_str);
2439 SessionDescriptionInterface *jsep_offer_str =
2440 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2441 SetLocalDescriptionWithoutError(jsep_offer_str);
2442 EXPECT_FALSE(session_->voice_channel()->secure_required());
2443 EXPECT_FALSE(session_->video_channel()->secure_required());
2444}
2445
2446// This test verifies that an answer contains new ufrag and password if an offer
2447// with new ufrag and password is received.
2448TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002449 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002450 cricket::MediaSessionOptions options;
2451 options.has_audio = true;
2452 options.has_video = true;
2453 talk_base::scoped_ptr<JsepSessionDescription> offer(
2454 CreateRemoteOffer(options));
2455 SetRemoteDescriptionWithoutError(offer.release());
2456
2457 mediastream_signaling_.SendAudioVideoStream1();
2458 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002459 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460 SetLocalDescriptionWithoutError(answer.release());
2461
2462 // Receive an offer with new ufrag and password.
2463 options.transport_options.ice_restart = true;
2464 talk_base::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002465 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002466 SetRemoteDescriptionWithoutError(updated_offer1.release());
2467
2468 talk_base::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002469 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002470
2471 CompareIceUfragAndPassword(updated_answer1->description(),
2472 session_->local_description()->description(),
2473 false);
2474
2475 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002476}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477
wu@webrtc.org91053e72013-08-10 07:18:04 +00002478// This test verifies that an answer contains old ufrag and password if an offer
2479// with old ufrag and password is received.
2480TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
2481 Init(NULL);
2482 cricket::MediaSessionOptions options;
2483 options.has_audio = true;
2484 options.has_video = true;
2485 talk_base::scoped_ptr<JsepSessionDescription> offer(
2486 CreateRemoteOffer(options));
2487 SetRemoteDescriptionWithoutError(offer.release());
2488
2489 mediastream_signaling_.SendAudioVideoStream1();
2490 talk_base::scoped_ptr<SessionDescriptionInterface> answer(
2491 CreateAnswer(NULL));
2492 SetLocalDescriptionWithoutError(answer.release());
2493
2494 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495 options.transport_options.ice_restart = false;
2496 talk_base::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002497 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002498 SetRemoteDescriptionWithoutError(updated_offer2.release());
2499
2500 talk_base::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002501 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502
2503 CompareIceUfragAndPassword(updated_answer2->description(),
2504 session_->local_description()->description(),
2505 true);
2506
2507 SetLocalDescriptionWithoutError(updated_answer2.release());
2508}
2509
2510TEST_F(WebRtcSessionTest, TestSessionContentError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002511 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002512 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002513 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002514 const std::string session_id_orig = offer->session_id();
2515 const std::string session_version_orig = offer->session_version();
2516 SetLocalDescriptionWithoutError(offer);
2517
2518 video_channel_ = media_engine_->GetVideoChannel(0);
2519 video_channel_->set_fail_set_send_codecs(true);
2520
2521 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002522 SessionDescriptionInterface* answer =
2523 CreateRemoteAnswer(session_->local_description());
2524 SetRemoteDescriptionExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525}
2526
2527// Runs the loopback call test with BUNDLE and STUN disabled.
2528TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
2529 // Lets try with only UDP ports.
2530 allocator_.set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
2531 cricket::PORTALLOCATOR_DISABLE_TCP |
2532 cricket::PORTALLOCATOR_DISABLE_STUN |
2533 cricket::PORTALLOCATOR_DISABLE_RELAY);
2534 TestLoopbackCall();
2535}
2536
2537// Regression-test for a crash which should have been an error.
2538TEST_F(WebRtcSessionTest, TestNoStateTransitionPendingError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002539 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002540 cricket::MediaSessionOptions options;
2541 options.has_audio = true;
2542 options.has_video = true;
2543
2544 session_->SetError(cricket::BaseSession::ERROR_CONTENT);
2545 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
2546 SessionDescriptionInterface* answer =
2547 CreateRemoteAnswer(offer, options);
2548 SetRemoteDescriptionExpectError(kSessionError, offer);
2549 SetLocalDescriptionExpectError(kSessionError, answer);
2550 // Not crashing is our success.
2551}
2552
2553TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
2554 constraints_.reset(new FakeConstraints());
2555 constraints_->AddOptional(
2556 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002557 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558
2559 SetLocalDescriptionWithDataChannel();
2560 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
2561}
2562
2563TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
2564 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2565
2566 constraints_.reset(new FakeConstraints());
2567 constraints_->AddOptional(
2568 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00002569 options_.disable_sctp_data_channels = false;
2570
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002571 InitWithDtls(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002572
2573 SetLocalDescriptionWithDataChannel();
2574 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
2575}
2576
wu@webrtc.org967bfff2013-09-19 05:49:50 +00002577TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
2578 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2579
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002580 InitWithDtls(false);
2581
2582 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
2583 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00002584 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
2585}
2586
2587TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
2588 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2589 SetFactoryDtlsSrtp();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00002590 InitWithDtls(false);
2591
2592 // Create remote offer with SCTP.
2593 cricket::MediaSessionOptions options;
2594 options.data_channel_type = cricket::DCT_SCTP;
2595 JsepSessionDescription* offer =
2596 CreateRemoteOffer(options, cricket::SEC_ENABLED);
2597 SetRemoteDescriptionWithoutError(offer);
2598
2599 // Verifies the answer contains SCTP.
2600 talk_base::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
2601 EXPECT_TRUE(answer != NULL);
2602 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
2603 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002604}
2605
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002606TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
2607 constraints_.reset(new FakeConstraints());
2608 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002609 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
2610 InitWithDtls(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002611
2612 SetLocalDescriptionWithDataChannel();
2613 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
2614}
2615
2616TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
2617 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2618
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002619 InitWithDtls(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002620
2621 SetLocalDescriptionWithDataChannel();
2622 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
2623}
wu@webrtc.org91053e72013-08-10 07:18:04 +00002624
wu@webrtc.org97077a32013-10-25 21:18:33 +00002625TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
2626 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2627 options_.disable_sctp_data_channels = true;
2628 InitWithDtls(false);
2629
2630 SetLocalDescriptionWithDataChannel();
2631 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
2632}
2633
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002634TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
2635 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2636 const int new_send_port = 9998;
2637 const int new_recv_port = 7775;
2638
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002639 InitWithDtls(false);
2640 SetFactoryDtlsSrtp();
2641
2642 // By default, don't actually add the codecs to desc_factory_; they don't
2643 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
2644 // let the session description get parsed. That'll get the proper codecs
2645 // into the stream.
2646 cricket::MediaSessionOptions options;
2647 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
2648 "stream1", new_send_port, options);
2649
2650 // SetRemoteDescription will take the ownership of the offer.
2651 SetRemoteDescriptionWithoutError(offer);
2652
2653 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
2654 new_recv_port, CreateAnswer(NULL));
2655 ASSERT_TRUE(answer != NULL);
2656
2657 // Now set the local description, which'll take ownership of the answer.
2658 SetLocalDescriptionWithoutError(answer);
2659
2660 // TEST PLAN: Set the port number to something new, set it in the SDP,
2661 // and pass it all the way down.
2662 webrtc::DataChannelInit dci;
2663 dci.reliable = true;
2664 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
2665 talk_base::scoped_refptr<webrtc::DataChannel> dc =
2666 session_->CreateDataChannel("datachannel", &dci);
2667
2668 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
2669 int portnum = -1;
2670 ASSERT_TRUE(ch != NULL);
2671 ASSERT_EQ(1UL, ch->send_codecs().size());
2672 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
2673 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
2674 ch->send_codecs()[0].name.c_str()));
2675 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
2676 &portnum));
2677 EXPECT_EQ(new_send_port, portnum);
2678
2679 ASSERT_EQ(1UL, ch->recv_codecs().size());
2680 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
2681 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
2682 ch->recv_codecs()[0].name.c_str()));
2683 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
2684 &portnum));
2685 EXPECT_EQ(new_recv_port, portnum);
2686}
2687
wu@webrtc.org91053e72013-08-10 07:18:04 +00002688// Verifies that CreateOffer succeeds when CreateOffer is called before async
2689// identity generation is finished.
2690TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
2691 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00002692 InitWithDtls(false);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002693
2694 EXPECT_TRUE(session_->waiting_for_identity());
2695 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
2696 EXPECT_TRUE(offer != NULL);
2697}
2698
2699// Verifies that CreateAnswer succeeds when CreateOffer is called before async
2700// identity generation is finished.
2701TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
2702 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00002703 InitWithDtls(false);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002704
2705 cricket::MediaSessionOptions options;
2706 scoped_ptr<JsepSessionDescription> offer(
2707 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
2708 ASSERT_TRUE(offer.get() != NULL);
2709 SetRemoteDescriptionWithoutError(offer.release());
2710
2711 talk_base::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
2712 EXPECT_TRUE(answer != NULL);
2713}
2714
2715// Verifies that CreateOffer succeeds when CreateOffer is called after async
2716// identity generation is finished.
2717TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
2718 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00002719 InitWithDtls(false);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002720
2721 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
2722 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
2723 EXPECT_TRUE(offer != NULL);
2724}
2725
2726// Verifies that CreateOffer fails when CreateOffer is called after async
2727// identity generation fails.
2728TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
2729 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00002730 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002731
2732 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
2733 talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
2734 EXPECT_TRUE(offer == NULL);
2735}
2736
2737// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
2738// before async identity generation is finished.
2739TEST_F(WebRtcSessionTest,
2740 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
2741 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2742 VerifyMultipleAsyncCreateDescription(
2743 true, CreateSessionDescriptionRequest::kOffer);
2744}
2745
2746// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
2747// before async identity generation fails.
2748TEST_F(WebRtcSessionTest,
2749 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
2750 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2751 VerifyMultipleAsyncCreateDescription(
2752 false, CreateSessionDescriptionRequest::kOffer);
2753}
2754
2755// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
2756// before async identity generation is finished.
2757TEST_F(WebRtcSessionTest,
2758 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
2759 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2760 VerifyMultipleAsyncCreateDescription(
2761 true, CreateSessionDescriptionRequest::kAnswer);
2762}
2763
2764// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
2765// before async identity generation fails.
2766TEST_F(WebRtcSessionTest,
2767 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
2768 MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp);
2769 VerifyMultipleAsyncCreateDescription(
2770 false, CreateSessionDescriptionRequest::kAnswer);
2771}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002772
2773// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
2774// offer has no SDES crypto but only DTLS fingerprint.
2775TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
2776 // Init without DTLS.
2777 Init(NULL);
2778 // Create a remote offer with secured transport disabled.
2779 cricket::MediaSessionOptions options;
2780 JsepSessionDescription* offer(CreateRemoteOffer(
2781 options, cricket::SEC_DISABLED));
2782 // Adds a DTLS fingerprint to the remote offer.
2783 cricket::SessionDescription* sdp = offer->description();
2784 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
2785 ASSERT_TRUE(audio != NULL);
2786 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
2787 audio->description.identity_fingerprint.reset(
2788 talk_base::SSLFingerprint::CreateFromRfc4572(
2789 talk_base::DIGEST_SHA_256, kFakeDtlsFingerprint));
2790 SetRemoteDescriptionExpectError(kSdpWithoutSdesAndDtlsDisabled,
2791 offer);
2792}
2793
wu@webrtc.orgde305012013-10-31 15:40:38 +00002794// This test verifies DSCP is properly applied on the media channels.
2795TEST_F(WebRtcSessionTest, TestDscpConstraint) {
2796 constraints_.reset(new FakeConstraints());
2797 constraints_->AddOptional(
2798 webrtc::MediaConstraintsInterface::kEnableDscp, true);
2799 Init(NULL);
2800 mediastream_signaling_.SendAudioVideoStream1();
2801 SessionDescriptionInterface* offer = CreateOffer(NULL);
2802
2803 SetLocalDescriptionWithoutError(offer);
2804
2805 video_channel_ = media_engine_->GetVideoChannel(0);
2806 voice_channel_ = media_engine_->GetVoiceChannel(0);
2807
2808 ASSERT_TRUE(video_channel_ != NULL);
2809 ASSERT_TRUE(voice_channel_ != NULL);
2810 cricket::AudioOptions audio_options;
2811 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
2812 cricket::VideoOptions video_options;
2813 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
2814 EXPECT_TRUE(audio_options.dscp.IsSet());
2815 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
2816 EXPECT_TRUE(video_options.dscp.IsSet());
2817 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
2818}
2819
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002820// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
2821// currently fails because upon disconnection and reconnection OnIceComplete is
2822// called more than once without returning to IceGatheringGathering.