blob: d0fb805a50e17b9b3c137fdcb7099216e41eea10 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "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"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033#include "talk/app/webrtc/test/fakeconstraints.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000034#include "talk/app/webrtc/test/fakedtlsidentityservice.h"
35#include "talk/app/webrtc/test/fakemediastreamsignaling.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000036#include "talk/app/webrtc/videotrack.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"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000039#include "talk/media/base/fakemediaengine.h"
40#include "talk/media/base/fakevideorenderer.h"
41#include "talk/media/base/mediachannel.h"
42#include "talk/media/devices/fakedevicemanager.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000043#include "webrtc/p2p/base/stunserver.h"
44#include "webrtc/p2p/base/teststunserver.h"
45#include "webrtc/p2p/base/testturnserver.h"
46#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000047#include "talk/session/media/channelmanager.h"
48#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000049#include "webrtc/base/fakenetwork.h"
50#include "webrtc/base/firewallsocketserver.h"
51#include "webrtc/base/gunit.h"
52#include "webrtc/base/logging.h"
53#include "webrtc/base/network.h"
54#include "webrtc/base/physicalsocketserver.h"
55#include "webrtc/base/ssladapter.h"
56#include "webrtc/base/sslstreamadapter.h"
57#include "webrtc/base/stringutils.h"
58#include "webrtc/base/thread.h"
59#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060
61#define MAYBE_SKIP_TEST(feature) \
62 if (!(feature())) { \
63 LOG(LS_INFO) << "Feature disabled... skipping"; \
64 return; \
65 }
66
67using cricket::BaseSession;
68using cricket::DF_PLAY;
69using cricket::DF_SEND;
70using cricket::FakeVoiceMediaChannel;
71using cricket::NS_GINGLE_P2P;
72using cricket::NS_JINGLE_ICE_UDP;
73using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000074using rtc::SocketAddress;
75using rtc::scoped_ptr;
76using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000078using webrtc::CreateSessionDescriptionObserver;
79using webrtc::CreateSessionDescriptionRequest;
80using webrtc::DTLSIdentityRequestObserver;
81using webrtc::DTLSIdentityServiceInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082using webrtc::FakeConstraints;
83using webrtc::IceCandidateCollection;
84using webrtc::JsepIceCandidate;
85using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000086using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::PeerConnectionInterface;
88using webrtc::SessionDescriptionInterface;
89using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000090using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000091using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000092using webrtc::kCreateChannelFailed;
93using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000095using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000096using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000097using webrtc::kSdpWithoutDtlsFingerprint;
98using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000100using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000101using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000103typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
104
wu@webrtc.org364f2042013-11-20 21:49:41 +0000105static const int kClientAddrPort = 0;
106static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000107static const char kClientIPv6AddrHost1[] =
108 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000109static const char kClientAddrHost2[] = "22.22.22.22";
110static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000111static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
112static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000113static const char kTurnUsername[] = "test";
114static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115
116static const char kSessionVersion[] = "1";
117
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118// Media index of candidates belonging to the first media content.
119static const int kMediaContentIndex0 = 0;
120static const char kMediaContentName0[] = "audio";
121
122// Media index of candidates belonging to the second media content.
123static const int kMediaContentIndex1 = 1;
124static const char kMediaContentName1[] = "video";
125
126static const int kIceCandidatesTimeout = 10000;
127
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000128static const char kFakeDtlsFingerprint[] =
129 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
130 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
131
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000132static const char kTooLongIceUfragPwd[] =
133 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
134 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
135 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
136 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
137
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138// Add some extra |newlines| to the |message| after |line|.
139static void InjectAfter(const std::string& line,
140 const std::string& newlines,
141 std::string* message) {
142 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000143 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 tmp.c_str(), tmp.length(), message);
145}
146
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000147class FakeMetricsObserver : public webrtc::MetricsObserverInterface {
148 public:
149 FakeMetricsObserver() { Reset(); }
150 void Reset() {
151 memset(peer_connection_metrics_counters_, 0,
152 sizeof(peer_connection_metrics_counters_));
153 memset(peer_connection_metrics_name_, 0,
154 sizeof(peer_connection_metrics_name_));
155 }
156
157 virtual void IncrementCounter(
158 webrtc::PeerConnectionMetricsCounter type) OVERRIDE {
159 peer_connection_metrics_counters_[type]++;
160 }
161 virtual void AddHistogramSample(webrtc::PeerConnectionMetricsName type,
162 int value) OVERRIDE {
163 ASSERT(peer_connection_metrics_name_[type] == 0);
164 peer_connection_metrics_name_[type] = value;
165 }
166
167 int peer_connection_metrics_counters_
168 [webrtc::kPeerConnectionMetricsCounter_Max];
169 int peer_connection_metrics_name_[webrtc::kPeerConnectionMetricsCounter_Max];
170
171 virtual int AddRef() OVERRIDE { return 1; }
172 virtual int Release() OVERRIDE { return 1; }
173};
174
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175class MockIceObserver : public webrtc::IceObserver {
176 public:
177 MockIceObserver()
178 : oncandidatesready_(false),
179 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
180 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
181 }
182
183 virtual void OnIceConnectionChange(
184 PeerConnectionInterface::IceConnectionState new_state) {
185 ice_connection_state_ = new_state;
186 }
187 virtual void OnIceGatheringChange(
188 PeerConnectionInterface::IceGatheringState new_state) {
189 // We can never transition back to "new".
190 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
191 ice_gathering_state_ = new_state;
192
193 // oncandidatesready_ really means "ICE gathering is complete".
194 // This if statement ensures that this value remains correct when we
195 // transition from kIceGatheringComplete to kIceGatheringGathering.
196 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
197 oncandidatesready_ = false;
198 }
199 }
200
201 // Found a new candidate.
202 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000203 switch (candidate->sdp_mline_index()) {
204 case kMediaContentIndex0:
205 mline_0_candidates_.push_back(candidate->candidate());
206 break;
207 case kMediaContentIndex1:
208 mline_1_candidates_.push_back(candidate->candidate());
209 break;
210 default:
211 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000213
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 // The ICE gathering state should always be Gathering when a candidate is
215 // received (or possibly Completed in the case of the final candidate).
216 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
217 }
218
219 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
220 virtual void OnIceComplete() {
221 EXPECT_FALSE(oncandidatesready_);
222 oncandidatesready_ = true;
223
224 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
225 // be called approximately simultaneously. For ease of testing, this
226 // check additionally requires that they be called in the above order.
227 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
228 ice_gathering_state_);
229 }
230
231 bool oncandidatesready_;
232 std::vector<cricket::Candidate> mline_0_candidates_;
233 std::vector<cricket::Candidate> mline_1_candidates_;
234 PeerConnectionInterface::IceConnectionState ice_connection_state_;
235 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
236};
237
238class WebRtcSessionForTest : public webrtc::WebRtcSession {
239 public:
240 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000241 rtc::Thread* signaling_thread,
242 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243 cricket::PortAllocator* port_allocator,
244 webrtc::IceObserver* ice_observer,
245 webrtc::MediaStreamSignaling* mediastream_signaling)
246 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
247 mediastream_signaling) {
248 RegisterIceObserver(ice_observer);
249 }
250 virtual ~WebRtcSessionForTest() {}
251
252 using cricket::BaseSession::GetTransportProxy;
253 using webrtc::WebRtcSession::SetAudioPlayout;
254 using webrtc::WebRtcSession::SetAudioSend;
255 using webrtc::WebRtcSession::SetCaptureDevice;
256 using webrtc::WebRtcSession::SetVideoPlayout;
257 using webrtc::WebRtcSession::SetVideoSend;
258};
259
wu@webrtc.org91053e72013-08-10 07:18:04 +0000260class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000261 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000263 enum State {
264 kInit,
265 kFailed,
266 kSucceeded,
267 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000268 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000269
270 // CreateSessionDescriptionObserver implementation.
271 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000272 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000273 state_ = kSucceeded;
274 }
275 virtual void OnFailure(const std::string& error) {
276 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 }
278
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000279 SessionDescriptionInterface* description() { return description_.get(); }
280
281 SessionDescriptionInterface* ReleaseDescription() {
282 return description_.release();
283 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284
wu@webrtc.org91053e72013-08-10 07:18:04 +0000285 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286
wu@webrtc.org91053e72013-08-10 07:18:04 +0000287 protected:
288 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289
290 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000291 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000292 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293};
294
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000295class FakeAudioRenderer : public cricket::AudioRenderer {
296 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000297 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
298 virtual ~FakeAudioRenderer() {
299 if (sink_)
300 sink_->OnClose();
301 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000302
303 virtual void AddChannel(int channel_id) OVERRIDE {
304 ASSERT(channel_id_ == -1);
305 channel_id_ = channel_id;
306 }
307 virtual void RemoveChannel(int channel_id) OVERRIDE {
308 ASSERT(channel_id == channel_id_);
309 channel_id_ = -1;
310 }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000311 virtual void SetSink(Sink* sink) OVERRIDE {
312 sink_ = sink;
313 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000314
315 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000316 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000317 private:
318 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000319 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000320};
321
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322class WebRtcSessionTest : public testing::Test {
323 protected:
324 // TODO Investigate why ChannelManager crashes, if it's created
325 // after stun_server.
326 WebRtcSessionTest()
327 : media_engine_(new cricket::FakeMediaEngine()),
328 data_engine_(new cricket::FakeDataEngine()),
329 device_manager_(new cricket::FakeDeviceManager()),
330 channel_manager_(new cricket::ChannelManager(
331 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000332 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333 tdesc_factory_(new cricket::TransportDescriptionFactory()),
334 desc_factory_(new cricket::MediaSessionDescriptionFactory(
335 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000336 pss_(new rtc::PhysicalSocketServer),
337 vss_(new rtc::VirtualSocketServer(pss_.get())),
338 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000340 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000341 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000342 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
343 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000344 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000345 mediastream_signaling_(channel_manager_.get()),
346 ice_type_(PeerConnectionInterface::kAll) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000348
349 cricket::ServerAddresses stun_servers;
350 stun_servers.insert(stun_socket_addr_);
351 allocator_.reset(new cricket::BasicPortAllocator(
352 &network_manager_,
353 stun_servers,
354 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000355 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 cricket::PORTALLOCATOR_DISABLE_RELAY |
jiayl@webrtc.orgdacdd942015-01-23 17:33:34 +0000357 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
358 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 EXPECT_TRUE(channel_manager_->Init());
360 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000361 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 }
363
364 void AddInterface(const SocketAddress& addr) {
365 network_manager_.AddInterface(addr);
366 }
367
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000368 void SetIceTransportType(PeerConnectionInterface::IceTransportsType type) {
369 ice_type_ = type;
370 }
371
wu@webrtc.org91053e72013-08-10 07:18:04 +0000372 void Init(DTLSIdentityServiceInterface* identity_service) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373 ASSERT_TRUE(session_.get() == NULL);
374 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000375 channel_manager_.get(), rtc::Thread::Current(),
376 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377 &observer_,
378 &mediastream_signaling_));
379
380 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
381 observer_.ice_connection_state_);
382 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
383 observer_.ice_gathering_state_);
384
wu@webrtc.org97077a32013-10-25 21:18:33 +0000385 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000386 identity_service, ice_type_));
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000387 session_->set_metrics_observer(&metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 }
389
390 void InitWithDtmfCodec() {
391 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000392 const cricket::AudioCodec kTelephoneEventCodec(
393 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394 std::vector<cricket::AudioCodec> codecs;
395 codecs.push_back(kTelephoneEventCodec);
396 media_engine_->SetAudioCodecs(codecs);
397 desc_factory_->set_audio_codecs(codecs);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000398 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000399 }
400
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000401 void InitWithDtls(bool identity_request_should_fail = false) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000402 FakeIdentityService* identity_service = new FakeIdentityService();
403 identity_service->set_should_fail(identity_request_should_fail);
404 Init(identity_service);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405 }
406
407 // Creates a local offer and applies it. Starts ice.
408 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
409 // to decide which streams to create.
410 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000411 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 SetLocalDescriptionWithoutError(offer);
413 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
414 observer_.ice_gathering_state_,
415 kIceCandidatesTimeout);
416 }
417
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000418 SessionDescriptionInterface* CreateOffer() {
419 PeerConnectionInterface::RTCOfferAnswerOptions options;
420 options.offer_to_receive_audio =
421 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
422
423 return CreateOffer(options);
424 }
425
wu@webrtc.org91053e72013-08-10 07:18:04 +0000426 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000427 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000428 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000429 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000430 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000431 EXPECT_TRUE_WAIT(
432 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000433 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000434 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000435 }
436
437 SessionDescriptionInterface* CreateAnswer(
438 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000439 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000440 = new WebRtcSessionCreateSDPObserverForTest();
441 session_->CreateAnswer(observer, constraints);
442 EXPECT_TRUE_WAIT(
443 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000444 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000445 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000446 }
447
wu@webrtc.org364f2042013-11-20 21:49:41 +0000448 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449 return (session_->voice_channel() != NULL &&
450 session_->video_channel() != NULL);
451 }
452
wu@webrtc.org364f2042013-11-20 21:49:41 +0000453 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000454 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
455 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
456 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
457 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
458 }
459
460 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
461 ASSERT_TRUE(session_.get() != NULL);
462 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
463 ASSERT_TRUE(content != NULL);
464 const cricket::AudioContentDescription* audio_content =
465 static_cast<const cricket::AudioContentDescription*>(
466 content->description);
467 ASSERT_TRUE(audio_content != NULL);
468 ASSERT_EQ(1U, audio_content->cryptos().size());
469 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
470 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
471 audio_content->cryptos()[0].cipher_suite);
472 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
473 audio_content->protocol());
474
475 content = cricket::GetFirstVideoContent(sdp);
476 ASSERT_TRUE(content != NULL);
477 const cricket::VideoContentDescription* video_content =
478 static_cast<const cricket::VideoContentDescription*>(
479 content->description);
480 ASSERT_TRUE(video_content != NULL);
481 ASSERT_EQ(1U, video_content->cryptos().size());
482 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
483 video_content->cryptos()[0].cipher_suite);
484 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
485 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
486 video_content->protocol());
487 }
488
489 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
490 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
491 ASSERT_TRUE(content != NULL);
492 const cricket::AudioContentDescription* audio_content =
493 static_cast<const cricket::AudioContentDescription*>(
494 content->description);
495 ASSERT_TRUE(audio_content != NULL);
496 ASSERT_EQ(0U, audio_content->cryptos().size());
497
498 content = cricket::GetFirstVideoContent(sdp);
499 ASSERT_TRUE(content != NULL);
500 const cricket::VideoContentDescription* video_content =
501 static_cast<const cricket::VideoContentDescription*>(
502 content->description);
503 ASSERT_TRUE(video_content != NULL);
504 ASSERT_EQ(0U, video_content->cryptos().size());
505
506 if (dtls) {
507 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
508 audio_content->protocol());
509 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
510 video_content->protocol());
511 } else {
512 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
513 audio_content->protocol());
514 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
515 video_content->protocol());
516 }
517 }
518
519 // Set the internal fake description factories to do DTLS-SRTP.
520 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000521 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000523 rtc::ToString(rtc::CreateRandomId());
524 identity_.reset(rtc::SSLIdentity::Generate(identity_name));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000525 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000526 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
527 }
528
529 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
530 bool expected) {
531 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
532 ASSERT_TRUE(audio != NULL);
533 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000534 const TransportInfo* video = sdp->GetTransportInfoByName("video");
535 ASSERT_TRUE(video != NULL);
536 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537 }
538
539 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000540 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000541 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000542 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000543 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000544 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000545 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000547 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
548 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000549 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 // Answer should be NULL as no crypto params in offer.
551 ASSERT_TRUE(answer == NULL);
552 }
553
554 void VerifyAnswerFromCryptoOffer() {
555 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000556 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557 options.bundle_enabled = true;
558 scoped_ptr<JsepSessionDescription> offer(
559 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
560 ASSERT_TRUE(offer.get() != NULL);
561 VerifyCryptoParams(offer->description());
562 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000563 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564 ASSERT_TRUE(answer.get() != NULL);
565 VerifyCryptoParams(answer->description());
566 }
567
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000568 void SetAndVerifyNumUnsignalledRecvStreams(
569 int value_set, int value_expected) {
570 constraints_.reset(new FakeConstraints());
571 constraints_->AddOptional(
572 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
573 value_set);
574 session_.reset();
575 Init(NULL);
576 mediastream_signaling_.SendAudioVideoStream1();
577 SessionDescriptionInterface* offer = CreateOffer();
578
579 SetLocalDescriptionWithoutError(offer);
580
581 video_channel_ = media_engine_->GetVideoChannel(0);
582
583 ASSERT_TRUE(video_channel_ != NULL);
584 cricket::VideoOptions video_options;
585 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
586 EXPECT_EQ(value_expected,
587 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
588 }
589
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000590 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
591 const cricket::SessionDescription* desc2,
592 bool expect_equal) {
593 if (desc1->contents().size() != desc2->contents().size()) {
594 EXPECT_FALSE(expect_equal);
595 return;
596 }
597
598 const cricket::ContentInfos& contents = desc1->contents();
599 cricket::ContentInfos::const_iterator it = contents.begin();
600
601 for (; it != contents.end(); ++it) {
602 const cricket::TransportDescription* transport_desc1 =
603 desc1->GetTransportDescriptionByName(it->name);
604 const cricket::TransportDescription* transport_desc2 =
605 desc2->GetTransportDescriptionByName(it->name);
606 if (!transport_desc1 || !transport_desc2) {
607 EXPECT_FALSE(expect_equal);
608 return;
609 }
610 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
611 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
612 EXPECT_FALSE(expect_equal);
613 return;
614 }
615 }
616 EXPECT_TRUE(expect_equal);
617 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000618
619 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
620 std::string *sdp) {
621 const cricket::SessionDescription* desc = current_desc->description();
622 EXPECT_TRUE(current_desc->ToString(sdp));
623
624 const cricket::ContentInfos& contents = desc->contents();
625 cricket::ContentInfos::const_iterator it = contents.begin();
626 // Replace ufrag and pwd lines with empty strings.
627 for (; it != contents.end(); ++it) {
628 const cricket::TransportDescription* transport_desc =
629 desc->GetTransportDescriptionByName(it->name);
630 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
631 + "\r\n";
632 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
633 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000634 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000635 "", 0,
636 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000637 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000638 "", 0,
639 sdp);
640 }
641 }
642
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000643 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
644 const std::string& modified_ice_ufrag,
645 const std::string& modified_ice_pwd,
646 std::string* sdp) {
647 const cricket::SessionDescription* desc = current_desc->description();
648 EXPECT_TRUE(current_desc->ToString(sdp));
649
650 const cricket::ContentInfos& contents = desc->contents();
651 cricket::ContentInfos::const_iterator it = contents.begin();
652 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
653 // |modified_ice_pwd| strings.
654 for (; it != contents.end(); ++it) {
655 const cricket::TransportDescription* transport_desc =
656 desc->GetTransportDescriptionByName(it->name);
657 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
658 + "\r\n";
659 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
660 + "\r\n";
661 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
662 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000663 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000664 mod_ufrag.c_str(), mod_ufrag.length(),
665 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000666 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000667 mod_pwd.c_str(), mod_pwd.length(),
668 sdp);
669 }
670 }
671
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000672 // Creates a remote offer and and applies it as a remote description,
673 // creates a local answer and applies is as a local description.
674 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
675 // to decide which local and remote streams to create.
676 void CreateAndSetRemoteOfferAndLocalAnswer() {
677 SessionDescriptionInterface* offer = CreateRemoteOffer();
678 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000679 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000680 SetLocalDescriptionWithoutError(answer);
681 }
682 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
683 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
684 }
685 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
686 BaseSession::State expected_state) {
687 SetLocalDescriptionWithoutError(desc);
688 EXPECT_EQ(expected_state, session_->state());
689 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000690 void SetLocalDescriptionExpectError(const std::string& action,
691 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 SessionDescriptionInterface* desc) {
693 std::string error;
694 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000695 std::string sdp_type = "local ";
696 sdp_type.append(action);
697 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698 EXPECT_NE(std::string::npos, error.find(expected_error));
699 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000700 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
701 SessionDescriptionInterface* desc) {
702 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
703 expected_error, desc);
704 }
705 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
706 SessionDescriptionInterface* desc) {
707 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
708 expected_error, desc);
709 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
711 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
712 }
713 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
714 BaseSession::State expected_state) {
715 SetRemoteDescriptionWithoutError(desc);
716 EXPECT_EQ(expected_state, session_->state());
717 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000718 void SetRemoteDescriptionExpectError(const std::string& action,
719 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000720 SessionDescriptionInterface* desc) {
721 std::string error;
722 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000723 std::string sdp_type = "remote ";
724 sdp_type.append(action);
725 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 EXPECT_NE(std::string::npos, error.find(expected_error));
727 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000728 void SetRemoteDescriptionOfferExpectError(
729 const std::string& expected_error, SessionDescriptionInterface* desc) {
730 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
731 expected_error, desc);
732 }
733 void SetRemoteDescriptionPranswerExpectError(
734 const std::string& expected_error, SessionDescriptionInterface* desc) {
735 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
736 expected_error, desc);
737 }
738 void SetRemoteDescriptionAnswerExpectError(
739 const std::string& expected_error, SessionDescriptionInterface* desc) {
740 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
741 expected_error, desc);
742 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743
744 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
745 SessionDescriptionInterface** nocrypto_answer) {
746 // Create a SDP without Crypto.
747 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000748 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 options.bundle_enabled = true;
750 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
751 ASSERT_TRUE(*offer != NULL);
752 VerifyCryptoParams((*offer)->description());
753
754 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
755 cricket::SEC_DISABLED);
756 EXPECT_TRUE(*nocrypto_answer != NULL);
757 }
758
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000759 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
760 SessionDescriptionInterface** nodtls_answer) {
761 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000762 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000763 options.bundle_enabled = true;
764
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000765 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000766 CreateRemoteOffer(options, cricket::SEC_ENABLED));
767
768 *nodtls_answer =
769 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
770 EXPECT_TRUE(*nodtls_answer != NULL);
771 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
772 VerifyCryptoParams((*nodtls_answer)->description());
773
774 SetFactoryDtlsSrtp();
775 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
776 ASSERT_TRUE(*offer != NULL);
777 VerifyFingerprintStatus((*offer)->description(), true);
778 VerifyCryptoParams((*offer)->description());
779 }
780
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 JsepSessionDescription* CreateRemoteOfferWithVersion(
782 cricket::MediaSessionOptions options,
783 cricket::SecurePolicy secure_policy,
784 const std::string& session_version,
785 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000786 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 const cricket::SessionDescription* cricket_desc = NULL;
788 if (current_desc) {
789 cricket_desc = current_desc->description();
790 session_id = current_desc->session_id();
791 }
792
793 desc_factory_->set_secure(secure_policy);
794 JsepSessionDescription* offer(
795 new JsepSessionDescription(JsepSessionDescription::kOffer));
796 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
797 session_id, session_version)) {
798 delete offer;
799 offer = NULL;
800 }
801 return offer;
802 }
803 JsepSessionDescription* CreateRemoteOffer(
804 cricket::MediaSessionOptions options) {
805 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
806 kSessionVersion, NULL);
807 }
808 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000809 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
810 return CreateRemoteOfferWithVersion(
811 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 }
813 JsepSessionDescription* CreateRemoteOffer(
814 cricket::MediaSessionOptions options,
815 const SessionDescriptionInterface* current_desc) {
816 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
817 kSessionVersion, current_desc);
818 }
819
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000820 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
821 const char* sctp_stream_name, int new_port,
822 cricket::MediaSessionOptions options) {
823 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000824 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
825 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000826 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
827 }
828
829 // Takes ownership of offer_basis (and deletes it).
830 JsepSessionDescription* ChangeSDPSctpPort(
831 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
832 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
833 // SessionDescription from the mutated string.
834 const char* default_port_str = "5000";
835 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000836 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000837 std::string offer_str;
838 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000839 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000840 new_port_str, strlen(new_port_str),
841 &offer_str);
842 JsepSessionDescription* offer = new JsepSessionDescription(
843 offer_basis->type());
844 delete offer_basis;
845 offer->Initialize(offer_str, NULL);
846 return offer;
847 }
848
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
850 // before this function to decide which streams to create.
851 JsepSessionDescription* CreateRemoteOffer() {
852 cricket::MediaSessionOptions options;
853 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
854 return CreateRemoteOffer(options, session_->remote_description());
855 }
856
857 JsepSessionDescription* CreateRemoteAnswer(
858 const SessionDescriptionInterface* offer,
859 cricket::MediaSessionOptions options,
860 cricket::SecurePolicy policy) {
861 desc_factory_->set_secure(policy);
862 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000863 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 JsepSessionDescription* answer(
865 new JsepSessionDescription(JsepSessionDescription::kAnswer));
866 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
867 options, NULL),
868 session_id, kSessionVersion)) {
869 delete answer;
870 answer = NULL;
871 }
872 return answer;
873 }
874
875 JsepSessionDescription* CreateRemoteAnswer(
876 const SessionDescriptionInterface* offer,
877 cricket::MediaSessionOptions options) {
878 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
879 }
880
881 // Creates an answer session description with streams based on
882 // |mediastream_signaling_|. Call
883 // mediastream_signaling_.UseOptionsWithStreamX() before this function
884 // to decide which streams to create.
885 JsepSessionDescription* CreateRemoteAnswer(
886 const SessionDescriptionInterface* offer) {
887 cricket::MediaSessionOptions options;
888 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
889 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
890 }
891
892 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000893 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000894 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000896
897 PeerConnectionInterface::RTCOfferAnswerOptions options;
898 options.use_rtp_mux = bundle;
899
900 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
902 // and answer.
903 SetLocalDescriptionWithoutError(offer);
904
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000905 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000906 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 std::string sdp;
908 EXPECT_TRUE(answer->ToString(&sdp));
909
910 size_t expected_candidate_num = 2;
911 if (!rtcp_mux) {
912 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
913 // for rtp and rtcp.
914 expected_candidate_num = 4;
915 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 const std::string kRtcpMux = "a=rtcp-mux";
917 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000918 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 kXRtcpMux.c_str(), kXRtcpMux.length(),
920 &sdp);
921 }
922
923 SessionDescriptionInterface* new_answer = CreateSessionDescription(
924 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925
926 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000927 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
929 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
930 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
931 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
932 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
933 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
934 if (bundle) {
935 EXPECT_TRUE(c0.IsEquivalent(c1));
936 } else {
937 EXPECT_FALSE(c0.IsEquivalent(c1));
938 }
939 }
940 }
941 // Tests that we can only send DTMF when the dtmf codec is supported.
942 void TestCanInsertDtmf(bool can) {
943 if (can) {
944 InitWithDtmfCodec();
945 } else {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000946 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 }
948 mediastream_signaling_.SendAudioVideoStream1();
949 CreateAndSetRemoteOfferAndLocalAnswer();
950 EXPECT_FALSE(session_->CanInsertDtmf(""));
951 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
952 }
953
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000954 // Helper class to configure loopback network and verify Best
955 // Connection using right IP protocol for TestLoopbackCall
956 // method. LoopbackNetworkManager applies firewall rules to block
957 // all ping traffic once ICE completed, and remove them to observe
958 // ICE reconnected again. This LoopbackNetworkConfiguration struct
959 // verifies the best connection is using the right IP protocol after
960 // initial ICE convergences.
961
962 class LoopbackNetworkConfiguration {
963 public:
964 LoopbackNetworkConfiguration()
965 : test_ipv6_network_(false),
966 test_extra_ipv4_network_(false),
967 best_connection_after_initial_ice_converged_(1, 0) {}
968
969 // Used to track the expected best connection count in each IP protocol.
970 struct ExpectedBestConnection {
971 ExpectedBestConnection(int ipv4_count, int ipv6_count)
972 : ipv4_count_(ipv4_count),
973 ipv6_count_(ipv6_count) {}
974
975 int ipv4_count_;
976 int ipv6_count_;
977 };
978
979 bool test_ipv6_network_;
980 bool test_extra_ipv4_network_;
981 ExpectedBestConnection best_connection_after_initial_ice_converged_;
982
983 void VerifyBestConnectionAfterIceConverge(
984 const FakeMetricsObserver& metrics_observer) const {
985 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
986 }
987
988 private:
989 void Verify(const FakeMetricsObserver& metrics_observer,
990 const ExpectedBestConnection& expected) const {
991 EXPECT_EQ(
992 metrics_observer
993 .peer_connection_metrics_counters_[webrtc::kBestConnections_IPv4],
994 expected.ipv4_count_);
995 EXPECT_EQ(
996 metrics_observer
997 .peer_connection_metrics_counters_[webrtc::kBestConnections_IPv6],
998 expected.ipv6_count_);
999 }
1000 };
1001
1002 class LoopbackNetworkManager {
1003 public:
1004 LoopbackNetworkManager(WebRtcSessionTest* session,
1005 const LoopbackNetworkConfiguration& config)
1006 : config_(config) {
1007 session->AddInterface(
1008 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1009 if (config_.test_extra_ipv4_network_) {
1010 session->AddInterface(
1011 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1012 }
1013 if (config_.test_ipv6_network_) {
1014 session->AddInterface(
1015 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1016 }
1017 }
1018
1019 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1020 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1021 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1022 if (config_.test_extra_ipv4_network_) {
1023 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1024 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1025 }
1026 if (config_.test_ipv6_network_) {
1027 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1028 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1029 }
1030 }
1031
1032 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1033
1034 private:
1035 LoopbackNetworkConfiguration config_;
1036 };
1037
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001038 // The method sets up a call from the session to itself, in a loopback
1039 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001040 // disconnection, and then a permanent disconnection.
1041 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001042 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1043 // While running the call, this method also checks if the session goes through
1044 // the correct sequence of ICE states when a connection is established,
1045 // broken, and re-established.
1046 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001047 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1048 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001049 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001050
1051 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1052 LoopbackNetworkManager loopback_network_manager(this, config);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001053 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001054 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001055 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056
1057 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1058 observer_.ice_gathering_state_);
1059 SetLocalDescriptionWithoutError(offer);
1060 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1061 observer_.ice_connection_state_);
1062 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1063 observer_.ice_gathering_state_,
1064 kIceCandidatesTimeout);
1065 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1066 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1067 observer_.ice_gathering_state_,
1068 kIceCandidatesTimeout);
1069
1070 std::string sdp;
1071 offer->ToString(&sdp);
1072 SessionDescriptionInterface* desc =
1073 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
1074 ASSERT_TRUE(desc != NULL);
1075 SetRemoteDescriptionWithoutError(desc);
1076
1077 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1078 observer_.ice_connection_state_,
1079 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001080
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001081 // The ice connection state is "Connected" too briefly to catch in a test.
1082 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 observer_.ice_connection_state_,
1084 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001086 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087 // Adding firewall rule to block ping requests, which should cause
1088 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001089
1090 loopback_network_manager.ApplyFirewallRules(fss_.get());
1091
1092 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1094 observer_.ice_connection_state_,
1095 kIceCandidatesTimeout);
1096
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001097 metrics_observer_.Reset();
1098
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001099 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001100 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 // Session is automatically calling OnSignalingReady after creation of
1102 // new portallocator session which will allocate new set of candidates.
1103
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001104 LOG(LS_INFO) << "Firewall Rules cleared";
1105
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001106 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001107 observer_.ice_connection_state_,
1108 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001109
1110 // Now we block ping requests and wait until the ICE connection transitions
1111 // to the Failed state. This will take at least 30 seconds because it must
1112 // wait for the Port to timeout.
1113 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001114
1115 loopback_network_manager.ApplyFirewallRules(fss_.get());
1116 LOG(LS_INFO) << "Firewall Rules applied again";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001117 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionFailed,
1118 observer_.ice_connection_state_,
1119 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001120 }
1121
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001122 void TestLoopbackCall() {
1123 LoopbackNetworkConfiguration config;
1124 TestLoopbackCall(config);
1125 }
1126
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127 void VerifyTransportType(const std::string& content_name,
1128 cricket::TransportProtocol protocol) {
1129 const cricket::Transport* transport = session_->GetTransport(content_name);
1130 ASSERT_TRUE(transport != NULL);
1131 EXPECT_EQ(protocol, transport->protocol());
1132 }
1133
1134 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1135 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001136 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1137 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1138
1139 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001140 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1141 codecs.push_back(kCNCodec1);
1142 codecs.push_back(kCNCodec2);
1143 media_engine_->SetAudioCodecs(codecs);
1144 desc_factory_->set_audio_codecs(codecs);
1145 }
1146
1147 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1148 const cricket::ContentDescription* description = content->description;
1149 ASSERT(description != NULL);
1150 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001151 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001152 ASSERT(audio_content_desc != NULL);
1153 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1154 if (audio_content_desc->codecs()[i].name == "CN")
1155 return false;
1156 }
1157 return true;
1158 }
1159
1160 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001161 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001162 dci.reliable = false;
1163 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001164 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001165 SetLocalDescriptionWithoutError(offer);
1166 }
1167
wu@webrtc.org91053e72013-08-10 07:18:04 +00001168 void VerifyMultipleAsyncCreateDescription(
1169 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001170 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001171 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001172 if (type == CreateSessionDescriptionRequest::kAnswer) {
1173 cricket::MediaSessionOptions options;
1174 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001175 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001176 ASSERT_TRUE(offer.get() != NULL);
1177 SetRemoteDescriptionWithoutError(offer.release());
1178 }
1179
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001180 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001181 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001182 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001183 observers[kNumber];
1184 for (int i = 0; i < kNumber; ++i) {
1185 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1186 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001187 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001188 } else {
1189 session_->CreateAnswer(observers[i], NULL);
1190 }
1191 }
1192
1193 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1194 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1195 WebRtcSessionCreateSDPObserverForTest::kFailed;
1196
1197 for (int i = 0; i < kNumber; ++i) {
1198 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1199 if (success) {
1200 EXPECT_TRUE(observers[i]->description() != NULL);
1201 } else {
1202 EXPECT_TRUE(observers[i]->description() == NULL);
1203 }
1204 }
1205 }
1206
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001207 void ConfigureAllocatorWithTurn() {
1208 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1209 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1210 relay_server.credentials = credentials;
1211 relay_server.ports.push_back(cricket::ProtocolAddress(
1212 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1213 allocator_->AddRelay(relay_server);
1214 allocator_->set_step_delay(cricket::kMinimumStepDelay);
1215 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
jiayl@webrtc.orgdacdd942015-01-23 17:33:34 +00001216 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
1217 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001218 }
1219
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001220 cricket::FakeMediaEngine* media_engine_;
1221 cricket::FakeDataEngine* data_engine_;
1222 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001223 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1224 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1225 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1226 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1227 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1228 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1229 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1230 rtc::SocketServerScope ss_scope_;
1231 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001232 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001233 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001234 rtc::FakeNetworkManager network_manager_;
1235 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001236 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001237 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001238 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001239 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001240 MockIceObserver observer_;
1241 cricket::FakeVideoMediaChannel* video_channel_;
1242 cricket::FakeVoiceMediaChannel* voice_channel_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001243 PeerConnectionInterface::IceTransportsType ice_type_;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001244 FakeMetricsObserver metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001245};
1246
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001247TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1248 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001249 // SDES is disabled when DTLS is on.
1250 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251}
1252
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001253TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001254 Init(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001255 // SDES is required if DTLS is off.
1256 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001257}
1258
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001259TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1260 TestSessionCandidatesWithBundleRtcpMux(false, false);
1261}
1262
1263// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1264// with rtcp-mux and/or bundle.
1265TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1266 TestSessionCandidatesWithBundleRtcpMux(false, true);
1267}
1268
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001269TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1270 TestSessionCandidatesWithBundleRtcpMux(true, true);
1271}
1272
1273TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001274 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1275 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001276 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277 mediastream_signaling_.SendAudioVideoStream1();
1278 InitiateCall();
1279 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1280 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1281 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1282}
1283
1284TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001285 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1286 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001287 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001288 rtc::FP_UDP,
1289 rtc::FD_ANY,
1290 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001291 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292 mediastream_signaling_.SendAudioVideoStream1();
1293 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001294 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1296 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1297 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1298}
1299
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001300// Test session delivers no candidates gathered when constraint set to "none".
1301TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1302 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1303 SetIceTransportType(PeerConnectionInterface::kNone);
1304 Init(NULL);
1305 mediastream_signaling_.SendAudioVideoStream1();
1306 InitiateCall();
1307 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1308 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1309 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1310}
1311
1312// Test session delivers only relay candidates gathered when constaint set to
1313// "relay".
1314TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1315 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1316 ConfigureAllocatorWithTurn();
1317 SetIceTransportType(PeerConnectionInterface::kRelay);
1318 Init(NULL);
1319 mediastream_signaling_.SendAudioVideoStream1();
1320 InitiateCall();
1321 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1322 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1323 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1324 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1325 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1326 observer_.mline_0_candidates_[i].type());
1327 }
1328 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1329 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1330 observer_.mline_1_candidates_[i].type());
1331 }
1332}
1333
1334// Test session delivers all candidates gathered when constaint set to "all".
1335TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1336 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1337 SetIceTransportType(PeerConnectionInterface::kAll);
1338 Init(NULL);
1339 mediastream_signaling_.SendAudioVideoStream1();
1340 InitiateCall();
1341 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1342 // Host + STUN. By default allocator is disabled to gather relay candidates.
1343 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1344 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1345}
1346
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001347TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
1348 Init(NULL);
1349 SessionDescriptionInterface* offer = NULL;
1350 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1351 std::string unknown_action;
1352 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1353 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1354}
1355
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001356// Test creating offers and receive answers and make sure the
1357// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001358TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001359 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001360 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001361 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 const std::string session_id_orig = offer->session_id();
1363 const std::string session_version_orig = offer->session_version();
1364 SetLocalDescriptionWithoutError(offer);
1365
1366 mediastream_signaling_.SendAudioVideoStream2();
1367 SessionDescriptionInterface* answer =
1368 CreateRemoteAnswer(session_->local_description());
1369 SetRemoteDescriptionWithoutError(answer);
1370
1371 video_channel_ = media_engine_->GetVideoChannel(0);
1372 voice_channel_ = media_engine_->GetVoiceChannel(0);
1373
1374 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1375 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1376
1377 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1378 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1379
1380 ASSERT_EQ(1u, video_channel_->send_streams().size());
1381 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1382 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1383 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1384
1385 // Create new offer without send streams.
1386 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001387 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001388
1389 // Verify the session id is the same and the session version is
1390 // increased.
1391 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001392 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1393 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001394
1395 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001396 EXPECT_EQ(0u, video_channel_->send_streams().size());
1397 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001398
1399 mediastream_signaling_.SendAudioVideoStream2();
1400 answer = CreateRemoteAnswer(session_->local_description());
1401 SetRemoteDescriptionWithoutError(answer);
1402
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403 // Make sure the receive streams have not changed.
1404 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1405 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1406 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1407 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1408}
1409
1410// Test receiving offers and creating answers and make sure the
1411// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001412TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001413 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001415 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001416 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001417 SetRemoteDescriptionWithoutError(offer);
1418
1419 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001420 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001421 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001422 SetLocalDescriptionWithoutError(answer);
1423
1424 const std::string session_id_orig = answer->session_id();
1425 const std::string session_version_orig = answer->session_version();
1426
1427 video_channel_ = media_engine_->GetVideoChannel(0);
1428 voice_channel_ = media_engine_->GetVoiceChannel(0);
1429
1430 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1431 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1432
1433 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1434 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1435
1436 ASSERT_EQ(1u, video_channel_->send_streams().size());
1437 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1438 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1439 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1440
1441 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001442 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001443 SetRemoteDescriptionWithoutError(offer);
1444
1445 // Answer by turning off all send streams.
1446 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001447 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448
1449 // Verify the session id is the same and the session version is
1450 // increased.
1451 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001452 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1453 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 SetLocalDescriptionWithoutError(answer);
1455
1456 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1457 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1458 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1459 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1460 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1461 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1462
1463 // Make sure we have no send streams.
1464 EXPECT_EQ(0u, video_channel_->send_streams().size());
1465 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1466}
1467
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001468TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
1469 Init(NULL);
1470 media_engine_->set_fail_create_channel(true);
1471
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001472 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001473 ASSERT_TRUE(offer != NULL);
1474 // SetRemoteDescription and SetLocalDescription will take the ownership of
1475 // the offer.
1476 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001477 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001478 ASSERT_TRUE(offer != NULL);
1479 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1480}
1481
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001482//
1483// Tests for creating/setting SDP under different SDES/DTLS polices:
1484//
1485// --DTLS off and SDES on
1486// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1487// set local/remote offer/answer with crypto --> success
1488// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1489// failure
1490// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1491// failure
1492// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1493// failure
1494//
1495// --DTLS on and SDES off
1496// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1497// set local/remote offer/answer with DTLS fingerprint --> success
1498// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1499// fingerprint --> failure
1500// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1501// --> failure
1502// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1503// --> failure
1504//
1505// --Encryption disabled: DTLS off and SDES off
1506// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1507// answer without SDES or DTLS --> success
1508// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1509// answer without SDES or DTLS --> success
1510//
1511
1512// Test that we return a failure when applying a remote/local offer that doesn't
1513// have cryptos enabled when DTLS is off.
1514TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001515 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001517 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001518 JsepSessionDescription* offer = CreateRemoteOffer(
1519 options, cricket::SEC_DISABLED);
1520 ASSERT_TRUE(offer != NULL);
1521 VerifyNoCryptoParams(offer->description(), false);
1522 // SetRemoteDescription and SetLocalDescription will take the ownership of
1523 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001524 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1526 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001527 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528}
1529
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001530// Test that we return a failure when applying a local answer that doesn't have
1531// cryptos enabled when DTLS is off.
1532TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001533 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001534 SessionDescriptionInterface* offer = NULL;
1535 SessionDescriptionInterface* answer = NULL;
1536 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1537 // SetRemoteDescription and SetLocalDescription will take the ownership of
1538 // the offer.
1539 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001540 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001541}
1542
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001543// Test we will return fail when apply an remote answer that doesn't have
1544// crypto enabled when DTLS is off.
1545TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001546 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547 SessionDescriptionInterface* offer = NULL;
1548 SessionDescriptionInterface* answer = NULL;
1549 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1550 // SetRemoteDescription and SetLocalDescription will take the ownership of
1551 // the offer.
1552 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001553 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554}
1555
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001556// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1557// and that we return an answer with a DTLS fingerprint.
1558TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001559 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561 InitWithDtls();
1562 SetFactoryDtlsSrtp();
1563 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001564 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001565 JsepSessionDescription* offer =
1566 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001567 ASSERT_TRUE(offer != NULL);
1568 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001569 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570
1571 // SetRemoteDescription will take the ownership of the offer.
1572 SetRemoteDescriptionWithoutError(offer);
1573
1574 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001575 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 ASSERT_TRUE(answer != NULL);
1577 VerifyFingerprintStatus(answer->description(), true);
1578 // Check that we don't have an a=crypto line in the answer.
1579 VerifyNoCryptoParams(answer->description(), true);
1580
1581 // Now set the local description, which should work, even without a=crypto.
1582 SetLocalDescriptionWithoutError(answer);
1583}
1584
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001585// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1586// and then we accept a remote answer with a DTLS fingerprint successfully.
1587TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001588 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001589 mediastream_signaling_.SendAudioVideoStream1();
1590 InitWithDtls();
1591 SetFactoryDtlsSrtp();
1592
1593 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001594 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001595 ASSERT_TRUE(offer != NULL);
1596 VerifyFingerprintStatus(offer->description(), true);
1597 // Check that we don't have an a=crypto line in the offer.
1598 VerifyNoCryptoParams(offer->description(), true);
1599
1600 // Now set the local description, which should work, even without a=crypto.
1601 SetLocalDescriptionWithoutError(offer);
1602
1603 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001604 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001605 JsepSessionDescription* answer =
1606 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1607 ASSERT_TRUE(answer != NULL);
1608 VerifyFingerprintStatus(answer->description(), true);
1609 VerifyNoCryptoParams(answer->description(), true);
1610
1611 // SetRemoteDescription will take the ownership of the answer.
1612 SetRemoteDescriptionWithoutError(answer);
1613}
1614
1615// Test that if we support DTLS and the other side didn't offer a fingerprint,
1616// we will fail to set the remote description.
1617TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001618 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 InitWithDtls();
1620 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001621 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001622 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623 JsepSessionDescription* offer = CreateRemoteOffer(
1624 options, cricket::SEC_REQUIRED);
1625 ASSERT_TRUE(offer != NULL);
1626 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001627 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001629 // SetRemoteDescription will take the ownership of the offer.
1630 SetRemoteDescriptionOfferExpectError(
1631 kSdpWithoutDtlsFingerprint, offer);
1632
1633 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1634 // SetLocalDescription will take the ownership of the offer.
1635 SetLocalDescriptionOfferExpectError(
1636 kSdpWithoutDtlsFingerprint, offer);
1637}
1638
1639// Test that we return a failure when applying a local answer that doesn't have
1640// a DTLS fingerprint when DTLS is required.
1641TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001642 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001643 InitWithDtls();
1644 SessionDescriptionInterface* offer = NULL;
1645 SessionDescriptionInterface* answer = NULL;
1646 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1647
1648 // SetRemoteDescription and SetLocalDescription will take the ownership of
1649 // the offer and answer.
1650 SetRemoteDescriptionWithoutError(offer);
1651 SetLocalDescriptionAnswerExpectError(
1652 kSdpWithoutDtlsFingerprint, answer);
1653}
1654
1655// Test that we return a failure when applying a remote answer that doesn't have
1656// a DTLS fingerprint when DTLS is required.
1657TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001658 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001659 InitWithDtls();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001660 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001661 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001662 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001663 JsepSessionDescription* answer =
1664 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1665
1666 // SetRemoteDescription and SetLocalDescription will take the ownership of
1667 // the offer and answer.
1668 SetLocalDescriptionWithoutError(offer);
1669 SetRemoteDescriptionAnswerExpectError(
1670 kSdpWithoutDtlsFingerprint, answer);
1671}
1672
1673// Test that we create a local offer without SDES or DTLS and accept a remote
1674// answer without SDES or DTLS when encryption is disabled.
1675TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1676 mediastream_signaling_.SendAudioVideoStream1();
1677 options_.disable_encryption = true;
1678 InitWithDtls();
1679
1680 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001681 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001682 ASSERT_TRUE(offer != NULL);
1683 VerifyFingerprintStatus(offer->description(), false);
1684 // Check that we don't have an a=crypto line in the offer.
1685 VerifyNoCryptoParams(offer->description(), false);
1686
1687 // Now set the local description, which should work, even without a=crypto.
1688 SetLocalDescriptionWithoutError(offer);
1689
1690 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001691 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001692 JsepSessionDescription* answer =
1693 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1694 ASSERT_TRUE(answer != NULL);
1695 VerifyFingerprintStatus(answer->description(), false);
1696 VerifyNoCryptoParams(answer->description(), false);
1697
1698 // SetRemoteDescription will take the ownership of the answer.
1699 SetRemoteDescriptionWithoutError(answer);
1700}
1701
1702// Test that we create a local answer without SDES or DTLS and accept a remote
1703// offer without SDES or DTLS when encryption is disabled.
1704TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1705 options_.disable_encryption = true;
1706 InitWithDtls();
1707
1708 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001709 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001710 JsepSessionDescription* offer =
1711 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1712 ASSERT_TRUE(offer != NULL);
1713 VerifyFingerprintStatus(offer->description(), false);
1714 VerifyNoCryptoParams(offer->description(), false);
1715
1716 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 SetRemoteDescriptionWithoutError(offer);
1718
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001719 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001720 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001721 ASSERT_TRUE(answer != NULL);
1722 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001723 // Check that we don't have an a=crypto line in the answer.
1724 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001726 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727 SetLocalDescriptionWithoutError(answer);
1728}
1729
1730TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001731 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732 mediastream_signaling_.SendNothing();
1733 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001734 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735 SetLocalDescriptionWithoutError(offer);
1736
1737 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001738 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739 SetLocalDescriptionWithoutError(offer2);
1740}
1741
1742TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001743 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744 mediastream_signaling_.SendNothing();
1745 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001746 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747 SetRemoteDescriptionWithoutError(offer);
1748
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001749 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750 SetRemoteDescriptionWithoutError(offer2);
1751}
1752
1753TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001754 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001756 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001758 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001759 SetRemoteDescriptionOfferExpectError(
1760 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761}
1762
1763TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001764 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001766 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001768 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001769 SetLocalDescriptionOfferExpectError(
1770 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771}
1772
1773TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001774 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 mediastream_signaling_.SendNothing();
1776 SessionDescriptionInterface* offer = CreateRemoteOffer();
1777 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1778
1779 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001780 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1782 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1783
1784 mediastream_signaling_.SendAudioVideoStream1();
1785 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001786 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1788
1789 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1790
1791 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001792 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1794}
1795
1796TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001797 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001799 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1801
1802 JsepSessionDescription* pranswer =
1803 CreateRemoteAnswer(session_->local_description());
1804 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1805
1806 SetRemoteDescriptionExpectState(pranswer,
1807 BaseSession::STATE_RECEIVEDPRACCEPT);
1808
1809 mediastream_signaling_.SendAudioVideoStream1();
1810 JsepSessionDescription* pranswer2 =
1811 CreateRemoteAnswer(session_->local_description());
1812 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1813
1814 SetRemoteDescriptionExpectState(pranswer2,
1815 BaseSession::STATE_RECEIVEDPRACCEPT);
1816
1817 mediastream_signaling_.SendAudioVideoStream2();
1818 SessionDescriptionInterface* answer =
1819 CreateRemoteAnswer(session_->local_description());
1820 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1821}
1822
1823TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001824 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001826 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1827
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828 SessionDescriptionInterface* answer =
1829 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001830 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1831 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832}
1833
1834TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001835 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001836 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001837 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1838
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839 SessionDescriptionInterface* answer =
1840 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001841 SetRemoteDescriptionAnswerExpectError(
1842 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001843}
1844
1845TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001846 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001847 mediastream_signaling_.SendAudioVideoStream1();
1848
1849 cricket::Candidate candidate;
1850 candidate.set_component(1);
1851 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1852
1853 // Fail since we have not set a offer description.
1854 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1855
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001856 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 SetLocalDescriptionWithoutError(offer);
1858 // Candidate should be allowed to add before remote description.
1859 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1860 candidate.set_component(2);
1861 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1862 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1863
1864 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1865 session_->local_description());
1866 SetRemoteDescriptionWithoutError(answer);
1867
1868 // Verifying the candidates are copied properly from internal vector.
1869 const SessionDescriptionInterface* remote_desc =
1870 session_->remote_description();
1871 ASSERT_TRUE(remote_desc != NULL);
1872 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1873 const IceCandidateCollection* candidates =
1874 remote_desc->candidates(kMediaContentIndex0);
1875 ASSERT_EQ(2u, candidates->count());
1876 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1877 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1878 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1879 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1880
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001881 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1882 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883 candidate.set_component(2);
1884 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1885 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001886 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887
1888 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1889 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1890}
1891
1892// Test that a remote candidate is added to the remote session description and
1893// that it is retained if the remote session description is changed.
1894TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001895 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001896 cricket::Candidate candidate1;
1897 candidate1.set_component(1);
1898 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1899 candidate1);
1900 mediastream_signaling_.SendAudioVideoStream1();
1901 CreateAndSetRemoteOfferAndLocalAnswer();
1902
1903 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1904 const SessionDescriptionInterface* remote_desc =
1905 session_->remote_description();
1906 ASSERT_TRUE(remote_desc != NULL);
1907 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1908 const IceCandidateCollection* candidates =
1909 remote_desc->candidates(kMediaContentIndex0);
1910 ASSERT_EQ(1u, candidates->count());
1911 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1912
1913 // Update the RemoteSessionDescription with a new session description and
1914 // a candidate and check that the new remote session description contains both
1915 // candidates.
1916 SessionDescriptionInterface* offer = CreateRemoteOffer();
1917 cricket::Candidate candidate2;
1918 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1919 candidate2);
1920 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1921 SetRemoteDescriptionWithoutError(offer);
1922
1923 remote_desc = session_->remote_description();
1924 ASSERT_TRUE(remote_desc != NULL);
1925 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1926 candidates = remote_desc->candidates(kMediaContentIndex0);
1927 ASSERT_EQ(2u, candidates->count());
1928 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1929 // Username and password have be updated with the TransportInfo of the
1930 // SessionDescription, won't be equal to the original one.
1931 candidate2.set_username(candidates->at(0)->candidate().username());
1932 candidate2.set_password(candidates->at(0)->candidate().password());
1933 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1934 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1935 // No need to verify the username and password.
1936 candidate1.set_username(candidates->at(1)->candidate().username());
1937 candidate1.set_password(candidates->at(1)->candidate().password());
1938 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1939
1940 // Test that the candidate is ignored if we can add the same candidate again.
1941 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1942}
1943
1944// Test that local candidates are added to the local session description and
1945// that they are retained if the local session description is changed.
1946TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001947 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001948 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001949 mediastream_signaling_.SendAudioVideoStream1();
1950 CreateAndSetRemoteOfferAndLocalAnswer();
1951
1952 const SessionDescriptionInterface* local_desc = session_->local_description();
1953 const IceCandidateCollection* candidates =
1954 local_desc->candidates(kMediaContentIndex0);
1955 ASSERT_TRUE(candidates != NULL);
1956 EXPECT_EQ(0u, candidates->count());
1957
1958 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1959
1960 local_desc = session_->local_description();
1961 candidates = local_desc->candidates(kMediaContentIndex0);
1962 ASSERT_TRUE(candidates != NULL);
1963 EXPECT_LT(0u, candidates->count());
1964 candidates = local_desc->candidates(1);
1965 ASSERT_TRUE(candidates != NULL);
1966 EXPECT_LT(0u, candidates->count());
1967
1968 // Update the session descriptions.
1969 mediastream_signaling_.SendAudioVideoStream1();
1970 CreateAndSetRemoteOfferAndLocalAnswer();
1971
1972 local_desc = session_->local_description();
1973 candidates = local_desc->candidates(kMediaContentIndex0);
1974 ASSERT_TRUE(candidates != NULL);
1975 EXPECT_LT(0u, candidates->count());
1976 candidates = local_desc->candidates(1);
1977 ASSERT_TRUE(candidates != NULL);
1978 EXPECT_LT(0u, candidates->count());
1979}
1980
1981// Test that we can set a remote session description with remote candidates.
1982TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001983 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984
1985 cricket::Candidate candidate1;
1986 candidate1.set_component(1);
1987 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
1988 candidate1);
1989 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001990 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991
1992 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
1993 SetRemoteDescriptionWithoutError(offer);
1994
1995 const SessionDescriptionInterface* remote_desc =
1996 session_->remote_description();
1997 ASSERT_TRUE(remote_desc != NULL);
1998 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1999 const IceCandidateCollection* candidates =
2000 remote_desc->candidates(kMediaContentIndex0);
2001 ASSERT_EQ(1u, candidates->count());
2002 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2003
wu@webrtc.org91053e72013-08-10 07:18:04 +00002004 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 SetLocalDescriptionWithoutError(answer);
2006}
2007
2008// Test that offers and answers contains ice candidates when Ice candidates have
2009// been gathered.
2010TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002011 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00002012 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013 mediastream_signaling_.SendAudioVideoStream1();
2014 // Ice is started but candidates are not provided until SetLocalDescription
2015 // is called.
2016 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2017 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2018 CreateAndSetRemoteOfferAndLocalAnswer();
2019 // Wait until at least one local candidate has been collected.
2020 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2021 kIceCandidatesTimeout);
2022 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
2023 kIceCandidatesTimeout);
2024
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002025 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2026
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2028 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2029 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
2030 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
2031
2032 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2033 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002034 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2036 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2037 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
2038 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
2039 SetLocalDescriptionWithoutError(answer);
2040}
2041
2042// Verifies TransportProxy and media channels are created with content names
2043// present in the SessionDescription.
2044TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002045 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002047 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048
2049 // CreateOffer creates session description with the content names "audio" and
2050 // "video". Goal is to modify these content names and verify transport channel
2051 // proxy in the BaseSession, as proxies are created with the content names
2052 // present in SDP.
2053 std::string sdp;
2054 EXPECT_TRUE(offer->ToString(&sdp));
2055 const std::string kAudioMid = "a=mid:audio";
2056 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2057 const std::string kVideoMid = "a=mid:video";
2058 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2059
2060 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002061 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062 kAudioMidReplaceStr.c_str(),
2063 kAudioMidReplaceStr.length(),
2064 &sdp);
2065 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002066 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 kVideoMidReplaceStr.c_str(),
2068 kVideoMidReplaceStr.length(),
2069 &sdp);
2070
2071 SessionDescriptionInterface* modified_offer =
2072 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2073
2074 SetRemoteDescriptionWithoutError(modified_offer);
2075
2076 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002077 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078 SetLocalDescriptionWithoutError(answer);
2079
2080 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
2081 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
2082 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2083 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2084}
2085
2086// Test that an offer contains the correct media content descriptions based on
2087// the send streams when no constraints have been set.
2088TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002089 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002090 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2091
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092 ASSERT_TRUE(offer != NULL);
2093 const cricket::ContentInfo* content =
2094 cricket::GetFirstAudioContent(offer->description());
2095 EXPECT_TRUE(content != NULL);
2096 content = cricket::GetFirstVideoContent(offer->description());
2097 EXPECT_TRUE(content == NULL);
2098}
2099
2100// Test that an offer contains the correct media content descriptions based on
2101// the send streams when no constraints have been set.
2102TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002103 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104 // Test Audio only offer.
2105 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002106 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2107
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108 const cricket::ContentInfo* content =
2109 cricket::GetFirstAudioContent(offer->description());
2110 EXPECT_TRUE(content != NULL);
2111 content = cricket::GetFirstVideoContent(offer->description());
2112 EXPECT_TRUE(content == NULL);
2113
2114 // Test Audio / Video offer.
2115 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002116 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117 content = cricket::GetFirstAudioContent(offer->description());
2118 EXPECT_TRUE(content != NULL);
2119 content = cricket::GetFirstVideoContent(offer->description());
2120 EXPECT_TRUE(content != NULL);
2121}
2122
2123// Test that an offer contains no media content descriptions if
2124// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2125TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002126 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002127 PeerConnectionInterface::RTCOfferAnswerOptions options;
2128 options.offer_to_receive_audio = 0;
2129 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002131 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002132 CreateOffer(options));
2133
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 ASSERT_TRUE(offer != NULL);
2135 const cricket::ContentInfo* content =
2136 cricket::GetFirstAudioContent(offer->description());
2137 EXPECT_TRUE(content == NULL);
2138 content = cricket::GetFirstVideoContent(offer->description());
2139 EXPECT_TRUE(content == NULL);
2140}
2141
2142// Test that an offer contains only audio media content descriptions if
2143// kOfferToReceiveAudio constraints are set to true.
2144TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002145 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002146 PeerConnectionInterface::RTCOfferAnswerOptions options;
2147 options.offer_to_receive_audio =
2148 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2149
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002150 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002151 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152
2153 const cricket::ContentInfo* content =
2154 cricket::GetFirstAudioContent(offer->description());
2155 EXPECT_TRUE(content != NULL);
2156 content = cricket::GetFirstVideoContent(offer->description());
2157 EXPECT_TRUE(content == NULL);
2158}
2159
2160// Test that an offer contains audio and video media content descriptions if
2161// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2162TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002163 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002165 PeerConnectionInterface::RTCOfferAnswerOptions options;
2166 options.offer_to_receive_audio =
2167 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2168 options.offer_to_receive_video =
2169 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2170
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002171 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002172 CreateOffer(options));
2173
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002174 const cricket::ContentInfo* content =
2175 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002176 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002177
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002178 content = cricket::GetFirstVideoContent(offer->description());
2179 EXPECT_TRUE(content != NULL);
2180
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002181 // Sets constraints to false and verifies that audio/video contents are
2182 // removed.
2183 options.offer_to_receive_audio = 0;
2184 options.offer_to_receive_video = 0;
2185 offer.reset(CreateOffer(options));
2186
2187 content = cricket::GetFirstAudioContent(offer->description());
2188 EXPECT_TRUE(content == NULL);
2189 content = cricket::GetFirstVideoContent(offer->description());
2190 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191}
2192
2193// Test that an answer can not be created if the last remote description is not
2194// an offer.
2195TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002196 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002197 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002198 SetLocalDescriptionWithoutError(offer);
2199 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2200 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002201 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002202}
2203
2204// Test that an answer contains the correct media content descriptions when no
2205// constraints have been set.
2206TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002207 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002209 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002211 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002212 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213 const cricket::ContentInfo* content =
2214 cricket::GetFirstAudioContent(answer->description());
2215 ASSERT_TRUE(content != NULL);
2216 EXPECT_FALSE(content->rejected);
2217
2218 content = cricket::GetFirstVideoContent(answer->description());
2219 ASSERT_TRUE(content != NULL);
2220 EXPECT_FALSE(content->rejected);
2221}
2222
2223// Test that an answer contains the correct media content descriptions when no
2224// constraints have been set and the offer only contain audio.
2225TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002226 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227 // Create a remote offer with audio only.
2228 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002229
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002230 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 CreateRemoteOffer(options));
2232 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2233 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2234
2235 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002236 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002237 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 const cricket::ContentInfo* content =
2239 cricket::GetFirstAudioContent(answer->description());
2240 ASSERT_TRUE(content != NULL);
2241 EXPECT_FALSE(content->rejected);
2242
2243 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2244}
2245
2246// Test that an answer contains the correct media content descriptions when no
2247// constraints have been set.
2248TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002249 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002251 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252 SetRemoteDescriptionWithoutError(offer.release());
2253 // Test with a stream with tracks.
2254 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002255 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002256 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257 const cricket::ContentInfo* content =
2258 cricket::GetFirstAudioContent(answer->description());
2259 ASSERT_TRUE(content != NULL);
2260 EXPECT_FALSE(content->rejected);
2261
2262 content = cricket::GetFirstVideoContent(answer->description());
2263 ASSERT_TRUE(content != NULL);
2264 EXPECT_FALSE(content->rejected);
2265}
2266
2267// Test that an answer contains the correct media content descriptions when
2268// constraints have been set but no stream is sent.
2269TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002270 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002271 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002272 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002273 SetRemoteDescriptionWithoutError(offer.release());
2274
2275 webrtc::FakeConstraints constraints_no_receive;
2276 constraints_no_receive.SetMandatoryReceiveAudio(false);
2277 constraints_no_receive.SetMandatoryReceiveVideo(false);
2278
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002279 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002280 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281 const cricket::ContentInfo* content =
2282 cricket::GetFirstAudioContent(answer->description());
2283 ASSERT_TRUE(content != NULL);
2284 EXPECT_TRUE(content->rejected);
2285
2286 content = cricket::GetFirstVideoContent(answer->description());
2287 ASSERT_TRUE(content != NULL);
2288 EXPECT_TRUE(content->rejected);
2289}
2290
2291// Test that an answer contains the correct media content descriptions when
2292// constraints have been set and streams are sent.
2293TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002294 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002296 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297 SetRemoteDescriptionWithoutError(offer.release());
2298
2299 webrtc::FakeConstraints constraints_no_receive;
2300 constraints_no_receive.SetMandatoryReceiveAudio(false);
2301 constraints_no_receive.SetMandatoryReceiveVideo(false);
2302
2303 // Test with a stream with tracks.
2304 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002305 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002306 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002307
2308 // TODO(perkj): Should the direction be set to SEND_ONLY?
2309 const cricket::ContentInfo* content =
2310 cricket::GetFirstAudioContent(answer->description());
2311 ASSERT_TRUE(content != NULL);
2312 EXPECT_FALSE(content->rejected);
2313
2314 // TODO(perkj): Should the direction be set to SEND_ONLY?
2315 content = cricket::GetFirstVideoContent(answer->description());
2316 ASSERT_TRUE(content != NULL);
2317 EXPECT_FALSE(content->rejected);
2318}
2319
2320TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2321 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002322 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002323 PeerConnectionInterface::RTCOfferAnswerOptions options;
2324 options.offer_to_receive_audio =
2325 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2326 options.voice_activity_detection = false;
2327
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002328 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002329 CreateOffer(options));
2330
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331 const cricket::ContentInfo* content =
2332 cricket::GetFirstAudioContent(offer->description());
2333 EXPECT_TRUE(content != NULL);
2334 EXPECT_TRUE(VerifyNoCNCodecs(content));
2335}
2336
2337TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2338 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002339 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002340 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002341 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342 SetRemoteDescriptionWithoutError(offer.release());
2343
2344 webrtc::FakeConstraints constraints;
2345 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002346 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002347 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348 const cricket::ContentInfo* content =
2349 cricket::GetFirstAudioContent(answer->description());
2350 ASSERT_TRUE(content != NULL);
2351 EXPECT_TRUE(VerifyNoCNCodecs(content));
2352}
2353
2354// This test verifies the call setup when remote answer with audio only and
2355// later updates with video.
2356TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002357 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2359 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2360
2361 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002362 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363
2364 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2366
2367 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2368 // and answer;
2369 SetLocalDescriptionWithoutError(offer);
2370 SetRemoteDescriptionWithoutError(answer);
2371
2372 video_channel_ = media_engine_->GetVideoChannel(0);
2373 voice_channel_ = media_engine_->GetVoiceChannel(0);
2374
2375 ASSERT_TRUE(video_channel_ == NULL);
2376
2377 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2378 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2379 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2380
2381 // Let the remote end update the session descriptions, with Audio and Video.
2382 mediastream_signaling_.SendAudioVideoStream2();
2383 CreateAndSetRemoteOfferAndLocalAnswer();
2384
2385 video_channel_ = media_engine_->GetVideoChannel(0);
2386 voice_channel_ = media_engine_->GetVoiceChannel(0);
2387
2388 ASSERT_TRUE(video_channel_ != NULL);
2389 ASSERT_TRUE(voice_channel_ != NULL);
2390
2391 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2392 ASSERT_EQ(1u, video_channel_->send_streams().size());
2393 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2394 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2395 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2396 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2397 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2398 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2399
2400 // Change session back to audio only.
2401 mediastream_signaling_.UseOptionsAudioOnly();
2402 CreateAndSetRemoteOfferAndLocalAnswer();
2403
2404 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2405 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2406 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2407 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2408 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2409}
2410
2411// This test verifies the call setup when remote answer with video only and
2412// later updates with audio.
2413TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002414 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002415 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2416 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2417 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002418 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419
2420 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002421 options.recv_audio = false;
2422 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002423 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2424 offer, options, cricket::SEC_ENABLED);
2425
2426 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2427 // and answer.
2428 SetLocalDescriptionWithoutError(offer);
2429 SetRemoteDescriptionWithoutError(answer);
2430
2431 video_channel_ = media_engine_->GetVideoChannel(0);
2432 voice_channel_ = media_engine_->GetVoiceChannel(0);
2433
2434 ASSERT_TRUE(voice_channel_ == NULL);
2435 ASSERT_TRUE(video_channel_ != NULL);
2436
2437 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2438 ASSERT_EQ(1u, video_channel_->send_streams().size());
2439 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2440
2441 // Update the session descriptions, with Audio and Video.
2442 mediastream_signaling_.SendAudioVideoStream2();
2443 CreateAndSetRemoteOfferAndLocalAnswer();
2444
2445 voice_channel_ = media_engine_->GetVoiceChannel(0);
2446 ASSERT_TRUE(voice_channel_ != NULL);
2447
2448 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2449 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2450 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2451 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2452
2453 // Change session back to video only.
2454 mediastream_signaling_.UseOptionsVideoOnly();
2455 CreateAndSetRemoteOfferAndLocalAnswer();
2456
2457 video_channel_ = media_engine_->GetVideoChannel(0);
2458 voice_channel_ = media_engine_->GetVoiceChannel(0);
2459
2460 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2461 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2462 ASSERT_EQ(1u, video_channel_->send_streams().size());
2463 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2464}
2465
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002466TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002467 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002468 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002469 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002470 VerifyCryptoParams(offer->description());
2471 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002472 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002473 VerifyCryptoParams(answer->description());
2474}
2475
2476TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002477 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002478 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002479 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002480 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481 VerifyNoCryptoParams(offer->description(), false);
2482}
2483
2484TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002485 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002486 VerifyAnswerFromNonCryptoOffer();
2487}
2488
2489TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002490 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002491 VerifyAnswerFromCryptoOffer();
2492}
2493
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002494// This test verifies that setLocalDescription fails if
2495// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2496TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
2497 Init(NULL);
2498 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002499 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2500
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002501 std::string sdp;
2502 RemoveIceUfragPwdLines(offer.get(), &sdp);
2503 SessionDescriptionInterface* modified_offer =
2504 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002505 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002506}
2507
2508// This test verifies that setRemoteDescription fails if
2509// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2510TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
2511 Init(NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002512 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002513 std::string sdp;
2514 RemoveIceUfragPwdLines(offer.get(), &sdp);
2515 SessionDescriptionInterface* modified_offer =
2516 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002517 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002518}
2519
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002520// This test verifies that setLocalDescription fails if local offer has
2521// too short ice ufrag and pwd strings.
2522TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
2523 Init(NULL);
2524 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
2525 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002526 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2527
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002528 std::string sdp;
2529 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2530 // recommended values of 4 and 22 bytes respectively.
2531 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2532 SessionDescriptionInterface* modified_offer =
2533 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2534 std::string error;
2535 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2536
2537 // Test with string greater than 256.
2538 sdp.clear();
2539 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2540 &sdp);
2541 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2542 NULL);
2543 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2544}
2545
2546// This test verifies that setRemoteDescription fails if remote offer has
2547// too short ice ufrag and pwd strings.
2548TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
2549 Init(NULL);
2550 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002551 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002552 std::string sdp;
2553 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2554 // recommended values of 4 and 22 bytes respectively.
2555 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2556 SessionDescriptionInterface* modified_offer =
2557 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2558 std::string error;
2559 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2560
2561 sdp.clear();
2562 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2563 &sdp);
2564 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2565 NULL);
2566 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2567}
2568
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002569TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) {
2570 // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in
2571 // local description is removed by the application, BUNDLE flag should be
2572 // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc.
wu@webrtc.org91053e72013-08-10 07:18:04 +00002573 Init(NULL);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002574 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2575 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002576 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2577
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002578 cricket::SessionDescription* offer_copy =
2579 offer->description()->Copy();
2580 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2581 JsepSessionDescription* modified_offer =
2582 new JsepSessionDescription(JsepSessionDescription::kOffer);
2583 modified_offer->Initialize(offer_copy, "1", "1");
2584
2585 SetLocalDescriptionWithoutError(modified_offer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002586 EXPECT_FALSE(allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002587}
2588
2589TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002590 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002591 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002592 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2593 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002594
2595 PeerConnectionInterface::RTCOfferAnswerOptions options;
2596 options.use_rtp_mux = true;
2597
2598 SessionDescriptionInterface* offer = CreateOffer(options);
2599
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600 SetLocalDescriptionWithoutError(offer);
2601 mediastream_signaling_.SendAudioVideoStream2();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002602 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002603 CreateRemoteAnswer(session_->local_description()));
2604 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2605 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2606 JsepSessionDescription* modified_answer =
2607 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2608 modified_answer->Initialize(answer_copy, "1", "1");
2609 SetRemoteDescriptionWithoutError(modified_answer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002610 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2611 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002612
2613 video_channel_ = media_engine_->GetVideoChannel(0);
2614 voice_channel_ = media_engine_->GetVoiceChannel(0);
2615
2616 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2617 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
2618
2619 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2620 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
2621
2622 ASSERT_EQ(1u, video_channel_->send_streams().size());
2623 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
2624 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2625 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
2626}
2627
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002628// This test verifies that SetLocalDescription and SetRemoteDescription fails
2629// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2630TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002631 WebRtcSessionTest::Init(NULL);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002632 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002633 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2634 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002635
2636 PeerConnectionInterface::RTCOfferAnswerOptions options;
2637 options.use_rtp_mux = true;
2638
2639 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002640 std::string offer_str;
2641 offer->ToString(&offer_str);
2642 // Disable rtcp-mux
2643 const std::string rtcp_mux = "rtcp-mux";
2644 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002645 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002646 xrtcp_mux.c_str(), xrtcp_mux.length(),
2647 &offer_str);
2648 JsepSessionDescription *local_offer =
2649 new JsepSessionDescription(JsepSessionDescription::kOffer);
2650 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002651 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002652 JsepSessionDescription *remote_offer =
2653 new JsepSessionDescription(JsepSessionDescription::kOffer);
2654 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002655 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002656 // Trying unmodified SDP.
2657 SetLocalDescriptionWithoutError(offer);
2658}
2659
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002660TEST_F(WebRtcSessionTest, SetAudioPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002661 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002662 mediastream_signaling_.SendAudioVideoStream1();
2663 CreateAndSetRemoteOfferAndLocalAnswer();
2664 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2665 ASSERT_TRUE(channel != NULL);
2666 ASSERT_EQ(1u, channel->recv_streams().size());
2667 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2668 double left_vol, right_vol;
2669 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2670 EXPECT_EQ(1, left_vol);
2671 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002672 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002673 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002674 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2675 EXPECT_EQ(0, left_vol);
2676 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002677 EXPECT_EQ(0, renderer->channel_id());
2678 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002679 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2680 EXPECT_EQ(1, left_vol);
2681 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002682 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002683}
2684
2685TEST_F(WebRtcSessionTest, SetAudioSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002686 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002687 mediastream_signaling_.SendAudioVideoStream1();
2688 CreateAndSetRemoteOfferAndLocalAnswer();
2689 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2690 ASSERT_TRUE(channel != NULL);
2691 ASSERT_EQ(1u, channel->send_streams().size());
2692 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2693 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2694
2695 cricket::AudioOptions options;
2696 options.echo_cancellation.Set(true);
2697
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002698 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002699 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002700 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2701 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002702 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002703 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002704
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002705 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002706 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002707 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2708 bool value;
2709 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2710 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002711 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002712 EXPECT_TRUE(renderer->sink() == NULL);
2713}
2714
2715TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
2716 Init(NULL);
2717 mediastream_signaling_.SendAudioVideoStream1();
2718 CreateAndSetRemoteOfferAndLocalAnswer();
2719 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2720 ASSERT_TRUE(channel != NULL);
2721 ASSERT_EQ(1u, channel->send_streams().size());
2722 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2723
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002724 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002725 cricket::AudioOptions options;
2726 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
2727 EXPECT_TRUE(renderer->sink() != NULL);
2728
2729 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
2730 // will invalidate the |renderer_| pointer in the sink and prevent getting a
2731 // SetSink(NULL) callback afterwards.
2732 renderer.reset();
2733
2734 // This will trigger SetSink(NULL) if no OnClose() callback.
2735 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002736}
2737
2738TEST_F(WebRtcSessionTest, SetVideoPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002739 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002740 mediastream_signaling_.SendAudioVideoStream1();
2741 CreateAndSetRemoteOfferAndLocalAnswer();
2742 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2743 ASSERT_TRUE(channel != NULL);
2744 ASSERT_LT(0u, channel->renderers().size());
2745 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2746 ASSERT_EQ(1u, channel->recv_streams().size());
2747 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2748 cricket::FakeVideoRenderer renderer;
2749 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2750 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2751 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2752 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2753}
2754
2755TEST_F(WebRtcSessionTest, SetVideoSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002756 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002757 mediastream_signaling_.SendAudioVideoStream1();
2758 CreateAndSetRemoteOfferAndLocalAnswer();
2759 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2760 ASSERT_TRUE(channel != NULL);
2761 ASSERT_EQ(1u, channel->send_streams().size());
2762 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2763 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2764 cricket::VideoOptions* options = NULL;
2765 session_->SetVideoSend(send_ssrc, false, options);
2766 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2767 session_->SetVideoSend(send_ssrc, true, options);
2768 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2769}
2770
2771TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2772 TestCanInsertDtmf(false);
2773}
2774
2775TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2776 TestCanInsertDtmf(true);
2777}
2778
2779TEST_F(WebRtcSessionTest, InsertDtmf) {
2780 // Setup
wu@webrtc.org91053e72013-08-10 07:18:04 +00002781 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002782 mediastream_signaling_.SendAudioVideoStream1();
2783 CreateAndSetRemoteOfferAndLocalAnswer();
2784 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2785 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2786
2787 // Insert DTMF
2788 const int expected_flags = DF_SEND;
2789 const int expected_duration = 90;
2790 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2791 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2792 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2793
2794 // Verify
2795 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2796 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2797 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2798 expected_duration, expected_flags));
2799 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2800 expected_duration, expected_flags));
2801 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2802 expected_duration, expected_flags));
2803}
2804
2805// This test verifies the |initiator| flag when session initiates the call.
2806TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002807 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002808 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002809 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002810 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2811 SetLocalDescriptionWithoutError(offer);
2812 EXPECT_TRUE(session_->initiator());
2813 SetRemoteDescriptionWithoutError(answer);
2814 EXPECT_TRUE(session_->initiator());
2815}
2816
2817// This test verifies the |initiator| flag when session receives the call.
2818TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002819 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002820 EXPECT_FALSE(session_->initiator());
2821 SessionDescriptionInterface* offer = CreateRemoteOffer();
2822 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002823 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002824
2825 EXPECT_FALSE(session_->initiator());
2826 SetLocalDescriptionWithoutError(answer);
2827 EXPECT_FALSE(session_->initiator());
2828}
2829
2830// This test verifies the ice protocol type at initiator of the call
2831// if |a=ice-options:google-ice| is present in answer.
2832TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002833 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002834 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002835 SessionDescriptionInterface* offer = CreateOffer();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002836 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002837 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002838 SetLocalDescriptionWithoutError(offer);
2839 std::string sdp;
2840 EXPECT_TRUE(answer->ToString(&sdp));
2841 // Adding ice-options to the session level.
2842 InjectAfter("t=0 0\r\n",
2843 "a=ice-options:google-ice\r\n",
2844 &sdp);
2845 SessionDescriptionInterface* answer_with_gice =
2846 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2847 SetRemoteDescriptionWithoutError(answer_with_gice);
2848 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2849 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2850}
2851
2852// This test verifies the ice protocol type at initiator of the call
2853// if ICE RFC5245 is supported in answer.
2854TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002855 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002856 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002857 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002858 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2859 SetLocalDescriptionWithoutError(offer);
2860
2861 SetRemoteDescriptionWithoutError(answer);
2862 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2863 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2864}
2865
2866// This test verifies the ice protocol type at receiver side of the call if
2867// receiver decides to use google-ice.
2868TEST_F(WebRtcSessionTest, TestReceiverGIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002869 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002870 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002871 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002872 SetRemoteDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002873 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002874 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002875 std::string sdp;
2876 EXPECT_TRUE(answer->ToString(&sdp));
2877 // Adding ice-options to the session level.
2878 InjectAfter("t=0 0\r\n",
2879 "a=ice-options:google-ice\r\n",
2880 &sdp);
2881 SessionDescriptionInterface* answer_with_gice =
2882 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2883 SetLocalDescriptionWithoutError(answer_with_gice);
2884 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2885 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2886}
2887
2888// This test verifies the ice protocol type at receiver side of the call if
2889// receiver decides to use ice RFC 5245.
2890TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002891 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002892 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002893 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002894 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002895 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002896 SetLocalDescriptionWithoutError(answer);
2897 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2898 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2899}
2900
2901// This test verifies the session state when ICE RFC5245 in offer and
2902// ICE google-ice in answer.
2903TEST_F(WebRtcSessionTest, TestIceOfferGIceOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002904 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002905 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002906 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2907
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002908 std::string offer_str;
2909 offer->ToString(&offer_str);
2910 // Disable google-ice
2911 const std::string gice_option = "google-ice";
2912 const std::string xgoogle_xice = "xgoogle-xice";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002913 rtc::replace_substrs(gice_option.c_str(), gice_option.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002914 xgoogle_xice.c_str(), xgoogle_xice.length(),
2915 &offer_str);
2916 JsepSessionDescription *ice_only_offer =
2917 new JsepSessionDescription(JsepSessionDescription::kOffer);
2918 EXPECT_TRUE((ice_only_offer)->Initialize(offer_str, NULL));
2919 SetLocalDescriptionWithoutError(ice_only_offer);
2920 std::string original_offer_sdp;
2921 EXPECT_TRUE(offer->ToString(&original_offer_sdp));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002922 SessionDescriptionInterface* pranswer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002923 CreateSessionDescription(JsepSessionDescription::kPrAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002924 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002925 SetRemoteDescriptionPranswerExpectError(kPushDownTDFailed,
2926 pranswer_with_gice);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002927 SessionDescriptionInterface* answer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002928 CreateSessionDescription(JsepSessionDescription::kAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002929 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002930 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed,
2931 answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002932}
2933
2934// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2935TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002936 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002937 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002938 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002939 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002940 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002941 CreateRemoteAnswer(session_->local_description()));
2942
2943 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2944 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002945 JsepSessionDescription* modified_answer =
2946 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002947
2948 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2949 answer->session_id(),
2950 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002951 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002952
wu@webrtc.org4e393072014-04-07 17:04:35 +00002953 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002954 std::string sdp;
2955 EXPECT_TRUE(answer->ToString(&sdp));
2956 const std::string kAudioMid = "a=mid:audio";
2957 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002958 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002959 kAudioMidReplaceStr.c_str(),
2960 kAudioMidReplaceStr.length(),
2961 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002962 SessionDescriptionInterface* modified_answer1 =
2963 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002964 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002965
wu@webrtc.org4e393072014-04-07 17:04:35 +00002966 // Different media types.
2967 EXPECT_TRUE(answer->ToString(&sdp));
2968 const std::string kAudioMline = "m=audio";
2969 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002970 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00002971 kAudioMlineReplaceStr.c_str(),
2972 kAudioMlineReplaceStr.length(),
2973 &sdp);
2974 SessionDescriptionInterface* modified_answer2 =
2975 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2976 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
2977
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002978 SetRemoteDescriptionWithoutError(answer.release());
2979}
2980
2981// Verifying remote offer and local answer have matching m-lines as per
2982// RFC 3264.
2983TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002984 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002985 mediastream_signaling_.SendAudioVideoStream1();
2986 SessionDescriptionInterface* offer = CreateRemoteOffer();
2987 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002988 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002989
2990 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2991 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002992 JsepSessionDescription* modified_answer =
2993 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002994
2995 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2996 answer->session_id(),
2997 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002998 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002999 SetLocalDescriptionWithoutError(answer);
3000}
3001
3002// This test verifies that WebRtcSession does not start candidate allocation
3003// before SetLocalDescription is called.
3004TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00003005 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003006 mediastream_signaling_.SendAudioVideoStream1();
3007 SessionDescriptionInterface* offer = CreateRemoteOffer();
3008 cricket::Candidate candidate;
3009 candidate.set_component(1);
3010 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3011 candidate);
3012 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3013 cricket::Candidate candidate1;
3014 candidate1.set_component(1);
3015 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3016 candidate1);
3017 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3018 SetRemoteDescriptionWithoutError(offer);
3019 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
3020 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
3021
3022 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003023 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003024 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3025 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3026
wu@webrtc.org91053e72013-08-10 07:18:04 +00003027 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003028 SetLocalDescriptionWithoutError(answer);
3029 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
3030 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
3031 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3032}
3033
3034// This test verifies that crypto parameter is updated in local session
3035// description as per security policy set in MediaSessionDescriptionFactory.
3036TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00003037 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003038 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003039 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003040
3041 // Making sure SetLocalDescription correctly sets crypto value in
3042 // SessionDescription object after de-serialization of sdp string. The value
3043 // will be set as per MediaSessionDescriptionFactory.
3044 std::string offer_str;
3045 offer->ToString(&offer_str);
3046 SessionDescriptionInterface* jsep_offer_str =
3047 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3048 SetLocalDescriptionWithoutError(jsep_offer_str);
3049 EXPECT_TRUE(session_->voice_channel()->secure_required());
3050 EXPECT_TRUE(session_->video_channel()->secure_required());
3051}
3052
3053// This test verifies the crypto parameter when security is disabled.
3054TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003055 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003056 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003057 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003058 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003059
3060 // Making sure SetLocalDescription correctly sets crypto value in
3061 // SessionDescription object after de-serialization of sdp string. The value
3062 // will be set as per MediaSessionDescriptionFactory.
3063 std::string offer_str;
3064 offer->ToString(&offer_str);
3065 SessionDescriptionInterface *jsep_offer_str =
3066 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3067 SetLocalDescriptionWithoutError(jsep_offer_str);
3068 EXPECT_FALSE(session_->voice_channel()->secure_required());
3069 EXPECT_FALSE(session_->video_channel()->secure_required());
3070}
3071
3072// This test verifies that an answer contains new ufrag and password if an offer
3073// with new ufrag and password is received.
3074TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00003075 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003076 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003077 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003078 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003079 CreateRemoteOffer(options));
3080 SetRemoteDescriptionWithoutError(offer.release());
3081
3082 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003083 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003084 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003085 SetLocalDescriptionWithoutError(answer.release());
3086
3087 // Receive an offer with new ufrag and password.
3088 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003089 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003090 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003091 SetRemoteDescriptionWithoutError(updated_offer1.release());
3092
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003093 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003094 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003095
3096 CompareIceUfragAndPassword(updated_answer1->description(),
3097 session_->local_description()->description(),
3098 false);
3099
3100 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003101}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003102
wu@webrtc.org91053e72013-08-10 07:18:04 +00003103// This test verifies that an answer contains old ufrag and password if an offer
3104// with old ufrag and password is received.
3105TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
3106 Init(NULL);
3107 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003108 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003109 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003110 CreateRemoteOffer(options));
3111 SetRemoteDescriptionWithoutError(offer.release());
3112
3113 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003114 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003115 CreateAnswer(NULL));
3116 SetLocalDescriptionWithoutError(answer.release());
3117
3118 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003119 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003120 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003121 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003122 SetRemoteDescriptionWithoutError(updated_offer2.release());
3123
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003124 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003125 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003126
3127 CompareIceUfragAndPassword(updated_answer2->description(),
3128 session_->local_description()->description(),
3129 true);
3130
3131 SetLocalDescriptionWithoutError(updated_answer2.release());
3132}
3133
3134TEST_F(WebRtcSessionTest, TestSessionContentError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00003135 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003136 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003137 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003138 const std::string session_id_orig = offer->session_id();
3139 const std::string session_version_orig = offer->session_version();
3140 SetLocalDescriptionWithoutError(offer);
3141
3142 video_channel_ = media_engine_->GetVideoChannel(0);
3143 video_channel_->set_fail_set_send_codecs(true);
3144
3145 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003146 SessionDescriptionInterface* answer =
3147 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003148 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003149}
3150
3151// Runs the loopback call test with BUNDLE and STUN disabled.
3152TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3153 // Lets try with only UDP ports.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003154 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003155 cricket::PORTALLOCATOR_DISABLE_TCP |
3156 cricket::PORTALLOCATOR_DISABLE_STUN |
3157 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003158 TestLoopbackCall();
3159}
3160
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003161TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
3162 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3163 cricket::PORTALLOCATOR_DISABLE_TCP |
3164 cricket::PORTALLOCATOR_DISABLE_STUN |
3165 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3166 cricket::PORTALLOCATOR_DISABLE_RELAY);
3167
3168 // best connection is IPv6 since it has higher network preference.
3169 LoopbackNetworkConfiguration config;
3170 config.test_ipv6_network_ = true;
3171 config.best_connection_after_initial_ice_converged_ =
3172 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3173
3174 TestLoopbackCall(config);
3175}
3176
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003177// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003178TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003179 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003180 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003181 cricket::PORTALLOCATOR_DISABLE_TCP |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003182 cricket::PORTALLOCATOR_DISABLE_RELAY);
3183 TestLoopbackCall();
3184}
3185
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003186TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00003187 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003188 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003189 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003190
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003191 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3192 std::string error_code_str = "ERROR_CONTENT";
3193 std::string error_desc = "Fake session error description.";
3194 session_->SetError(error_code, error_desc);
3195
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003196 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3197 SessionDescriptionInterface* answer =
3198 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003199
3200 std::string action;
3201 std::ostringstream session_error_msg;
3202 session_error_msg << kSessionError << error_code_str << ". ";
3203 session_error_msg << kSessionErrorDesc << error_desc << ".";
3204 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3205 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003206}
3207
3208TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3209 constraints_.reset(new FakeConstraints());
3210 constraints_->AddOptional(
3211 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003212 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003213
3214 SetLocalDescriptionWithDataChannel();
3215 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3216}
3217
3218TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003219 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003220
3221 constraints_.reset(new FakeConstraints());
3222 constraints_->AddOptional(
3223 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003224 options_.disable_sctp_data_channels = false;
3225
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003226 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003227
3228 SetLocalDescriptionWithDataChannel();
3229 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3230}
3231
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003232TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003233 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003234
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003235 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003236
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003237 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003238 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003239 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3240}
3241
3242TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003243 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003244 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003245 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003246
3247 // Create remote offer with SCTP.
3248 cricket::MediaSessionOptions options;
3249 options.data_channel_type = cricket::DCT_SCTP;
3250 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003251 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003252 SetRemoteDescriptionWithoutError(offer);
3253
3254 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003255 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003256 EXPECT_TRUE(answer != NULL);
3257 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3258 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003259}
3260
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003261TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3262 constraints_.reset(new FakeConstraints());
3263 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003264 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003265 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003266
3267 SetLocalDescriptionWithDataChannel();
3268 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3269}
3270
3271TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003272 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003273
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003274 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003275
3276 SetLocalDescriptionWithDataChannel();
3277 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3278}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003279
wu@webrtc.org97077a32013-10-25 21:18:33 +00003280TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003281 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003282 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003283 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003284
3285 SetLocalDescriptionWithDataChannel();
3286 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3287}
3288
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003289TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003290 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003291 const int new_send_port = 9998;
3292 const int new_recv_port = 7775;
3293
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003294 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003295 SetFactoryDtlsSrtp();
3296
3297 // By default, don't actually add the codecs to desc_factory_; they don't
3298 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3299 // let the session description get parsed. That'll get the proper codecs
3300 // into the stream.
3301 cricket::MediaSessionOptions options;
3302 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3303 "stream1", new_send_port, options);
3304
3305 // SetRemoteDescription will take the ownership of the offer.
3306 SetRemoteDescriptionWithoutError(offer);
3307
3308 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3309 new_recv_port, CreateAnswer(NULL));
3310 ASSERT_TRUE(answer != NULL);
3311
3312 // Now set the local description, which'll take ownership of the answer.
3313 SetLocalDescriptionWithoutError(answer);
3314
3315 // TEST PLAN: Set the port number to something new, set it in the SDP,
3316 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003317 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003318 dci.reliable = true;
3319 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003320 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003321 session_->CreateDataChannel("datachannel", &dci);
3322
3323 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3324 int portnum = -1;
3325 ASSERT_TRUE(ch != NULL);
3326 ASSERT_EQ(1UL, ch->send_codecs().size());
3327 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
3328 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3329 ch->send_codecs()[0].name.c_str()));
3330 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3331 &portnum));
3332 EXPECT_EQ(new_send_port, portnum);
3333
3334 ASSERT_EQ(1UL, ch->recv_codecs().size());
3335 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
3336 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3337 ch->recv_codecs()[0].name.c_str()));
3338 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3339 &portnum));
3340 EXPECT_EQ(new_recv_port, portnum);
3341}
3342
wu@webrtc.org91053e72013-08-10 07:18:04 +00003343// Verifies that CreateOffer succeeds when CreateOffer is called before async
3344// identity generation is finished.
3345TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003346 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003347 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003348
3349 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003350 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003351 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3352
wu@webrtc.org91053e72013-08-10 07:18:04 +00003353 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003354 VerifyNoCryptoParams(offer->description(), true);
3355 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003356}
3357
3358// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3359// identity generation is finished.
3360TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003361 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003362 InitWithDtls();
3363 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003364
3365 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003366 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003367 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003368 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003369 ASSERT_TRUE(offer.get() != NULL);
3370 SetRemoteDescriptionWithoutError(offer.release());
3371
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003372 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003373 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003374 VerifyNoCryptoParams(answer->description(), true);
3375 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003376}
3377
3378// Verifies that CreateOffer succeeds when CreateOffer is called after async
3379// identity generation is finished.
3380TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003381 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003382 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003383
3384 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003385
3386 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003387 EXPECT_TRUE(offer != NULL);
3388}
3389
3390// Verifies that CreateOffer fails when CreateOffer is called after async
3391// identity generation fails.
3392TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003393 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003394 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003395
3396 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003397
3398 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003399 EXPECT_TRUE(offer == NULL);
3400}
3401
3402// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3403// before async identity generation is finished.
3404TEST_F(WebRtcSessionTest,
3405 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003406 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003407 VerifyMultipleAsyncCreateDescription(
3408 true, CreateSessionDescriptionRequest::kOffer);
3409}
3410
3411// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3412// before async identity generation fails.
3413TEST_F(WebRtcSessionTest,
3414 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003415 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003416 VerifyMultipleAsyncCreateDescription(
3417 false, CreateSessionDescriptionRequest::kOffer);
3418}
3419
3420// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3421// before async identity generation is finished.
3422TEST_F(WebRtcSessionTest,
3423 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003424 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003425 VerifyMultipleAsyncCreateDescription(
3426 true, CreateSessionDescriptionRequest::kAnswer);
3427}
3428
3429// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3430// before async identity generation fails.
3431TEST_F(WebRtcSessionTest,
3432 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003433 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003434 VerifyMultipleAsyncCreateDescription(
3435 false, CreateSessionDescriptionRequest::kAnswer);
3436}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003437
3438// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3439// offer has no SDES crypto but only DTLS fingerprint.
3440TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3441 // Init without DTLS.
3442 Init(NULL);
3443 // Create a remote offer with secured transport disabled.
3444 cricket::MediaSessionOptions options;
3445 JsepSessionDescription* offer(CreateRemoteOffer(
3446 options, cricket::SEC_DISABLED));
3447 // Adds a DTLS fingerprint to the remote offer.
3448 cricket::SessionDescription* sdp = offer->description();
3449 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3450 ASSERT_TRUE(audio != NULL);
3451 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3452 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003453 rtc::SSLFingerprint::CreateFromRfc4572(
3454 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003455 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003456 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003457}
3458
wu@webrtc.orgde305012013-10-31 15:40:38 +00003459// This test verifies DSCP is properly applied on the media channels.
3460TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3461 constraints_.reset(new FakeConstraints());
3462 constraints_->AddOptional(
3463 webrtc::MediaConstraintsInterface::kEnableDscp, true);
3464 Init(NULL);
3465 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003466 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003467
3468 SetLocalDescriptionWithoutError(offer);
3469
3470 video_channel_ = media_engine_->GetVideoChannel(0);
3471 voice_channel_ = media_engine_->GetVoiceChannel(0);
3472
3473 ASSERT_TRUE(video_channel_ != NULL);
3474 ASSERT_TRUE(voice_channel_ != NULL);
3475 cricket::AudioOptions audio_options;
3476 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3477 cricket::VideoOptions video_options;
3478 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3479 EXPECT_TRUE(audio_options.dscp.IsSet());
3480 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3481 EXPECT_TRUE(video_options.dscp.IsSet());
3482 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3483}
3484
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003485TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3486 constraints_.reset(new FakeConstraints());
3487 constraints_->AddOptional(
3488 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3489 true);
3490 Init(NULL);
3491 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003492 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003493
3494 SetLocalDescriptionWithoutError(offer);
3495
3496 video_channel_ = media_engine_->GetVideoChannel(0);
3497
3498 ASSERT_TRUE(video_channel_ != NULL);
3499 cricket::VideoOptions video_options;
3500 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3501 EXPECT_TRUE(
3502 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3503}
3504
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003505TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3506 // Number of unsignalled receiving streams should be between 0 and
3507 // kMaxUnsignalledRecvStreams.
3508 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3509 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3510 kMaxUnsignalledRecvStreams);
3511 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3512}
3513
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003514TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3515 constraints_.reset(new FakeConstraints());
3516 constraints_->AddOptional(
3517 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3518 true);
3519 Init(NULL);
3520 mediastream_signaling_.SendAudioVideoStream1();
3521 SessionDescriptionInterface* offer = CreateOffer();
3522
3523 SetLocalDescriptionWithoutError(offer);
3524
3525 voice_channel_ = media_engine_->GetVoiceChannel(0);
3526
3527 ASSERT_TRUE(voice_channel_ != NULL);
3528 cricket::AudioOptions audio_options;
3529 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3530 EXPECT_TRUE(
3531 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3532}
3533
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003534// Tests that we can renegotiate new media content with ICE candidates in the
3535// new remote SDP.
3536TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003537 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003538 InitWithDtls();
3539 SetFactoryDtlsSrtp();
3540
3541 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003542 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003543 SetLocalDescriptionWithoutError(offer);
3544
3545 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3546 SetRemoteDescriptionWithoutError(answer);
3547
3548 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003549 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003550 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3551
3552 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003553 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003554 candidate1.set_component(1);
3555 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3556 candidate1);
3557 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3558 SetRemoteDescriptionWithoutError(offer);
3559
3560 answer = CreateAnswer(NULL);
3561 SetLocalDescriptionWithoutError(answer);
3562}
3563
3564// Tests that we can renegotiate new media content with ICE candidates separated
3565// from the remote SDP.
3566TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003567 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003568 InitWithDtls();
3569 SetFactoryDtlsSrtp();
3570
3571 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003572 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003573 SetLocalDescriptionWithoutError(offer);
3574
3575 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3576 SetRemoteDescriptionWithoutError(answer);
3577
3578 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003579 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003580 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3581 SetRemoteDescriptionWithoutError(offer);
3582
3583 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003584 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003585 candidate1.set_component(1);
3586 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3587 candidate1);
3588 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3589
3590 answer = CreateAnswer(NULL);
3591 SetLocalDescriptionWithoutError(answer);
3592}
3593
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003594// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3595// currently fails because upon disconnection and reconnection OnIceComplete is
3596// called more than once without returning to IceGatheringGathering.