blob: e4f39f822b0ffacf7c8498706565a619f0c6f1bd [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"
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000046#include "webrtc/p2p/base/transportchannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000047#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000048#include "talk/session/media/channelmanager.h"
49#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000050#include "webrtc/base/fakenetwork.h"
51#include "webrtc/base/firewallsocketserver.h"
52#include "webrtc/base/gunit.h"
53#include "webrtc/base/logging.h"
54#include "webrtc/base/network.h"
55#include "webrtc/base/physicalsocketserver.h"
56#include "webrtc/base/ssladapter.h"
57#include "webrtc/base/sslstreamadapter.h"
58#include "webrtc/base/stringutils.h"
59#include "webrtc/base/thread.h"
60#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061
62#define MAYBE_SKIP_TEST(feature) \
63 if (!(feature())) { \
64 LOG(LS_INFO) << "Feature disabled... skipping"; \
65 return; \
66 }
67
68using cricket::BaseSession;
69using cricket::DF_PLAY;
70using cricket::DF_SEND;
71using cricket::FakeVoiceMediaChannel;
72using cricket::NS_GINGLE_P2P;
73using cricket::NS_JINGLE_ICE_UDP;
74using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000075using rtc::SocketAddress;
76using rtc::scoped_ptr;
77using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000079using webrtc::CreateSessionDescriptionObserver;
80using webrtc::CreateSessionDescriptionRequest;
81using webrtc::DTLSIdentityRequestObserver;
82using webrtc::DTLSIdentityServiceInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083using webrtc::FakeConstraints;
84using webrtc::IceCandidateCollection;
85using webrtc::JsepIceCandidate;
86using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000087using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088using webrtc::PeerConnectionInterface;
89using webrtc::SessionDescriptionInterface;
90using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000091using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000092using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000093using webrtc::kCreateChannelFailed;
94using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000096using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000097using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000098using webrtc::kSdpWithoutDtlsFingerprint;
99using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000101using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000102using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000104typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
105
wu@webrtc.org364f2042013-11-20 21:49:41 +0000106static const int kClientAddrPort = 0;
107static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000108static const char kClientIPv6AddrHost1[] =
109 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000110static const char kClientAddrHost2[] = "22.22.22.22";
111static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000112static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
113static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000114static const char kTurnUsername[] = "test";
115static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116
117static const char kSessionVersion[] = "1";
118
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119// Media index of candidates belonging to the first media content.
120static const int kMediaContentIndex0 = 0;
121static const char kMediaContentName0[] = "audio";
122
123// Media index of candidates belonging to the second media content.
124static const int kMediaContentIndex1 = 1;
125static const char kMediaContentName1[] = "video";
126
127static const int kIceCandidatesTimeout = 10000;
128
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000129static const char kFakeDtlsFingerprint[] =
130 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
131 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
132
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000133static const char kTooLongIceUfragPwd[] =
134 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
135 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
136 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
137 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
138
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000139static const char kSdpWithRtx[] =
140 "v=0\r\n"
141 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
142 "s=-\r\n"
143 "t=0 0\r\n"
144 "a=msid-semantic: WMS stream1\r\n"
145 "m=video 9 RTP/SAVPF 0 96\r\n"
146 "c=IN IP4 0.0.0.0\r\n"
147 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
148 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
149 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
150 "a=mid:video\r\n"
151 "a=sendrecv\r\n"
152 "a=rtcp-mux\r\n"
153 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
154 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
155 "a=rtpmap:0 fake_video_codec/90000\r\n"
156 "a=rtpmap:96 rtx/90000\r\n"
157 "a=fmtp:96 apt=0\r\n";
158
Henrik Lundin64dad832015-05-11 12:44:23 +0200159static const int kAudioJitterBufferMaxPackets = 50;
160
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161// Add some extra |newlines| to the |message| after |line|.
162static void InjectAfter(const std::string& line,
163 const std::string& newlines,
164 std::string* message) {
165 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000166 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 tmp.c_str(), tmp.length(), message);
168}
169
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000170class FakeMetricsObserver : public webrtc::MetricsObserverInterface {
171 public:
172 FakeMetricsObserver() { Reset(); }
173 void Reset() {
174 memset(peer_connection_metrics_counters_, 0,
175 sizeof(peer_connection_metrics_counters_));
176 memset(peer_connection_metrics_name_, 0,
177 sizeof(peer_connection_metrics_name_));
178 }
179
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000180 void IncrementCounter(webrtc::PeerConnectionMetricsCounter type) override {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000181 peer_connection_metrics_counters_[type]++;
182 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000183 void AddHistogramSample(webrtc::PeerConnectionMetricsName type,
184 int value) override {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000185 ASSERT(peer_connection_metrics_name_[type] == 0);
186 peer_connection_metrics_name_[type] = value;
187 }
188
189 int peer_connection_metrics_counters_
190 [webrtc::kPeerConnectionMetricsCounter_Max];
191 int peer_connection_metrics_name_[webrtc::kPeerConnectionMetricsCounter_Max];
192
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000193 int AddRef() override { return 1; }
194 int Release() override { return 1; }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000195};
196
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000197class MockIceObserver : public webrtc::IceObserver {
198 public:
199 MockIceObserver()
200 : oncandidatesready_(false),
201 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
202 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
203 }
204
205 virtual void OnIceConnectionChange(
206 PeerConnectionInterface::IceConnectionState new_state) {
207 ice_connection_state_ = new_state;
208 }
209 virtual void OnIceGatheringChange(
210 PeerConnectionInterface::IceGatheringState new_state) {
211 // We can never transition back to "new".
212 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
213 ice_gathering_state_ = new_state;
214
215 // oncandidatesready_ really means "ICE gathering is complete".
216 // This if statement ensures that this value remains correct when we
217 // transition from kIceGatheringComplete to kIceGatheringGathering.
218 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
219 oncandidatesready_ = false;
220 }
221 }
222
223 // Found a new candidate.
224 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000225 switch (candidate->sdp_mline_index()) {
226 case kMediaContentIndex0:
227 mline_0_candidates_.push_back(candidate->candidate());
228 break;
229 case kMediaContentIndex1:
230 mline_1_candidates_.push_back(candidate->candidate());
231 break;
232 default:
233 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000235
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236 // The ICE gathering state should always be Gathering when a candidate is
237 // received (or possibly Completed in the case of the final candidate).
238 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
239 }
240
241 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
242 virtual void OnIceComplete() {
243 EXPECT_FALSE(oncandidatesready_);
244 oncandidatesready_ = true;
245
246 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
247 // be called approximately simultaneously. For ease of testing, this
248 // check additionally requires that they be called in the above order.
249 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
250 ice_gathering_state_);
251 }
252
253 bool oncandidatesready_;
254 std::vector<cricket::Candidate> mline_0_candidates_;
255 std::vector<cricket::Candidate> mline_1_candidates_;
256 PeerConnectionInterface::IceConnectionState ice_connection_state_;
257 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
258};
259
260class WebRtcSessionForTest : public webrtc::WebRtcSession {
261 public:
262 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000263 rtc::Thread* signaling_thread,
264 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000265 cricket::PortAllocator* port_allocator,
266 webrtc::IceObserver* ice_observer,
267 webrtc::MediaStreamSignaling* mediastream_signaling)
268 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
269 mediastream_signaling) {
270 RegisterIceObserver(ice_observer);
271 }
272 virtual ~WebRtcSessionForTest() {}
273
274 using cricket::BaseSession::GetTransportProxy;
275 using webrtc::WebRtcSession::SetAudioPlayout;
276 using webrtc::WebRtcSession::SetAudioSend;
277 using webrtc::WebRtcSession::SetCaptureDevice;
278 using webrtc::WebRtcSession::SetVideoPlayout;
279 using webrtc::WebRtcSession::SetVideoSend;
280};
281
wu@webrtc.org91053e72013-08-10 07:18:04 +0000282class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000283 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000285 enum State {
286 kInit,
287 kFailed,
288 kSucceeded,
289 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000290 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000291
292 // CreateSessionDescriptionObserver implementation.
293 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000294 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000295 state_ = kSucceeded;
296 }
297 virtual void OnFailure(const std::string& error) {
298 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 }
300
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000301 SessionDescriptionInterface* description() { return description_.get(); }
302
303 SessionDescriptionInterface* ReleaseDescription() {
304 return description_.release();
305 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306
wu@webrtc.org91053e72013-08-10 07:18:04 +0000307 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308
wu@webrtc.org91053e72013-08-10 07:18:04 +0000309 protected:
310 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311
312 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000313 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000314 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315};
316
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000317class FakeAudioRenderer : public cricket::AudioRenderer {
318 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000319 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
320 virtual ~FakeAudioRenderer() {
321 if (sink_)
322 sink_->OnClose();
323 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000324
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000325 void AddChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000326 ASSERT(channel_id_ == -1);
327 channel_id_ = channel_id;
328 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000329 void RemoveChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000330 ASSERT(channel_id == channel_id_);
331 channel_id_ = -1;
332 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000333 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000334
335 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000336 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000337 private:
338 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000339 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000340};
341
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342class WebRtcSessionTest : public testing::Test {
343 protected:
344 // TODO Investigate why ChannelManager crashes, if it's created
345 // after stun_server.
346 WebRtcSessionTest()
347 : media_engine_(new cricket::FakeMediaEngine()),
348 data_engine_(new cricket::FakeDataEngine()),
349 device_manager_(new cricket::FakeDeviceManager()),
350 channel_manager_(new cricket::ChannelManager(
351 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000352 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 tdesc_factory_(new cricket::TransportDescriptionFactory()),
354 desc_factory_(new cricket::MediaSessionDescriptionFactory(
355 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000356 pss_(new rtc::PhysicalSocketServer),
357 vss_(new rtc::VirtualSocketServer(pss_.get())),
358 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000360 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000361 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000362 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
363 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000364 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000365 mediastream_signaling_(channel_manager_.get()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000367
368 cricket::ServerAddresses stun_servers;
369 stun_servers.insert(stun_socket_addr_);
370 allocator_.reset(new cricket::BasicPortAllocator(
371 &network_manager_,
372 stun_servers,
373 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000374 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375 cricket::PORTALLOCATOR_DISABLE_RELAY |
jiayl@webrtc.orgdacdd942015-01-23 17:33:34 +0000376 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377 EXPECT_TRUE(channel_manager_->Init());
378 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000379 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 }
381
382 void AddInterface(const SocketAddress& addr) {
383 network_manager_.AddInterface(addr);
384 }
385
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000386 void Init(
387 DTLSIdentityServiceInterface* identity_service,
Henrik Lundin64dad832015-05-11 12:44:23 +0200388 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000389 ASSERT_TRUE(session_.get() == NULL);
390 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000391 channel_manager_.get(), rtc::Thread::Current(),
392 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000393 &observer_,
394 &mediastream_signaling_));
395
396 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
397 observer_.ice_connection_state_);
398 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
399 observer_.ice_gathering_state_);
400
wu@webrtc.org97077a32013-10-25 21:18:33 +0000401 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
Henrik Lundin64dad832015-05-11 12:44:23 +0200402 identity_service, rtc_configuration));
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000403 session_->set_metrics_observer(&metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404 }
405
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000406 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200407 PeerConnectionInterface::RTCConfiguration configuration;
408 configuration.type = PeerConnectionInterface::kAll;
409 configuration.bundle_policy =
410 PeerConnectionInterface::kBundlePolicyBalanced;
411 configuration.audio_jitter_buffer_max_packets =
412 kAudioJitterBufferMaxPackets;
413 Init(NULL, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000414 }
415
416 void InitWithIceTransport(
417 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200418 PeerConnectionInterface::RTCConfiguration configuration;
419 configuration.type = ice_transport_type;
420 configuration.bundle_policy =
421 PeerConnectionInterface::kBundlePolicyBalanced;
422 configuration.audio_jitter_buffer_max_packets =
423 kAudioJitterBufferMaxPackets;
424 Init(NULL, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000425 }
426
427 void InitWithBundlePolicy(
428 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200429 PeerConnectionInterface::RTCConfiguration configuration;
430 configuration.type = PeerConnectionInterface::kAll;
431 configuration.bundle_policy = bundle_policy;
432 configuration.audio_jitter_buffer_max_packets =
433 kAudioJitterBufferMaxPackets;
434 Init(NULL, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000435 }
436
437 void InitWithDtls(bool identity_request_should_fail = false) {
438 FakeIdentityService* identity_service = new FakeIdentityService();
439 identity_service->set_should_fail(identity_request_should_fail);
Henrik Lundin64dad832015-05-11 12:44:23 +0200440 PeerConnectionInterface::RTCConfiguration configuration;
441 configuration.type = PeerConnectionInterface::kAll;
442 configuration.bundle_policy =
443 PeerConnectionInterface::kBundlePolicyBalanced;
444 configuration.audio_jitter_buffer_max_packets =
445 kAudioJitterBufferMaxPackets;
446 Init(identity_service, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000447 }
448
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449 void InitWithDtmfCodec() {
450 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000451 const cricket::AudioCodec kTelephoneEventCodec(
452 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453 std::vector<cricket::AudioCodec> codecs;
454 codecs.push_back(kTelephoneEventCodec);
455 media_engine_->SetAudioCodecs(codecs);
456 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000457 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458 }
459
460 // Creates a local offer and applies it. Starts ice.
461 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
462 // to decide which streams to create.
463 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000464 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465 SetLocalDescriptionWithoutError(offer);
466 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
467 observer_.ice_gathering_state_,
468 kIceCandidatesTimeout);
469 }
470
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000471 SessionDescriptionInterface* CreateOffer() {
472 PeerConnectionInterface::RTCOfferAnswerOptions options;
473 options.offer_to_receive_audio =
474 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
475
476 return CreateOffer(options);
477 }
478
wu@webrtc.org91053e72013-08-10 07:18:04 +0000479 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000480 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000481 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000482 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000483 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000484 EXPECT_TRUE_WAIT(
485 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000486 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000487 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000488 }
489
490 SessionDescriptionInterface* CreateAnswer(
491 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000492 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000493 = new WebRtcSessionCreateSDPObserverForTest();
494 session_->CreateAnswer(observer, constraints);
495 EXPECT_TRUE_WAIT(
496 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000497 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000498 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000499 }
500
wu@webrtc.org364f2042013-11-20 21:49:41 +0000501 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 return (session_->voice_channel() != NULL &&
503 session_->video_channel() != NULL);
504 }
505
wu@webrtc.org364f2042013-11-20 21:49:41 +0000506 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000507 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
508 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
509 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
510 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
511 }
512
513 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
514 ASSERT_TRUE(session_.get() != NULL);
515 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
516 ASSERT_TRUE(content != NULL);
517 const cricket::AudioContentDescription* audio_content =
518 static_cast<const cricket::AudioContentDescription*>(
519 content->description);
520 ASSERT_TRUE(audio_content != NULL);
521 ASSERT_EQ(1U, audio_content->cryptos().size());
522 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
523 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
524 audio_content->cryptos()[0].cipher_suite);
525 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
526 audio_content->protocol());
527
528 content = cricket::GetFirstVideoContent(sdp);
529 ASSERT_TRUE(content != NULL);
530 const cricket::VideoContentDescription* video_content =
531 static_cast<const cricket::VideoContentDescription*>(
532 content->description);
533 ASSERT_TRUE(video_content != NULL);
534 ASSERT_EQ(1U, video_content->cryptos().size());
535 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
536 video_content->cryptos()[0].cipher_suite);
537 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
538 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
539 video_content->protocol());
540 }
541
542 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
543 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
544 ASSERT_TRUE(content != NULL);
545 const cricket::AudioContentDescription* audio_content =
546 static_cast<const cricket::AudioContentDescription*>(
547 content->description);
548 ASSERT_TRUE(audio_content != NULL);
549 ASSERT_EQ(0U, audio_content->cryptos().size());
550
551 content = cricket::GetFirstVideoContent(sdp);
552 ASSERT_TRUE(content != NULL);
553 const cricket::VideoContentDescription* video_content =
554 static_cast<const cricket::VideoContentDescription*>(
555 content->description);
556 ASSERT_TRUE(video_content != NULL);
557 ASSERT_EQ(0U, video_content->cryptos().size());
558
559 if (dtls) {
560 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
561 audio_content->protocol());
562 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
563 video_content->protocol());
564 } else {
565 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
566 audio_content->protocol());
567 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
568 video_content->protocol());
569 }
570 }
571
572 // Set the internal fake description factories to do DTLS-SRTP.
573 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000574 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000576 rtc::ToString(rtc::CreateRandomId());
577 identity_.reset(rtc::SSLIdentity::Generate(identity_name));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000578 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000579 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
580 }
581
582 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
583 bool expected) {
584 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
585 ASSERT_TRUE(audio != NULL);
586 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000587 const TransportInfo* video = sdp->GetTransportInfoByName("video");
588 ASSERT_TRUE(video != NULL);
589 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000590 }
591
592 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000593 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000595 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000596 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000597 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000598 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000599 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000600 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
601 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000602 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603 // Answer should be NULL as no crypto params in offer.
604 ASSERT_TRUE(answer == NULL);
605 }
606
607 void VerifyAnswerFromCryptoOffer() {
608 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000609 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610 options.bundle_enabled = true;
611 scoped_ptr<JsepSessionDescription> offer(
612 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
613 ASSERT_TRUE(offer.get() != NULL);
614 VerifyCryptoParams(offer->description());
615 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000616 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000617 ASSERT_TRUE(answer.get() != NULL);
618 VerifyCryptoParams(answer->description());
619 }
620
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000621 void SetAndVerifyNumUnsignalledRecvStreams(
622 int value_set, int value_expected) {
623 constraints_.reset(new FakeConstraints());
624 constraints_->AddOptional(
625 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
626 value_set);
627 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000628 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000629 mediastream_signaling_.SendAudioVideoStream1();
630 SessionDescriptionInterface* offer = CreateOffer();
631
632 SetLocalDescriptionWithoutError(offer);
633
634 video_channel_ = media_engine_->GetVideoChannel(0);
635
636 ASSERT_TRUE(video_channel_ != NULL);
637 cricket::VideoOptions video_options;
638 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
639 EXPECT_EQ(value_expected,
640 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
641 }
642
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000643 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
644 const cricket::SessionDescription* desc2,
645 bool expect_equal) {
646 if (desc1->contents().size() != desc2->contents().size()) {
647 EXPECT_FALSE(expect_equal);
648 return;
649 }
650
651 const cricket::ContentInfos& contents = desc1->contents();
652 cricket::ContentInfos::const_iterator it = contents.begin();
653
654 for (; it != contents.end(); ++it) {
655 const cricket::TransportDescription* transport_desc1 =
656 desc1->GetTransportDescriptionByName(it->name);
657 const cricket::TransportDescription* transport_desc2 =
658 desc2->GetTransportDescriptionByName(it->name);
659 if (!transport_desc1 || !transport_desc2) {
660 EXPECT_FALSE(expect_equal);
661 return;
662 }
663 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
664 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
665 EXPECT_FALSE(expect_equal);
666 return;
667 }
668 }
669 EXPECT_TRUE(expect_equal);
670 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000671
672 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
673 std::string *sdp) {
674 const cricket::SessionDescription* desc = current_desc->description();
675 EXPECT_TRUE(current_desc->ToString(sdp));
676
677 const cricket::ContentInfos& contents = desc->contents();
678 cricket::ContentInfos::const_iterator it = contents.begin();
679 // Replace ufrag and pwd lines with empty strings.
680 for (; it != contents.end(); ++it) {
681 const cricket::TransportDescription* transport_desc =
682 desc->GetTransportDescriptionByName(it->name);
683 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
684 + "\r\n";
685 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
686 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000687 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000688 "", 0,
689 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000690 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000691 "", 0,
692 sdp);
693 }
694 }
695
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000696 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
697 const std::string& modified_ice_ufrag,
698 const std::string& modified_ice_pwd,
699 std::string* sdp) {
700 const cricket::SessionDescription* desc = current_desc->description();
701 EXPECT_TRUE(current_desc->ToString(sdp));
702
703 const cricket::ContentInfos& contents = desc->contents();
704 cricket::ContentInfos::const_iterator it = contents.begin();
705 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
706 // |modified_ice_pwd| strings.
707 for (; it != contents.end(); ++it) {
708 const cricket::TransportDescription* transport_desc =
709 desc->GetTransportDescriptionByName(it->name);
710 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
711 + "\r\n";
712 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
713 + "\r\n";
714 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
715 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000716 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000717 mod_ufrag.c_str(), mod_ufrag.length(),
718 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000719 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000720 mod_pwd.c_str(), mod_pwd.length(),
721 sdp);
722 }
723 }
724
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 // Creates a remote offer and and applies it as a remote description,
726 // creates a local answer and applies is as a local description.
727 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
728 // to decide which local and remote streams to create.
729 void CreateAndSetRemoteOfferAndLocalAnswer() {
730 SessionDescriptionInterface* offer = CreateRemoteOffer();
731 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000732 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733 SetLocalDescriptionWithoutError(answer);
734 }
735 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
736 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
737 }
738 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
739 BaseSession::State expected_state) {
740 SetLocalDescriptionWithoutError(desc);
741 EXPECT_EQ(expected_state, session_->state());
742 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000743 void SetLocalDescriptionExpectError(const std::string& action,
744 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 SessionDescriptionInterface* desc) {
746 std::string error;
747 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000748 std::string sdp_type = "local ";
749 sdp_type.append(action);
750 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000751 EXPECT_NE(std::string::npos, error.find(expected_error));
752 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000753 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
754 SessionDescriptionInterface* desc) {
755 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
756 expected_error, desc);
757 }
758 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
759 SessionDescriptionInterface* desc) {
760 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
761 expected_error, desc);
762 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
764 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
765 }
766 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
767 BaseSession::State expected_state) {
768 SetRemoteDescriptionWithoutError(desc);
769 EXPECT_EQ(expected_state, session_->state());
770 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000771 void SetRemoteDescriptionExpectError(const std::string& action,
772 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773 SessionDescriptionInterface* desc) {
774 std::string error;
775 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000776 std::string sdp_type = "remote ";
777 sdp_type.append(action);
778 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779 EXPECT_NE(std::string::npos, error.find(expected_error));
780 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000781 void SetRemoteDescriptionOfferExpectError(
782 const std::string& expected_error, SessionDescriptionInterface* desc) {
783 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
784 expected_error, desc);
785 }
786 void SetRemoteDescriptionPranswerExpectError(
787 const std::string& expected_error, SessionDescriptionInterface* desc) {
788 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
789 expected_error, desc);
790 }
791 void SetRemoteDescriptionAnswerExpectError(
792 const std::string& expected_error, SessionDescriptionInterface* desc) {
793 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
794 expected_error, desc);
795 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796
797 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
798 SessionDescriptionInterface** nocrypto_answer) {
799 // Create a SDP without Crypto.
800 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000801 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 options.bundle_enabled = true;
803 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
804 ASSERT_TRUE(*offer != NULL);
805 VerifyCryptoParams((*offer)->description());
806
807 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
808 cricket::SEC_DISABLED);
809 EXPECT_TRUE(*nocrypto_answer != NULL);
810 }
811
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000812 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
813 SessionDescriptionInterface** nodtls_answer) {
814 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000815 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000816 options.bundle_enabled = true;
817
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000818 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000819 CreateRemoteOffer(options, cricket::SEC_ENABLED));
820
821 *nodtls_answer =
822 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
823 EXPECT_TRUE(*nodtls_answer != NULL);
824 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
825 VerifyCryptoParams((*nodtls_answer)->description());
826
827 SetFactoryDtlsSrtp();
828 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
829 ASSERT_TRUE(*offer != NULL);
830 VerifyFingerprintStatus((*offer)->description(), true);
831 VerifyCryptoParams((*offer)->description());
832 }
833
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 JsepSessionDescription* CreateRemoteOfferWithVersion(
835 cricket::MediaSessionOptions options,
836 cricket::SecurePolicy secure_policy,
837 const std::string& session_version,
838 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000839 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 const cricket::SessionDescription* cricket_desc = NULL;
841 if (current_desc) {
842 cricket_desc = current_desc->description();
843 session_id = current_desc->session_id();
844 }
845
846 desc_factory_->set_secure(secure_policy);
847 JsepSessionDescription* offer(
848 new JsepSessionDescription(JsepSessionDescription::kOffer));
849 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
850 session_id, session_version)) {
851 delete offer;
852 offer = NULL;
853 }
854 return offer;
855 }
856 JsepSessionDescription* CreateRemoteOffer(
857 cricket::MediaSessionOptions options) {
858 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
859 kSessionVersion, NULL);
860 }
861 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000862 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
863 return CreateRemoteOfferWithVersion(
864 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 }
866 JsepSessionDescription* CreateRemoteOffer(
867 cricket::MediaSessionOptions options,
868 const SessionDescriptionInterface* current_desc) {
869 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
870 kSessionVersion, current_desc);
871 }
872
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000873 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
874 const char* sctp_stream_name, int new_port,
875 cricket::MediaSessionOptions options) {
876 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000877 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
878 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000879 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
880 }
881
882 // Takes ownership of offer_basis (and deletes it).
883 JsepSessionDescription* ChangeSDPSctpPort(
884 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
885 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
886 // SessionDescription from the mutated string.
887 const char* default_port_str = "5000";
888 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000889 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000890 std::string offer_str;
891 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000892 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000893 new_port_str, strlen(new_port_str),
894 &offer_str);
895 JsepSessionDescription* offer = new JsepSessionDescription(
896 offer_basis->type());
897 delete offer_basis;
898 offer->Initialize(offer_str, NULL);
899 return offer;
900 }
901
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
903 // before this function to decide which streams to create.
904 JsepSessionDescription* CreateRemoteOffer() {
905 cricket::MediaSessionOptions options;
906 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
907 return CreateRemoteOffer(options, session_->remote_description());
908 }
909
910 JsepSessionDescription* CreateRemoteAnswer(
911 const SessionDescriptionInterface* offer,
912 cricket::MediaSessionOptions options,
913 cricket::SecurePolicy policy) {
914 desc_factory_->set_secure(policy);
915 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000916 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 JsepSessionDescription* answer(
918 new JsepSessionDescription(JsepSessionDescription::kAnswer));
919 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
920 options, NULL),
921 session_id, kSessionVersion)) {
922 delete answer;
923 answer = NULL;
924 }
925 return answer;
926 }
927
928 JsepSessionDescription* CreateRemoteAnswer(
929 const SessionDescriptionInterface* offer,
930 cricket::MediaSessionOptions options) {
931 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
932 }
933
934 // Creates an answer session description with streams based on
935 // |mediastream_signaling_|. Call
936 // mediastream_signaling_.UseOptionsWithStreamX() before this function
937 // to decide which streams to create.
938 JsepSessionDescription* CreateRemoteAnswer(
939 const SessionDescriptionInterface* offer) {
940 cricket::MediaSessionOptions options;
941 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
942 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
943 }
944
945 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000946 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000947 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000949
950 PeerConnectionInterface::RTCOfferAnswerOptions options;
951 options.use_rtp_mux = bundle;
952
953 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
955 // and answer.
956 SetLocalDescriptionWithoutError(offer);
957
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000958 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000959 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960 std::string sdp;
961 EXPECT_TRUE(answer->ToString(&sdp));
962
963 size_t expected_candidate_num = 2;
964 if (!rtcp_mux) {
965 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
966 // for rtp and rtcp.
967 expected_candidate_num = 4;
968 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 const std::string kRtcpMux = "a=rtcp-mux";
970 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000971 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 kXRtcpMux.c_str(), kXRtcpMux.length(),
973 &sdp);
974 }
975
976 SessionDescriptionInterface* new_answer = CreateSessionDescription(
977 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978
979 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000980 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
982 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
983 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
984 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
985 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
986 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
987 if (bundle) {
988 EXPECT_TRUE(c0.IsEquivalent(c1));
989 } else {
990 EXPECT_FALSE(c0.IsEquivalent(c1));
991 }
992 }
993 }
994 // Tests that we can only send DTMF when the dtmf codec is supported.
995 void TestCanInsertDtmf(bool can) {
996 if (can) {
997 InitWithDtmfCodec();
998 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000999 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000 }
1001 mediastream_signaling_.SendAudioVideoStream1();
1002 CreateAndSetRemoteOfferAndLocalAnswer();
1003 EXPECT_FALSE(session_->CanInsertDtmf(""));
1004 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1005 }
1006
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001007 // Helper class to configure loopback network and verify Best
1008 // Connection using right IP protocol for TestLoopbackCall
1009 // method. LoopbackNetworkManager applies firewall rules to block
1010 // all ping traffic once ICE completed, and remove them to observe
1011 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1012 // verifies the best connection is using the right IP protocol after
1013 // initial ICE convergences.
1014
1015 class LoopbackNetworkConfiguration {
1016 public:
1017 LoopbackNetworkConfiguration()
1018 : test_ipv6_network_(false),
1019 test_extra_ipv4_network_(false),
1020 best_connection_after_initial_ice_converged_(1, 0) {}
1021
1022 // Used to track the expected best connection count in each IP protocol.
1023 struct ExpectedBestConnection {
1024 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1025 : ipv4_count_(ipv4_count),
1026 ipv6_count_(ipv6_count) {}
1027
1028 int ipv4_count_;
1029 int ipv6_count_;
1030 };
1031
1032 bool test_ipv6_network_;
1033 bool test_extra_ipv4_network_;
1034 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1035
1036 void VerifyBestConnectionAfterIceConverge(
1037 const FakeMetricsObserver& metrics_observer) const {
1038 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1039 }
1040
1041 private:
1042 void Verify(const FakeMetricsObserver& metrics_observer,
1043 const ExpectedBestConnection& expected) const {
1044 EXPECT_EQ(
1045 metrics_observer
1046 .peer_connection_metrics_counters_[webrtc::kBestConnections_IPv4],
1047 expected.ipv4_count_);
1048 EXPECT_EQ(
1049 metrics_observer
1050 .peer_connection_metrics_counters_[webrtc::kBestConnections_IPv6],
1051 expected.ipv6_count_);
1052 }
1053 };
1054
1055 class LoopbackNetworkManager {
1056 public:
1057 LoopbackNetworkManager(WebRtcSessionTest* session,
1058 const LoopbackNetworkConfiguration& config)
1059 : config_(config) {
1060 session->AddInterface(
1061 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1062 if (config_.test_extra_ipv4_network_) {
1063 session->AddInterface(
1064 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1065 }
1066 if (config_.test_ipv6_network_) {
1067 session->AddInterface(
1068 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1069 }
1070 }
1071
1072 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1073 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1074 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1075 if (config_.test_extra_ipv4_network_) {
1076 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1077 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1078 }
1079 if (config_.test_ipv6_network_) {
1080 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1081 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1082 }
1083 }
1084
1085 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1086
1087 private:
1088 LoopbackNetworkConfiguration config_;
1089 };
1090
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001091 // The method sets up a call from the session to itself, in a loopback
1092 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001093 // disconnection, and then a permanent disconnection.
1094 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001095 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1096 // While running the call, this method also checks if the session goes through
1097 // the correct sequence of ICE states when a connection is established,
1098 // broken, and re-established.
1099 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001100 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1101 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001103
1104 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1105 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001106 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001107 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001108 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001109
1110 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1111 observer_.ice_gathering_state_);
1112 SetLocalDescriptionWithoutError(offer);
1113 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1114 observer_.ice_connection_state_);
1115 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1116 observer_.ice_gathering_state_,
1117 kIceCandidatesTimeout);
1118 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1119 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1120 observer_.ice_gathering_state_,
1121 kIceCandidatesTimeout);
1122
1123 std::string sdp;
1124 offer->ToString(&sdp);
1125 SessionDescriptionInterface* desc =
1126 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
1127 ASSERT_TRUE(desc != NULL);
1128 SetRemoteDescriptionWithoutError(desc);
1129
1130 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1131 observer_.ice_connection_state_,
1132 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001133
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001134 // The ice connection state is "Connected" too briefly to catch in a test.
1135 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136 observer_.ice_connection_state_,
1137 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001138
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001139 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001140 // Adding firewall rule to block ping requests, which should cause
1141 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001142
1143 loopback_network_manager.ApplyFirewallRules(fss_.get());
1144
1145 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001146 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1147 observer_.ice_connection_state_,
1148 kIceCandidatesTimeout);
1149
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001150 metrics_observer_.Reset();
1151
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001152 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001153 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001154 // Session is automatically calling OnSignalingReady after creation of
1155 // new portallocator session which will allocate new set of candidates.
1156
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001157 LOG(LS_INFO) << "Firewall Rules cleared";
1158
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001159 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001160 observer_.ice_connection_state_,
1161 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001162
1163 // Now we block ping requests and wait until the ICE connection transitions
1164 // to the Failed state. This will take at least 30 seconds because it must
1165 // wait for the Port to timeout.
1166 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001167
1168 loopback_network_manager.ApplyFirewallRules(fss_.get());
1169 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001170 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001171 observer_.ice_connection_state_,
1172 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001173 }
1174
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001175 void TestLoopbackCall() {
1176 LoopbackNetworkConfiguration config;
1177 TestLoopbackCall(config);
1178 }
1179
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001180 void VerifyTransportType(const std::string& content_name,
1181 cricket::TransportProtocol protocol) {
1182 const cricket::Transport* transport = session_->GetTransport(content_name);
1183 ASSERT_TRUE(transport != NULL);
1184 EXPECT_EQ(protocol, transport->protocol());
1185 }
1186
1187 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1188 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001189 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1190 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1191
1192 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001193 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1194 codecs.push_back(kCNCodec1);
1195 codecs.push_back(kCNCodec2);
1196 media_engine_->SetAudioCodecs(codecs);
1197 desc_factory_->set_audio_codecs(codecs);
1198 }
1199
1200 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1201 const cricket::ContentDescription* description = content->description;
1202 ASSERT(description != NULL);
1203 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001204 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001205 ASSERT(audio_content_desc != NULL);
1206 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1207 if (audio_content_desc->codecs()[i].name == "CN")
1208 return false;
1209 }
1210 return true;
1211 }
1212
1213 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001214 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001215 dci.reliable = false;
1216 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001217 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001218 SetLocalDescriptionWithoutError(offer);
1219 }
1220
wu@webrtc.org91053e72013-08-10 07:18:04 +00001221 void VerifyMultipleAsyncCreateDescription(
1222 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001223 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001224 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001225 if (type == CreateSessionDescriptionRequest::kAnswer) {
1226 cricket::MediaSessionOptions options;
1227 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001228 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001229 ASSERT_TRUE(offer.get() != NULL);
1230 SetRemoteDescriptionWithoutError(offer.release());
1231 }
1232
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001233 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001234 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001235 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001236 observers[kNumber];
1237 for (int i = 0; i < kNumber; ++i) {
1238 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1239 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001240 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001241 } else {
1242 session_->CreateAnswer(observers[i], NULL);
1243 }
1244 }
1245
1246 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1247 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1248 WebRtcSessionCreateSDPObserverForTest::kFailed;
1249
1250 for (int i = 0; i < kNumber; ++i) {
1251 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1252 if (success) {
1253 EXPECT_TRUE(observers[i]->description() != NULL);
1254 } else {
1255 EXPECT_TRUE(observers[i]->description() == NULL);
1256 }
1257 }
1258 }
1259
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001260 void ConfigureAllocatorWithTurn() {
1261 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1262 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1263 relay_server.credentials = credentials;
1264 relay_server.ports.push_back(cricket::ProtocolAddress(
1265 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1266 allocator_->AddRelay(relay_server);
1267 allocator_->set_step_delay(cricket::kMinimumStepDelay);
1268 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
jiayl@webrtc.orgdacdd942015-01-23 17:33:34 +00001269 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001270 }
1271
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272 cricket::FakeMediaEngine* media_engine_;
1273 cricket::FakeDataEngine* data_engine_;
1274 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001275 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1276 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1277 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1278 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1279 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1280 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1281 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1282 rtc::SocketServerScope ss_scope_;
1283 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001284 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001285 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001286 rtc::FakeNetworkManager network_manager_;
1287 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001288 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001289 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001291 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292 MockIceObserver observer_;
1293 cricket::FakeVideoMediaChannel* video_channel_;
1294 cricket::FakeVoiceMediaChannel* voice_channel_;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001295 FakeMetricsObserver metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296};
1297
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001298TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1299 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001300 // SDES is disabled when DTLS is on.
1301 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302}
1303
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001304TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001305 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001306 // SDES is required if DTLS is off.
1307 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001308}
1309
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1311 TestSessionCandidatesWithBundleRtcpMux(false, false);
1312}
1313
1314// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1315// with rtcp-mux and/or bundle.
1316TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1317 TestSessionCandidatesWithBundleRtcpMux(false, true);
1318}
1319
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1321 TestSessionCandidatesWithBundleRtcpMux(true, true);
1322}
1323
1324TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001325 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1326 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001327 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001328 mediastream_signaling_.SendAudioVideoStream1();
1329 InitiateCall();
1330 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1331 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1332 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1333}
1334
1335TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001336 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1337 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001338 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001339 rtc::FP_UDP,
1340 rtc::FD_ANY,
1341 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001342 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 mediastream_signaling_.SendAudioVideoStream1();
1344 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001345 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001346 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1347 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1348 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1349}
1350
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001351// Test session delivers no candidates gathered when constraint set to "none".
1352TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1353 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001354 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001355 mediastream_signaling_.SendAudioVideoStream1();
1356 InitiateCall();
1357 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1358 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1359 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1360}
1361
1362// Test session delivers only relay candidates gathered when constaint set to
1363// "relay".
1364TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1365 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1366 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001367 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001368 mediastream_signaling_.SendAudioVideoStream1();
1369 InitiateCall();
1370 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1371 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1372 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1373 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1374 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1375 observer_.mline_0_candidates_[i].type());
1376 }
1377 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1378 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1379 observer_.mline_1_candidates_[i].type());
1380 }
1381}
1382
1383// Test session delivers all candidates gathered when constaint set to "all".
1384TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1385 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001386 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001387 mediastream_signaling_.SendAudioVideoStream1();
1388 InitiateCall();
1389 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1390 // Host + STUN. By default allocator is disabled to gather relay candidates.
1391 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1392 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1393}
1394
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001395TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001396 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001397 SessionDescriptionInterface* offer = NULL;
1398 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1399 std::string unknown_action;
1400 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1401 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1402}
1403
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001404// Test creating offers and receive answers and make sure the
1405// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001406TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001407 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001409 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001410 const std::string session_id_orig = offer->session_id();
1411 const std::string session_version_orig = offer->session_version();
1412 SetLocalDescriptionWithoutError(offer);
1413
1414 mediastream_signaling_.SendAudioVideoStream2();
1415 SessionDescriptionInterface* answer =
1416 CreateRemoteAnswer(session_->local_description());
1417 SetRemoteDescriptionWithoutError(answer);
1418
1419 video_channel_ = media_engine_->GetVideoChannel(0);
1420 voice_channel_ = media_engine_->GetVoiceChannel(0);
1421
1422 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1423 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1424
1425 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1426 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1427
1428 ASSERT_EQ(1u, video_channel_->send_streams().size());
1429 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1430 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1431 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1432
1433 // Create new offer without send streams.
1434 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001435 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001436
1437 // Verify the session id is the same and the session version is
1438 // increased.
1439 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001440 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1441 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001442
1443 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001444 EXPECT_EQ(0u, video_channel_->send_streams().size());
1445 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446
1447 mediastream_signaling_.SendAudioVideoStream2();
1448 answer = CreateRemoteAnswer(session_->local_description());
1449 SetRemoteDescriptionWithoutError(answer);
1450
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 // Make sure the receive streams have not changed.
1452 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1453 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1454 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1455 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1456}
1457
1458// Test receiving offers and creating answers and make sure the
1459// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001460TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001461 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001463 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001464 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 SetRemoteDescriptionWithoutError(offer);
1466
1467 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001468 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001469 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001470 SetLocalDescriptionWithoutError(answer);
1471
1472 const std::string session_id_orig = answer->session_id();
1473 const std::string session_version_orig = answer->session_version();
1474
1475 video_channel_ = media_engine_->GetVideoChannel(0);
1476 voice_channel_ = media_engine_->GetVoiceChannel(0);
1477
1478 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1479 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1480
1481 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1482 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1483
1484 ASSERT_EQ(1u, video_channel_->send_streams().size());
1485 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1486 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1487 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1488
1489 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001490 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491 SetRemoteDescriptionWithoutError(offer);
1492
1493 // Answer by turning off all send streams.
1494 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001495 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001496
1497 // Verify the session id is the same and the session version is
1498 // increased.
1499 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001500 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1501 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001502 SetLocalDescriptionWithoutError(answer);
1503
1504 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1505 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1506 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1507 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1508 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1509 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1510
1511 // Make sure we have no send streams.
1512 EXPECT_EQ(0u, video_channel_->send_streams().size());
1513 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1514}
1515
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001516TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001517 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001518 media_engine_->set_fail_create_channel(true);
1519
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001520 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001521 ASSERT_TRUE(offer != NULL);
1522 // SetRemoteDescription and SetLocalDescription will take the ownership of
1523 // the offer.
1524 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001525 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001526 ASSERT_TRUE(offer != NULL);
1527 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1528}
1529
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001530//
1531// Tests for creating/setting SDP under different SDES/DTLS polices:
1532//
1533// --DTLS off and SDES on
1534// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1535// set local/remote offer/answer with crypto --> success
1536// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1537// failure
1538// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1539// failure
1540// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1541// failure
1542//
1543// --DTLS on and SDES off
1544// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1545// set local/remote offer/answer with DTLS fingerprint --> success
1546// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1547// fingerprint --> failure
1548// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1549// --> failure
1550// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1551// --> failure
1552//
1553// --Encryption disabled: DTLS off and SDES off
1554// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1555// answer without SDES or DTLS --> success
1556// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1557// answer without SDES or DTLS --> success
1558//
1559
1560// Test that we return a failure when applying a remote/local offer that doesn't
1561// have cryptos enabled when DTLS is off.
1562TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001563 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001565 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566 JsepSessionDescription* offer = CreateRemoteOffer(
1567 options, cricket::SEC_DISABLED);
1568 ASSERT_TRUE(offer != NULL);
1569 VerifyNoCryptoParams(offer->description(), false);
1570 // SetRemoteDescription and SetLocalDescription will take the ownership of
1571 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001572 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1574 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001575 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576}
1577
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001578// Test that we return a failure when applying a local answer that doesn't have
1579// cryptos enabled when DTLS is off.
1580TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001581 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 SessionDescriptionInterface* offer = NULL;
1583 SessionDescriptionInterface* answer = NULL;
1584 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1585 // SetRemoteDescription and SetLocalDescription will take the ownership of
1586 // the offer.
1587 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001588 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589}
1590
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001591// Test we will return fail when apply an remote answer that doesn't have
1592// crypto enabled when DTLS is off.
1593TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001594 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 SessionDescriptionInterface* offer = NULL;
1596 SessionDescriptionInterface* answer = NULL;
1597 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1598 // SetRemoteDescription and SetLocalDescription will take the ownership of
1599 // the offer.
1600 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001601 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602}
1603
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001604// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1605// and that we return an answer with a DTLS fingerprint.
1606TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001607 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001609 InitWithDtls();
1610 SetFactoryDtlsSrtp();
1611 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001612 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001613 JsepSessionDescription* offer =
1614 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 ASSERT_TRUE(offer != NULL);
1616 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001617 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618
1619 // SetRemoteDescription will take the ownership of the offer.
1620 SetRemoteDescriptionWithoutError(offer);
1621
1622 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001623 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 ASSERT_TRUE(answer != NULL);
1625 VerifyFingerprintStatus(answer->description(), true);
1626 // Check that we don't have an a=crypto line in the answer.
1627 VerifyNoCryptoParams(answer->description(), true);
1628
1629 // Now set the local description, which should work, even without a=crypto.
1630 SetLocalDescriptionWithoutError(answer);
1631}
1632
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001633// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1634// and then we accept a remote answer with a DTLS fingerprint successfully.
1635TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001636 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001637 mediastream_signaling_.SendAudioVideoStream1();
1638 InitWithDtls();
1639 SetFactoryDtlsSrtp();
1640
1641 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001642 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001643 ASSERT_TRUE(offer != NULL);
1644 VerifyFingerprintStatus(offer->description(), true);
1645 // Check that we don't have an a=crypto line in the offer.
1646 VerifyNoCryptoParams(offer->description(), true);
1647
1648 // Now set the local description, which should work, even without a=crypto.
1649 SetLocalDescriptionWithoutError(offer);
1650
1651 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001652 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001653 JsepSessionDescription* answer =
1654 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1655 ASSERT_TRUE(answer != NULL);
1656 VerifyFingerprintStatus(answer->description(), true);
1657 VerifyNoCryptoParams(answer->description(), true);
1658
1659 // SetRemoteDescription will take the ownership of the answer.
1660 SetRemoteDescriptionWithoutError(answer);
1661}
1662
1663// Test that if we support DTLS and the other side didn't offer a fingerprint,
1664// we will fail to set the remote description.
1665TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001666 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 InitWithDtls();
1668 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001669 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001670 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001671 JsepSessionDescription* offer = CreateRemoteOffer(
1672 options, cricket::SEC_REQUIRED);
1673 ASSERT_TRUE(offer != NULL);
1674 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001675 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001677 // SetRemoteDescription will take the ownership of the offer.
1678 SetRemoteDescriptionOfferExpectError(
1679 kSdpWithoutDtlsFingerprint, offer);
1680
1681 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1682 // SetLocalDescription will take the ownership of the offer.
1683 SetLocalDescriptionOfferExpectError(
1684 kSdpWithoutDtlsFingerprint, offer);
1685}
1686
1687// Test that we return a failure when applying a local answer that doesn't have
1688// a DTLS fingerprint when DTLS is required.
1689TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001690 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001691 InitWithDtls();
1692 SessionDescriptionInterface* offer = NULL;
1693 SessionDescriptionInterface* answer = NULL;
1694 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1695
1696 // SetRemoteDescription and SetLocalDescription will take the ownership of
1697 // the offer and answer.
1698 SetRemoteDescriptionWithoutError(offer);
1699 SetLocalDescriptionAnswerExpectError(
1700 kSdpWithoutDtlsFingerprint, answer);
1701}
1702
1703// Test that we return a failure when applying a remote answer that doesn't have
1704// a DTLS fingerprint when DTLS is required.
1705TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001706 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001707 InitWithDtls();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001708 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001709 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001710 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001711 JsepSessionDescription* answer =
1712 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1713
1714 // SetRemoteDescription and SetLocalDescription will take the ownership of
1715 // the offer and answer.
1716 SetLocalDescriptionWithoutError(offer);
1717 SetRemoteDescriptionAnswerExpectError(
1718 kSdpWithoutDtlsFingerprint, answer);
1719}
1720
1721// Test that we create a local offer without SDES or DTLS and accept a remote
1722// answer without SDES or DTLS when encryption is disabled.
1723TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1724 mediastream_signaling_.SendAudioVideoStream1();
1725 options_.disable_encryption = true;
1726 InitWithDtls();
1727
1728 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001729 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001730 ASSERT_TRUE(offer != NULL);
1731 VerifyFingerprintStatus(offer->description(), false);
1732 // Check that we don't have an a=crypto line in the offer.
1733 VerifyNoCryptoParams(offer->description(), false);
1734
1735 // Now set the local description, which should work, even without a=crypto.
1736 SetLocalDescriptionWithoutError(offer);
1737
1738 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001739 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001740 JsepSessionDescription* answer =
1741 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1742 ASSERT_TRUE(answer != NULL);
1743 VerifyFingerprintStatus(answer->description(), false);
1744 VerifyNoCryptoParams(answer->description(), false);
1745
1746 // SetRemoteDescription will take the ownership of the answer.
1747 SetRemoteDescriptionWithoutError(answer);
1748}
1749
1750// Test that we create a local answer without SDES or DTLS and accept a remote
1751// offer without SDES or DTLS when encryption is disabled.
1752TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1753 options_.disable_encryption = true;
1754 InitWithDtls();
1755
1756 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001757 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001758 JsepSessionDescription* offer =
1759 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1760 ASSERT_TRUE(offer != NULL);
1761 VerifyFingerprintStatus(offer->description(), false);
1762 VerifyNoCryptoParams(offer->description(), false);
1763
1764 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 SetRemoteDescriptionWithoutError(offer);
1766
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001767 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001768 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769 ASSERT_TRUE(answer != NULL);
1770 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001771 // Check that we don't have an a=crypto line in the answer.
1772 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001774 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 SetLocalDescriptionWithoutError(answer);
1776}
1777
1778TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001779 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780 mediastream_signaling_.SendNothing();
1781 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001782 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783 SetLocalDescriptionWithoutError(offer);
1784
1785 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001786 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 SetLocalDescriptionWithoutError(offer2);
1788}
1789
1790TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001791 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 mediastream_signaling_.SendNothing();
1793 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001794 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 SetRemoteDescriptionWithoutError(offer);
1796
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001797 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 SetRemoteDescriptionWithoutError(offer2);
1799}
1800
1801TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001802 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001804 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001806 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001807 SetRemoteDescriptionOfferExpectError(
1808 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809}
1810
1811TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001812 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001814 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001816 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001817 SetLocalDescriptionOfferExpectError(
1818 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001819}
1820
1821TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001822 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 mediastream_signaling_.SendNothing();
1824 SessionDescriptionInterface* offer = CreateRemoteOffer();
1825 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1826
1827 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001828 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1830 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1831
1832 mediastream_signaling_.SendAudioVideoStream1();
1833 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001834 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1836
1837 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1838
1839 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001840 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001841 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1842}
1843
1844TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001845 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001847 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1849
1850 JsepSessionDescription* pranswer =
1851 CreateRemoteAnswer(session_->local_description());
1852 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1853
1854 SetRemoteDescriptionExpectState(pranswer,
1855 BaseSession::STATE_RECEIVEDPRACCEPT);
1856
1857 mediastream_signaling_.SendAudioVideoStream1();
1858 JsepSessionDescription* pranswer2 =
1859 CreateRemoteAnswer(session_->local_description());
1860 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1861
1862 SetRemoteDescriptionExpectState(pranswer2,
1863 BaseSession::STATE_RECEIVEDPRACCEPT);
1864
1865 mediastream_signaling_.SendAudioVideoStream2();
1866 SessionDescriptionInterface* answer =
1867 CreateRemoteAnswer(session_->local_description());
1868 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1869}
1870
1871TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001872 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001873 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001874 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1875
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876 SessionDescriptionInterface* answer =
1877 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001878 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1879 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001880}
1881
1882TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001883 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001885 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1886
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887 SessionDescriptionInterface* answer =
1888 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001889 SetRemoteDescriptionAnswerExpectError(
1890 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001891}
1892
1893TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001894 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001895 mediastream_signaling_.SendAudioVideoStream1();
1896
1897 cricket::Candidate candidate;
1898 candidate.set_component(1);
1899 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1900
1901 // Fail since we have not set a offer description.
1902 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1903
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001904 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001905 SetLocalDescriptionWithoutError(offer);
1906 // Candidate should be allowed to add before remote description.
1907 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1908 candidate.set_component(2);
1909 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1910 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1911
1912 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1913 session_->local_description());
1914 SetRemoteDescriptionWithoutError(answer);
1915
1916 // Verifying the candidates are copied properly from internal vector.
1917 const SessionDescriptionInterface* remote_desc =
1918 session_->remote_description();
1919 ASSERT_TRUE(remote_desc != NULL);
1920 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1921 const IceCandidateCollection* candidates =
1922 remote_desc->candidates(kMediaContentIndex0);
1923 ASSERT_EQ(2u, candidates->count());
1924 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1925 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1926 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1927 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1928
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001929 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1930 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001931 candidate.set_component(2);
1932 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1933 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001934 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001935
1936 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1937 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1938}
1939
1940// Test that a remote candidate is added to the remote session description and
1941// that it is retained if the remote session description is changed.
1942TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001943 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001944 cricket::Candidate candidate1;
1945 candidate1.set_component(1);
1946 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1947 candidate1);
1948 mediastream_signaling_.SendAudioVideoStream1();
1949 CreateAndSetRemoteOfferAndLocalAnswer();
1950
1951 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1952 const SessionDescriptionInterface* remote_desc =
1953 session_->remote_description();
1954 ASSERT_TRUE(remote_desc != NULL);
1955 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1956 const IceCandidateCollection* candidates =
1957 remote_desc->candidates(kMediaContentIndex0);
1958 ASSERT_EQ(1u, candidates->count());
1959 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1960
1961 // Update the RemoteSessionDescription with a new session description and
1962 // a candidate and check that the new remote session description contains both
1963 // candidates.
1964 SessionDescriptionInterface* offer = CreateRemoteOffer();
1965 cricket::Candidate candidate2;
1966 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1967 candidate2);
1968 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1969 SetRemoteDescriptionWithoutError(offer);
1970
1971 remote_desc = session_->remote_description();
1972 ASSERT_TRUE(remote_desc != NULL);
1973 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1974 candidates = remote_desc->candidates(kMediaContentIndex0);
1975 ASSERT_EQ(2u, candidates->count());
1976 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1977 // Username and password have be updated with the TransportInfo of the
1978 // SessionDescription, won't be equal to the original one.
1979 candidate2.set_username(candidates->at(0)->candidate().username());
1980 candidate2.set_password(candidates->at(0)->candidate().password());
1981 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1982 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1983 // No need to verify the username and password.
1984 candidate1.set_username(candidates->at(1)->candidate().username());
1985 candidate1.set_password(candidates->at(1)->candidate().password());
1986 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1987
1988 // Test that the candidate is ignored if we can add the same candidate again.
1989 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1990}
1991
1992// Test that local candidates are added to the local session description and
1993// that they are retained if the local session description is changed.
1994TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001995 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001996 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 mediastream_signaling_.SendAudioVideoStream1();
1998 CreateAndSetRemoteOfferAndLocalAnswer();
1999
2000 const SessionDescriptionInterface* local_desc = session_->local_description();
2001 const IceCandidateCollection* candidates =
2002 local_desc->candidates(kMediaContentIndex0);
2003 ASSERT_TRUE(candidates != NULL);
2004 EXPECT_EQ(0u, candidates->count());
2005
2006 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2007
2008 local_desc = session_->local_description();
2009 candidates = local_desc->candidates(kMediaContentIndex0);
2010 ASSERT_TRUE(candidates != NULL);
2011 EXPECT_LT(0u, candidates->count());
2012 candidates = local_desc->candidates(1);
2013 ASSERT_TRUE(candidates != NULL);
2014 EXPECT_LT(0u, candidates->count());
2015
2016 // Update the session descriptions.
2017 mediastream_signaling_.SendAudioVideoStream1();
2018 CreateAndSetRemoteOfferAndLocalAnswer();
2019
2020 local_desc = session_->local_description();
2021 candidates = local_desc->candidates(kMediaContentIndex0);
2022 ASSERT_TRUE(candidates != NULL);
2023 EXPECT_LT(0u, candidates->count());
2024 candidates = local_desc->candidates(1);
2025 ASSERT_TRUE(candidates != NULL);
2026 EXPECT_LT(0u, candidates->count());
2027}
2028
2029// Test that we can set a remote session description with remote candidates.
2030TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002031 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002032
2033 cricket::Candidate candidate1;
2034 candidate1.set_component(1);
2035 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2036 candidate1);
2037 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002038 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039
2040 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2041 SetRemoteDescriptionWithoutError(offer);
2042
2043 const SessionDescriptionInterface* remote_desc =
2044 session_->remote_description();
2045 ASSERT_TRUE(remote_desc != NULL);
2046 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2047 const IceCandidateCollection* candidates =
2048 remote_desc->candidates(kMediaContentIndex0);
2049 ASSERT_EQ(1u, candidates->count());
2050 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2051
wu@webrtc.org91053e72013-08-10 07:18:04 +00002052 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 SetLocalDescriptionWithoutError(answer);
2054}
2055
2056// Test that offers and answers contains ice candidates when Ice candidates have
2057// been gathered.
2058TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002059 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002060 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061 mediastream_signaling_.SendAudioVideoStream1();
2062 // Ice is started but candidates are not provided until SetLocalDescription
2063 // is called.
2064 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2065 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2066 CreateAndSetRemoteOfferAndLocalAnswer();
2067 // Wait until at least one local candidate has been collected.
2068 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2069 kIceCandidatesTimeout);
2070 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
2071 kIceCandidatesTimeout);
2072
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002073 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2074
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2076 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2077 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
2078 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
2079
2080 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2081 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002082 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2084 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2085 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
2086 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
2087 SetLocalDescriptionWithoutError(answer);
2088}
2089
2090// Verifies TransportProxy and media channels are created with content names
2091// present in the SessionDescription.
2092TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002093 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002095 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096
2097 // CreateOffer creates session description with the content names "audio" and
2098 // "video". Goal is to modify these content names and verify transport channel
2099 // proxy in the BaseSession, as proxies are created with the content names
2100 // present in SDP.
2101 std::string sdp;
2102 EXPECT_TRUE(offer->ToString(&sdp));
2103 const std::string kAudioMid = "a=mid:audio";
2104 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2105 const std::string kVideoMid = "a=mid:video";
2106 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2107
2108 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002109 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110 kAudioMidReplaceStr.c_str(),
2111 kAudioMidReplaceStr.length(),
2112 &sdp);
2113 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002114 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115 kVideoMidReplaceStr.c_str(),
2116 kVideoMidReplaceStr.length(),
2117 &sdp);
2118
2119 SessionDescriptionInterface* modified_offer =
2120 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2121
2122 SetRemoteDescriptionWithoutError(modified_offer);
2123
2124 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002125 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126 SetLocalDescriptionWithoutError(answer);
2127
2128 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
2129 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
2130 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2131 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2132}
2133
2134// Test that an offer contains the correct media content descriptions based on
2135// the send streams when no constraints have been set.
2136TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002137 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002138 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2139
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 ASSERT_TRUE(offer != NULL);
2141 const cricket::ContentInfo* content =
2142 cricket::GetFirstAudioContent(offer->description());
2143 EXPECT_TRUE(content != NULL);
2144 content = cricket::GetFirstVideoContent(offer->description());
2145 EXPECT_TRUE(content == NULL);
2146}
2147
2148// Test that an offer contains the correct media content descriptions based on
2149// the send streams when no constraints have been set.
2150TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002151 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 // Test Audio only offer.
2153 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002154 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2155
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156 const cricket::ContentInfo* content =
2157 cricket::GetFirstAudioContent(offer->description());
2158 EXPECT_TRUE(content != NULL);
2159 content = cricket::GetFirstVideoContent(offer->description());
2160 EXPECT_TRUE(content == NULL);
2161
2162 // Test Audio / Video offer.
2163 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002164 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165 content = cricket::GetFirstAudioContent(offer->description());
2166 EXPECT_TRUE(content != NULL);
2167 content = cricket::GetFirstVideoContent(offer->description());
2168 EXPECT_TRUE(content != NULL);
2169}
2170
2171// Test that an offer contains no media content descriptions if
2172// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2173TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002174 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002175 PeerConnectionInterface::RTCOfferAnswerOptions options;
2176 options.offer_to_receive_audio = 0;
2177 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002178
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002179 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002180 CreateOffer(options));
2181
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002182 ASSERT_TRUE(offer != NULL);
2183 const cricket::ContentInfo* content =
2184 cricket::GetFirstAudioContent(offer->description());
2185 EXPECT_TRUE(content == NULL);
2186 content = cricket::GetFirstVideoContent(offer->description());
2187 EXPECT_TRUE(content == NULL);
2188}
2189
2190// Test that an offer contains only audio media content descriptions if
2191// kOfferToReceiveAudio constraints are set to true.
2192TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002193 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002194 PeerConnectionInterface::RTCOfferAnswerOptions options;
2195 options.offer_to_receive_audio =
2196 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2197
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002198 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002199 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002200
2201 const cricket::ContentInfo* content =
2202 cricket::GetFirstAudioContent(offer->description());
2203 EXPECT_TRUE(content != NULL);
2204 content = cricket::GetFirstVideoContent(offer->description());
2205 EXPECT_TRUE(content == NULL);
2206}
2207
2208// Test that an offer contains audio and video media content descriptions if
2209// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2210TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002211 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002213 PeerConnectionInterface::RTCOfferAnswerOptions options;
2214 options.offer_to_receive_audio =
2215 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2216 options.offer_to_receive_video =
2217 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2218
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002219 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002220 CreateOffer(options));
2221
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002222 const cricket::ContentInfo* content =
2223 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002224 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002225
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226 content = cricket::GetFirstVideoContent(offer->description());
2227 EXPECT_TRUE(content != NULL);
2228
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002229 // Sets constraints to false and verifies that audio/video contents are
2230 // removed.
2231 options.offer_to_receive_audio = 0;
2232 options.offer_to_receive_video = 0;
2233 offer.reset(CreateOffer(options));
2234
2235 content = cricket::GetFirstAudioContent(offer->description());
2236 EXPECT_TRUE(content == NULL);
2237 content = cricket::GetFirstVideoContent(offer->description());
2238 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239}
2240
2241// Test that an answer can not be created if the last remote description is not
2242// an offer.
2243TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002244 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002245 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246 SetLocalDescriptionWithoutError(offer);
2247 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2248 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002249 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250}
2251
2252// Test that an answer contains the correct media content descriptions when no
2253// constraints have been set.
2254TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002255 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002257 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002258 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002259 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002260 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002261 const cricket::ContentInfo* content =
2262 cricket::GetFirstAudioContent(answer->description());
2263 ASSERT_TRUE(content != NULL);
2264 EXPECT_FALSE(content->rejected);
2265
2266 content = cricket::GetFirstVideoContent(answer->description());
2267 ASSERT_TRUE(content != NULL);
2268 EXPECT_FALSE(content->rejected);
2269}
2270
2271// Test that an answer contains the correct media content descriptions when no
2272// constraints have been set and the offer only contain audio.
2273TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002274 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275 // Create a remote offer with audio only.
2276 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002277
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002278 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002279 CreateRemoteOffer(options));
2280 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2281 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2282
2283 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002284 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002285 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286 const cricket::ContentInfo* content =
2287 cricket::GetFirstAudioContent(answer->description());
2288 ASSERT_TRUE(content != NULL);
2289 EXPECT_FALSE(content->rejected);
2290
2291 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2292}
2293
2294// Test that an answer contains the correct media content descriptions when no
2295// constraints have been set.
2296TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002297 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002299 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300 SetRemoteDescriptionWithoutError(offer.release());
2301 // Test with a stream with tracks.
2302 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002303 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002304 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 const cricket::ContentInfo* content =
2306 cricket::GetFirstAudioContent(answer->description());
2307 ASSERT_TRUE(content != NULL);
2308 EXPECT_FALSE(content->rejected);
2309
2310 content = cricket::GetFirstVideoContent(answer->description());
2311 ASSERT_TRUE(content != NULL);
2312 EXPECT_FALSE(content->rejected);
2313}
2314
2315// Test that an answer contains the correct media content descriptions when
2316// constraints have been set but no stream is sent.
2317TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002318 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002320 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002321 SetRemoteDescriptionWithoutError(offer.release());
2322
2323 webrtc::FakeConstraints constraints_no_receive;
2324 constraints_no_receive.SetMandatoryReceiveAudio(false);
2325 constraints_no_receive.SetMandatoryReceiveVideo(false);
2326
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002327 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002328 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329 const cricket::ContentInfo* content =
2330 cricket::GetFirstAudioContent(answer->description());
2331 ASSERT_TRUE(content != NULL);
2332 EXPECT_TRUE(content->rejected);
2333
2334 content = cricket::GetFirstVideoContent(answer->description());
2335 ASSERT_TRUE(content != NULL);
2336 EXPECT_TRUE(content->rejected);
2337}
2338
2339// Test that an answer contains the correct media content descriptions when
2340// constraints have been set and streams are sent.
2341TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002342 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002344 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345 SetRemoteDescriptionWithoutError(offer.release());
2346
2347 webrtc::FakeConstraints constraints_no_receive;
2348 constraints_no_receive.SetMandatoryReceiveAudio(false);
2349 constraints_no_receive.SetMandatoryReceiveVideo(false);
2350
2351 // Test with a stream with tracks.
2352 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002353 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002354 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355
2356 // TODO(perkj): Should the direction be set to SEND_ONLY?
2357 const cricket::ContentInfo* content =
2358 cricket::GetFirstAudioContent(answer->description());
2359 ASSERT_TRUE(content != NULL);
2360 EXPECT_FALSE(content->rejected);
2361
2362 // TODO(perkj): Should the direction be set to SEND_ONLY?
2363 content = cricket::GetFirstVideoContent(answer->description());
2364 ASSERT_TRUE(content != NULL);
2365 EXPECT_FALSE(content->rejected);
2366}
2367
2368TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2369 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002370 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002371 PeerConnectionInterface::RTCOfferAnswerOptions options;
2372 options.offer_to_receive_audio =
2373 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2374 options.voice_activity_detection = false;
2375
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002376 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002377 CreateOffer(options));
2378
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379 const cricket::ContentInfo* content =
2380 cricket::GetFirstAudioContent(offer->description());
2381 EXPECT_TRUE(content != NULL);
2382 EXPECT_TRUE(VerifyNoCNCodecs(content));
2383}
2384
2385TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2386 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002387 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002389 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002390 SetRemoteDescriptionWithoutError(offer.release());
2391
2392 webrtc::FakeConstraints constraints;
2393 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002394 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002395 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396 const cricket::ContentInfo* content =
2397 cricket::GetFirstAudioContent(answer->description());
2398 ASSERT_TRUE(content != NULL);
2399 EXPECT_TRUE(VerifyNoCNCodecs(content));
2400}
2401
2402// This test verifies the call setup when remote answer with audio only and
2403// later updates with video.
2404TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002405 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002406 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2407 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2408
2409 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002410 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002411
2412 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2414
2415 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2416 // and answer;
2417 SetLocalDescriptionWithoutError(offer);
2418 SetRemoteDescriptionWithoutError(answer);
2419
2420 video_channel_ = media_engine_->GetVideoChannel(0);
2421 voice_channel_ = media_engine_->GetVoiceChannel(0);
2422
2423 ASSERT_TRUE(video_channel_ == NULL);
2424
2425 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2426 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2427 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2428
2429 // Let the remote end update the session descriptions, with Audio and Video.
2430 mediastream_signaling_.SendAudioVideoStream2();
2431 CreateAndSetRemoteOfferAndLocalAnswer();
2432
2433 video_channel_ = media_engine_->GetVideoChannel(0);
2434 voice_channel_ = media_engine_->GetVoiceChannel(0);
2435
2436 ASSERT_TRUE(video_channel_ != NULL);
2437 ASSERT_TRUE(voice_channel_ != NULL);
2438
2439 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2440 ASSERT_EQ(1u, video_channel_->send_streams().size());
2441 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2442 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2443 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2444 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2445 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2446 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2447
2448 // Change session back to audio only.
2449 mediastream_signaling_.UseOptionsAudioOnly();
2450 CreateAndSetRemoteOfferAndLocalAnswer();
2451
2452 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2453 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2454 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2455 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2456 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2457}
2458
2459// This test verifies the call setup when remote answer with video only and
2460// later updates with audio.
2461TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002462 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2464 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2465 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002466 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002467
2468 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002469 options.recv_audio = false;
2470 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2472 offer, options, cricket::SEC_ENABLED);
2473
2474 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2475 // and answer.
2476 SetLocalDescriptionWithoutError(offer);
2477 SetRemoteDescriptionWithoutError(answer);
2478
2479 video_channel_ = media_engine_->GetVideoChannel(0);
2480 voice_channel_ = media_engine_->GetVoiceChannel(0);
2481
2482 ASSERT_TRUE(voice_channel_ == NULL);
2483 ASSERT_TRUE(video_channel_ != NULL);
2484
2485 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2486 ASSERT_EQ(1u, video_channel_->send_streams().size());
2487 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2488
2489 // Update the session descriptions, with Audio and Video.
2490 mediastream_signaling_.SendAudioVideoStream2();
2491 CreateAndSetRemoteOfferAndLocalAnswer();
2492
2493 voice_channel_ = media_engine_->GetVoiceChannel(0);
2494 ASSERT_TRUE(voice_channel_ != NULL);
2495
2496 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2497 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2498 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2499 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2500
2501 // Change session back to video only.
2502 mediastream_signaling_.UseOptionsVideoOnly();
2503 CreateAndSetRemoteOfferAndLocalAnswer();
2504
2505 video_channel_ = media_engine_->GetVideoChannel(0);
2506 voice_channel_ = media_engine_->GetVoiceChannel(0);
2507
2508 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2509 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2510 ASSERT_EQ(1u, video_channel_->send_streams().size());
2511 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2512}
2513
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002514TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002515 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002517 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002518 VerifyCryptoParams(offer->description());
2519 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002520 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002521 VerifyCryptoParams(answer->description());
2522}
2523
2524TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002525 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002526 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002527 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002528 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002529 VerifyNoCryptoParams(offer->description(), false);
2530}
2531
2532TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002533 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002534 VerifyAnswerFromNonCryptoOffer();
2535}
2536
2537TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002538 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539 VerifyAnswerFromCryptoOffer();
2540}
2541
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002542// This test verifies that setLocalDescription fails if
2543// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2544TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002545 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002546 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002547 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2548
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002549 std::string sdp;
2550 RemoveIceUfragPwdLines(offer.get(), &sdp);
2551 SessionDescriptionInterface* modified_offer =
2552 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002553 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002554}
2555
2556// This test verifies that setRemoteDescription fails if
2557// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2558TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002559 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002560 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002561 std::string sdp;
2562 RemoveIceUfragPwdLines(offer.get(), &sdp);
2563 SessionDescriptionInterface* modified_offer =
2564 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002565 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002566}
2567
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002568// This test verifies that setLocalDescription fails if local offer has
2569// too short ice ufrag and pwd strings.
2570TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002571 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002572 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
2573 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002574 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2575
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002576 std::string sdp;
2577 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2578 // recommended values of 4 and 22 bytes respectively.
2579 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2580 SessionDescriptionInterface* modified_offer =
2581 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2582 std::string error;
2583 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2584
2585 // Test with string greater than 256.
2586 sdp.clear();
2587 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2588 &sdp);
2589 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2590 NULL);
2591 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2592}
2593
2594// This test verifies that setRemoteDescription fails if remote offer has
2595// too short ice ufrag and pwd strings.
2596TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002597 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002598 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002599 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002600 std::string sdp;
2601 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2602 // recommended values of 4 and 22 bytes respectively.
2603 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2604 SessionDescriptionInterface* modified_offer =
2605 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2606 std::string error;
2607 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2608
2609 sdp.clear();
2610 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2611 &sdp);
2612 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2613 NULL);
2614 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2615}
2616
Peter Thatcher4eddf182015-04-30 10:55:59 -07002617// kBundlePolicyBalanced bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002618TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2619 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002620 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002621
2622 PeerConnectionInterface::RTCOfferAnswerOptions options;
2623 options.use_rtp_mux = true;
2624
2625 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002627
2628 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2629 session_->GetTransportProxy("video")->impl());
2630
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002631 mediastream_signaling_.SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002632 SessionDescriptionInterface* answer =
2633 CreateRemoteAnswer(session_->local_description());
2634 SetRemoteDescriptionWithoutError(answer);
2635
2636 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2637 session_->GetTransportProxy("video")->impl());
2638}
2639
2640// kBundlePolicyBalanced bundle policy but no BUNDLE in the answer.
2641TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2642 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2643 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002644
Donald Curtis0e209b02015-03-24 09:29:54 -07002645 PeerConnectionInterface::RTCOfferAnswerOptions options;
2646 options.use_rtp_mux = true;
2647
2648 SessionDescriptionInterface* offer = CreateOffer(options);
2649 SetLocalDescriptionWithoutError(offer);
2650
2651 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2652 session_->GetTransportProxy("video")->impl());
2653
2654 mediastream_signaling_.SendAudioVideoStream2();
2655
2656 // Remove BUNDLE from the answer.
2657 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2658 CreateRemoteAnswer(session_->local_description()));
2659 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2660 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2661 JsepSessionDescription* modified_answer =
2662 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2663 modified_answer->Initialize(answer_copy, "1", "1");
2664 SetRemoteDescriptionWithoutError(modified_answer); //
2665
2666 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2667 session_->GetTransportProxy("video")->impl());
2668}
2669
2670// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2671TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2672 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2673 mediastream_signaling_.SendAudioVideoStream1();
2674
2675 PeerConnectionInterface::RTCOfferAnswerOptions options;
2676 options.use_rtp_mux = true;
2677
2678 SessionDescriptionInterface* offer = CreateOffer(options);
2679 SetLocalDescriptionWithoutError(offer);
2680
2681 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2682 session_->GetTransportProxy("video")->impl());
2683
2684 mediastream_signaling_.SendAudioVideoStream2();
2685 SessionDescriptionInterface* answer =
2686 CreateRemoteAnswer(session_->local_description());
2687 SetRemoteDescriptionWithoutError(answer);
2688
2689 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2690 session_->GetTransportProxy("video")->impl());
2691}
2692
2693// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
2694TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
2695 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2696 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002697
Donald Curtis0e209b02015-03-24 09:29:54 -07002698 PeerConnectionInterface::RTCOfferAnswerOptions options;
2699 options.use_rtp_mux = true;
2700
2701 SessionDescriptionInterface* offer = CreateOffer(options);
2702 SetLocalDescriptionWithoutError(offer);
2703
2704 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2705 session_->GetTransportProxy("video")->impl());
2706
2707 mediastream_signaling_.SendAudioVideoStream2();
2708
2709 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002710 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002711 CreateRemoteAnswer(session_->local_description()));
2712 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2713 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2714 JsepSessionDescription* modified_answer =
2715 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2716 modified_answer->Initialize(answer_copy, "1", "1");
2717 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718
Donald Curtis0e209b02015-03-24 09:29:54 -07002719 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2720 session_->GetTransportProxy("video")->impl());
2721}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002722
Peter Thatcher4eddf182015-04-30 10:55:59 -07002723// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002724TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
2725 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2726 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002727
Donald Curtis0e209b02015-03-24 09:29:54 -07002728 PeerConnectionInterface::RTCOfferAnswerOptions options;
2729 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002730
Donald Curtis0e209b02015-03-24 09:29:54 -07002731 SessionDescriptionInterface* offer = CreateOffer(options);
2732 SetLocalDescriptionWithoutError(offer);
2733
2734 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2735 session_->GetTransportProxy("video")->impl());
2736
2737 mediastream_signaling_.SendAudioVideoStream2();
2738 SessionDescriptionInterface* answer =
2739 CreateRemoteAnswer(session_->local_description());
2740 SetRemoteDescriptionWithoutError(answer);
2741
2742 // This should lead to an audio-only call but isn't implemented
2743 // correctly yet.
2744 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2745 session_->GetTransportProxy("video")->impl());
2746}
2747
2748// kBundlePolicyMaxCompat bundle policy but no BUNDLE in the answer.
2749TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
2750 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2751 mediastream_signaling_.SendAudioVideoStream1();
2752 PeerConnectionInterface::RTCOfferAnswerOptions options;
2753 options.use_rtp_mux = true;
2754
2755 SessionDescriptionInterface* offer = CreateOffer(options);
2756 SetLocalDescriptionWithoutError(offer);
2757
2758 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2759 session_->GetTransportProxy("video")->impl());
2760
2761 mediastream_signaling_.SendAudioVideoStream2();
2762
2763 // Remove BUNDLE from the answer.
2764 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2765 CreateRemoteAnswer(session_->local_description()));
2766 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2767 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2768 JsepSessionDescription* modified_answer =
2769 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2770 modified_answer->Initialize(answer_copy, "1", "1");
2771 SetRemoteDescriptionWithoutError(modified_answer); //
2772
2773 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2774 session_->GetTransportProxy("video")->impl());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002775}
2776
Peter Thatcher4eddf182015-04-30 10:55:59 -07002777// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
2778TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
2779 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2780 mediastream_signaling_.SendAudioVideoStream1();
2781
2782 PeerConnectionInterface::RTCOfferAnswerOptions options;
2783 options.use_rtp_mux = true;
2784
2785 SessionDescriptionInterface* offer = CreateOffer(options);
2786 SetRemoteDescriptionWithoutError(offer);
2787
2788 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2789 session_->GetTransportProxy("video")->impl());
2790}
2791
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002792// This test verifies that SetLocalDescription and SetRemoteDescription fails
2793// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2794TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002795 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002796 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002797
2798 PeerConnectionInterface::RTCOfferAnswerOptions options;
2799 options.use_rtp_mux = true;
2800
2801 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002802 std::string offer_str;
2803 offer->ToString(&offer_str);
2804 // Disable rtcp-mux
2805 const std::string rtcp_mux = "rtcp-mux";
2806 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002807 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002808 xrtcp_mux.c_str(), xrtcp_mux.length(),
2809 &offer_str);
2810 JsepSessionDescription *local_offer =
2811 new JsepSessionDescription(JsepSessionDescription::kOffer);
2812 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002813 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002814 JsepSessionDescription *remote_offer =
2815 new JsepSessionDescription(JsepSessionDescription::kOffer);
2816 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002817 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002818 // Trying unmodified SDP.
2819 SetLocalDescriptionWithoutError(offer);
2820}
2821
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002822TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002823 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002824 mediastream_signaling_.SendAudioVideoStream1();
2825 CreateAndSetRemoteOfferAndLocalAnswer();
2826 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2827 ASSERT_TRUE(channel != NULL);
2828 ASSERT_EQ(1u, channel->recv_streams().size());
2829 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2830 double left_vol, right_vol;
2831 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2832 EXPECT_EQ(1, left_vol);
2833 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002834 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002835 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002836 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2837 EXPECT_EQ(0, left_vol);
2838 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002839 EXPECT_EQ(0, renderer->channel_id());
2840 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002841 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2842 EXPECT_EQ(1, left_vol);
2843 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002844 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002845}
2846
2847TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002848 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002849 mediastream_signaling_.SendAudioVideoStream1();
2850 CreateAndSetRemoteOfferAndLocalAnswer();
2851 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2852 ASSERT_TRUE(channel != NULL);
2853 ASSERT_EQ(1u, channel->send_streams().size());
2854 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2855 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2856
2857 cricket::AudioOptions options;
2858 options.echo_cancellation.Set(true);
2859
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002860 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002861 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002862 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2863 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002864 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002865 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002866
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002867 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002868 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002869 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2870 bool value;
2871 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2872 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002873 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002874 EXPECT_TRUE(renderer->sink() == NULL);
2875}
2876
2877TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002878 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002879 mediastream_signaling_.SendAudioVideoStream1();
2880 CreateAndSetRemoteOfferAndLocalAnswer();
2881 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2882 ASSERT_TRUE(channel != NULL);
2883 ASSERT_EQ(1u, channel->send_streams().size());
2884 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2885
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002886 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002887 cricket::AudioOptions options;
2888 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
2889 EXPECT_TRUE(renderer->sink() != NULL);
2890
2891 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
2892 // will invalidate the |renderer_| pointer in the sink and prevent getting a
2893 // SetSink(NULL) callback afterwards.
2894 renderer.reset();
2895
2896 // This will trigger SetSink(NULL) if no OnClose() callback.
2897 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002898}
2899
2900TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002901 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002902 mediastream_signaling_.SendAudioVideoStream1();
2903 CreateAndSetRemoteOfferAndLocalAnswer();
2904 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2905 ASSERT_TRUE(channel != NULL);
2906 ASSERT_LT(0u, channel->renderers().size());
2907 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2908 ASSERT_EQ(1u, channel->recv_streams().size());
2909 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2910 cricket::FakeVideoRenderer renderer;
2911 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2912 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2913 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2914 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2915}
2916
2917TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002918 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002919 mediastream_signaling_.SendAudioVideoStream1();
2920 CreateAndSetRemoteOfferAndLocalAnswer();
2921 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2922 ASSERT_TRUE(channel != NULL);
2923 ASSERT_EQ(1u, channel->send_streams().size());
2924 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2925 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2926 cricket::VideoOptions* options = NULL;
2927 session_->SetVideoSend(send_ssrc, false, options);
2928 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2929 session_->SetVideoSend(send_ssrc, true, options);
2930 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2931}
2932
2933TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2934 TestCanInsertDtmf(false);
2935}
2936
2937TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2938 TestCanInsertDtmf(true);
2939}
2940
2941TEST_F(WebRtcSessionTest, InsertDtmf) {
2942 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002943 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002944 mediastream_signaling_.SendAudioVideoStream1();
2945 CreateAndSetRemoteOfferAndLocalAnswer();
2946 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2947 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2948
2949 // Insert DTMF
2950 const int expected_flags = DF_SEND;
2951 const int expected_duration = 90;
2952 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2953 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2954 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2955
2956 // Verify
2957 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2958 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2959 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2960 expected_duration, expected_flags));
2961 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2962 expected_duration, expected_flags));
2963 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2964 expected_duration, expected_flags));
2965}
2966
2967// This test verifies the |initiator| flag when session initiates the call.
2968TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002969 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002970 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002971 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002972 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2973 SetLocalDescriptionWithoutError(offer);
2974 EXPECT_TRUE(session_->initiator());
2975 SetRemoteDescriptionWithoutError(answer);
2976 EXPECT_TRUE(session_->initiator());
2977}
2978
2979// This test verifies the |initiator| flag when session receives the call.
2980TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002981 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002982 EXPECT_FALSE(session_->initiator());
2983 SessionDescriptionInterface* offer = CreateRemoteOffer();
2984 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002985 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002986
2987 EXPECT_FALSE(session_->initiator());
2988 SetLocalDescriptionWithoutError(answer);
2989 EXPECT_FALSE(session_->initiator());
2990}
2991
2992// This test verifies the ice protocol type at initiator of the call
2993// if |a=ice-options:google-ice| is present in answer.
2994TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002995 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002996 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002997 SessionDescriptionInterface* offer = CreateOffer();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002998 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002999 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003000 SetLocalDescriptionWithoutError(offer);
3001 std::string sdp;
3002 EXPECT_TRUE(answer->ToString(&sdp));
3003 // Adding ice-options to the session level.
3004 InjectAfter("t=0 0\r\n",
3005 "a=ice-options:google-ice\r\n",
3006 &sdp);
3007 SessionDescriptionInterface* answer_with_gice =
3008 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00003009 // Default offer is ICEPROTO_RFC5245, so we expect responder with
3010 // only gice to fail.
3011 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed, answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003012}
3013
3014// This test verifies the ice protocol type at initiator of the call
3015// if ICE RFC5245 is supported in answer.
3016TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003017 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003018 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003019 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003020 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3021 SetLocalDescriptionWithoutError(offer);
3022
3023 SetRemoteDescriptionWithoutError(answer);
3024 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
3025 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
3026}
3027
3028// This test verifies the ice protocol type at receiver side of the call if
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003029// receiver decides to use ice RFC 5245.
3030TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003031 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003032 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003033 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003034 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003035 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003036 SetLocalDescriptionWithoutError(answer);
3037 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
3038 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
3039}
3040
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003041// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3042TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003043 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003044 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003045 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003046 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003047 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003048 CreateRemoteAnswer(session_->local_description()));
3049
3050 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3051 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003052 JsepSessionDescription* modified_answer =
3053 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003054
3055 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3056 answer->session_id(),
3057 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003058 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003059
wu@webrtc.org4e393072014-04-07 17:04:35 +00003060 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003061 std::string sdp;
3062 EXPECT_TRUE(answer->ToString(&sdp));
3063 const std::string kAudioMid = "a=mid:audio";
3064 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003065 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003066 kAudioMidReplaceStr.c_str(),
3067 kAudioMidReplaceStr.length(),
3068 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003069 SessionDescriptionInterface* modified_answer1 =
3070 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003071 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003072
wu@webrtc.org4e393072014-04-07 17:04:35 +00003073 // Different media types.
3074 EXPECT_TRUE(answer->ToString(&sdp));
3075 const std::string kAudioMline = "m=audio";
3076 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003077 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003078 kAudioMlineReplaceStr.c_str(),
3079 kAudioMlineReplaceStr.length(),
3080 &sdp);
3081 SessionDescriptionInterface* modified_answer2 =
3082 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3083 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3084
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003085 SetRemoteDescriptionWithoutError(answer.release());
3086}
3087
3088// Verifying remote offer and local answer have matching m-lines as per
3089// RFC 3264.
3090TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003091 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003092 mediastream_signaling_.SendAudioVideoStream1();
3093 SessionDescriptionInterface* offer = CreateRemoteOffer();
3094 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003095 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003096
3097 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3098 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003099 JsepSessionDescription* modified_answer =
3100 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003101
3102 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3103 answer->session_id(),
3104 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003105 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003106 SetLocalDescriptionWithoutError(answer);
3107}
3108
3109// This test verifies that WebRtcSession does not start candidate allocation
3110// before SetLocalDescription is called.
3111TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003112 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003113 mediastream_signaling_.SendAudioVideoStream1();
3114 SessionDescriptionInterface* offer = CreateRemoteOffer();
3115 cricket::Candidate candidate;
3116 candidate.set_component(1);
3117 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3118 candidate);
3119 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3120 cricket::Candidate candidate1;
3121 candidate1.set_component(1);
3122 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3123 candidate1);
3124 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3125 SetRemoteDescriptionWithoutError(offer);
3126 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
3127 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
3128
3129 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003130 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003131 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3132 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3133
wu@webrtc.org91053e72013-08-10 07:18:04 +00003134 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003135 SetLocalDescriptionWithoutError(answer);
3136 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
3137 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
3138 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3139}
3140
3141// This test verifies that crypto parameter is updated in local session
3142// description as per security policy set in MediaSessionDescriptionFactory.
3143TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003144 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003145 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003146 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003147
3148 // Making sure SetLocalDescription correctly sets crypto value in
3149 // SessionDescription object after de-serialization of sdp string. The value
3150 // will be set as per MediaSessionDescriptionFactory.
3151 std::string offer_str;
3152 offer->ToString(&offer_str);
3153 SessionDescriptionInterface* jsep_offer_str =
3154 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3155 SetLocalDescriptionWithoutError(jsep_offer_str);
3156 EXPECT_TRUE(session_->voice_channel()->secure_required());
3157 EXPECT_TRUE(session_->video_channel()->secure_required());
3158}
3159
3160// This test verifies the crypto parameter when security is disabled.
3161TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003162 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003163 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003164 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003165 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003166
3167 // Making sure SetLocalDescription correctly sets crypto value in
3168 // SessionDescription object after de-serialization of sdp string. The value
3169 // will be set as per MediaSessionDescriptionFactory.
3170 std::string offer_str;
3171 offer->ToString(&offer_str);
3172 SessionDescriptionInterface *jsep_offer_str =
3173 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3174 SetLocalDescriptionWithoutError(jsep_offer_str);
3175 EXPECT_FALSE(session_->voice_channel()->secure_required());
3176 EXPECT_FALSE(session_->video_channel()->secure_required());
3177}
3178
3179// This test verifies that an answer contains new ufrag and password if an offer
3180// with new ufrag and password is received.
3181TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003182 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003183 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003184 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003185 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003186 CreateRemoteOffer(options));
3187 SetRemoteDescriptionWithoutError(offer.release());
3188
3189 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003190 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003191 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003192 SetLocalDescriptionWithoutError(answer.release());
3193
3194 // Receive an offer with new ufrag and password.
3195 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003196 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003197 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003198 SetRemoteDescriptionWithoutError(updated_offer1.release());
3199
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003200 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003201 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003202
3203 CompareIceUfragAndPassword(updated_answer1->description(),
3204 session_->local_description()->description(),
3205 false);
3206
3207 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003208}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003209
wu@webrtc.org91053e72013-08-10 07:18:04 +00003210// This test verifies that an answer contains old ufrag and password if an offer
3211// with old ufrag and password is received.
3212TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003213 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003214 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003215 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003216 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003217 CreateRemoteOffer(options));
3218 SetRemoteDescriptionWithoutError(offer.release());
3219
3220 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003221 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003222 CreateAnswer(NULL));
3223 SetLocalDescriptionWithoutError(answer.release());
3224
3225 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003226 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003227 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003228 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003229 SetRemoteDescriptionWithoutError(updated_offer2.release());
3230
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003231 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003232 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003233
3234 CompareIceUfragAndPassword(updated_answer2->description(),
3235 session_->local_description()->description(),
3236 true);
3237
3238 SetLocalDescriptionWithoutError(updated_answer2.release());
3239}
3240
3241TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003242 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003243 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003244 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003245 const std::string session_id_orig = offer->session_id();
3246 const std::string session_version_orig = offer->session_version();
3247 SetLocalDescriptionWithoutError(offer);
3248
3249 video_channel_ = media_engine_->GetVideoChannel(0);
3250 video_channel_->set_fail_set_send_codecs(true);
3251
3252 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003253 SessionDescriptionInterface* answer =
3254 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003255 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003256}
3257
3258// Runs the loopback call test with BUNDLE and STUN disabled.
3259TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3260 // Lets try with only UDP ports.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003261 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003262 cricket::PORTALLOCATOR_DISABLE_TCP |
3263 cricket::PORTALLOCATOR_DISABLE_STUN |
3264 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003265 TestLoopbackCall();
3266}
3267
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003268TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
3269 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3270 cricket::PORTALLOCATOR_DISABLE_TCP |
3271 cricket::PORTALLOCATOR_DISABLE_STUN |
3272 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3273 cricket::PORTALLOCATOR_DISABLE_RELAY);
3274
3275 // best connection is IPv6 since it has higher network preference.
3276 LoopbackNetworkConfiguration config;
3277 config.test_ipv6_network_ = true;
3278 config.best_connection_after_initial_ice_converged_ =
3279 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3280
3281 TestLoopbackCall(config);
3282}
3283
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003284// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003285TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003286 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003287 cricket::PORTALLOCATOR_DISABLE_TCP |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003288 cricket::PORTALLOCATOR_DISABLE_RELAY);
3289 TestLoopbackCall();
3290}
3291
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003292TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003293 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003294 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003295 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003296
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003297 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3298 std::string error_code_str = "ERROR_CONTENT";
3299 std::string error_desc = "Fake session error description.";
3300 session_->SetError(error_code, error_desc);
3301
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003302 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3303 SessionDescriptionInterface* answer =
3304 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003305
3306 std::string action;
3307 std::ostringstream session_error_msg;
3308 session_error_msg << kSessionError << error_code_str << ". ";
3309 session_error_msg << kSessionErrorDesc << error_desc << ".";
3310 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3311 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003312}
3313
3314TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3315 constraints_.reset(new FakeConstraints());
3316 constraints_->AddOptional(
3317 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003318 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003319
3320 SetLocalDescriptionWithDataChannel();
3321 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3322}
3323
3324TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003325 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003326
3327 constraints_.reset(new FakeConstraints());
3328 constraints_->AddOptional(
3329 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003330 options_.disable_sctp_data_channels = false;
3331
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003332 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003333
3334 SetLocalDescriptionWithDataChannel();
3335 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3336}
3337
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003338TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003339 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003340
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003341 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003342
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003343 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003344 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003345 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3346}
3347
3348TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003349 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003350 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003351 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003352
3353 // Create remote offer with SCTP.
3354 cricket::MediaSessionOptions options;
3355 options.data_channel_type = cricket::DCT_SCTP;
3356 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003357 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003358 SetRemoteDescriptionWithoutError(offer);
3359
3360 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003361 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003362 EXPECT_TRUE(answer != NULL);
3363 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3364 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003365}
3366
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003367TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3368 constraints_.reset(new FakeConstraints());
3369 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003370 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003371 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003372
3373 SetLocalDescriptionWithDataChannel();
3374 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3375}
3376
3377TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003378 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003379
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003380 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003381
3382 SetLocalDescriptionWithDataChannel();
3383 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3384}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003385
wu@webrtc.org97077a32013-10-25 21:18:33 +00003386TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003387 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003388 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003389 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003390
3391 SetLocalDescriptionWithDataChannel();
3392 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3393}
3394
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003395TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003396 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003397 const int new_send_port = 9998;
3398 const int new_recv_port = 7775;
3399
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003400 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003401 SetFactoryDtlsSrtp();
3402
3403 // By default, don't actually add the codecs to desc_factory_; they don't
3404 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3405 // let the session description get parsed. That'll get the proper codecs
3406 // into the stream.
3407 cricket::MediaSessionOptions options;
3408 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3409 "stream1", new_send_port, options);
3410
3411 // SetRemoteDescription will take the ownership of the offer.
3412 SetRemoteDescriptionWithoutError(offer);
3413
3414 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3415 new_recv_port, CreateAnswer(NULL));
3416 ASSERT_TRUE(answer != NULL);
3417
3418 // Now set the local description, which'll take ownership of the answer.
3419 SetLocalDescriptionWithoutError(answer);
3420
3421 // TEST PLAN: Set the port number to something new, set it in the SDP,
3422 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003423 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003424 dci.reliable = true;
3425 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003426 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003427 session_->CreateDataChannel("datachannel", &dci);
3428
3429 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3430 int portnum = -1;
3431 ASSERT_TRUE(ch != NULL);
3432 ASSERT_EQ(1UL, ch->send_codecs().size());
3433 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
3434 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3435 ch->send_codecs()[0].name.c_str()));
3436 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3437 &portnum));
3438 EXPECT_EQ(new_send_port, portnum);
3439
3440 ASSERT_EQ(1UL, ch->recv_codecs().size());
3441 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
3442 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3443 ch->recv_codecs()[0].name.c_str()));
3444 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3445 &portnum));
3446 EXPECT_EQ(new_recv_port, portnum);
3447}
3448
wu@webrtc.org91053e72013-08-10 07:18:04 +00003449// Verifies that CreateOffer succeeds when CreateOffer is called before async
3450// identity generation is finished.
3451TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003452 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003453 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003454
3455 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003456 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003457 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3458
wu@webrtc.org91053e72013-08-10 07:18:04 +00003459 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003460 VerifyNoCryptoParams(offer->description(), true);
3461 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003462}
3463
3464// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3465// identity generation is finished.
3466TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003467 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003468 InitWithDtls();
3469 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003470
3471 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003472 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003473 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003474 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003475 ASSERT_TRUE(offer.get() != NULL);
3476 SetRemoteDescriptionWithoutError(offer.release());
3477
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003478 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003479 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003480 VerifyNoCryptoParams(answer->description(), true);
3481 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003482}
3483
3484// Verifies that CreateOffer succeeds when CreateOffer is called after async
3485// identity generation is finished.
3486TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003487 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003488 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003489
3490 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003491
3492 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003493 EXPECT_TRUE(offer != NULL);
3494}
3495
3496// Verifies that CreateOffer fails when CreateOffer is called after async
3497// identity generation fails.
3498TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003499 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003500 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003501
3502 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003503
3504 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003505 EXPECT_TRUE(offer == NULL);
3506}
3507
3508// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3509// before async identity generation is finished.
3510TEST_F(WebRtcSessionTest,
3511 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003512 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003513 VerifyMultipleAsyncCreateDescription(
3514 true, CreateSessionDescriptionRequest::kOffer);
3515}
3516
3517// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3518// before async identity generation fails.
3519TEST_F(WebRtcSessionTest,
3520 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003521 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003522 VerifyMultipleAsyncCreateDescription(
3523 false, CreateSessionDescriptionRequest::kOffer);
3524}
3525
3526// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3527// before async identity generation is finished.
3528TEST_F(WebRtcSessionTest,
3529 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003530 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003531 VerifyMultipleAsyncCreateDescription(
3532 true, CreateSessionDescriptionRequest::kAnswer);
3533}
3534
3535// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3536// before async identity generation fails.
3537TEST_F(WebRtcSessionTest,
3538 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003539 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003540 VerifyMultipleAsyncCreateDescription(
3541 false, CreateSessionDescriptionRequest::kAnswer);
3542}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003543
3544// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3545// offer has no SDES crypto but only DTLS fingerprint.
3546TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3547 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003548 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003549 // Create a remote offer with secured transport disabled.
3550 cricket::MediaSessionOptions options;
3551 JsepSessionDescription* offer(CreateRemoteOffer(
3552 options, cricket::SEC_DISABLED));
3553 // Adds a DTLS fingerprint to the remote offer.
3554 cricket::SessionDescription* sdp = offer->description();
3555 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3556 ASSERT_TRUE(audio != NULL);
3557 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3558 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003559 rtc::SSLFingerprint::CreateFromRfc4572(
3560 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003561 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003562 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003563}
3564
wu@webrtc.orgde305012013-10-31 15:40:38 +00003565// This test verifies DSCP is properly applied on the media channels.
3566TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3567 constraints_.reset(new FakeConstraints());
3568 constraints_->AddOptional(
3569 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003570 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003571 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003572 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003573
3574 SetLocalDescriptionWithoutError(offer);
3575
3576 video_channel_ = media_engine_->GetVideoChannel(0);
3577 voice_channel_ = media_engine_->GetVoiceChannel(0);
3578
3579 ASSERT_TRUE(video_channel_ != NULL);
3580 ASSERT_TRUE(voice_channel_ != NULL);
3581 cricket::AudioOptions audio_options;
3582 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3583 cricket::VideoOptions video_options;
3584 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3585 EXPECT_TRUE(audio_options.dscp.IsSet());
3586 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3587 EXPECT_TRUE(video_options.dscp.IsSet());
3588 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3589}
3590
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003591TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3592 constraints_.reset(new FakeConstraints());
3593 constraints_->AddOptional(
3594 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3595 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003596 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003597 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003598 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003599
3600 SetLocalDescriptionWithoutError(offer);
3601
3602 video_channel_ = media_engine_->GetVideoChannel(0);
3603
3604 ASSERT_TRUE(video_channel_ != NULL);
3605 cricket::VideoOptions video_options;
3606 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3607 EXPECT_TRUE(
3608 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3609}
3610
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003611TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3612 // Number of unsignalled receiving streams should be between 0 and
3613 // kMaxUnsignalledRecvStreams.
3614 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3615 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3616 kMaxUnsignalledRecvStreams);
3617 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3618}
3619
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003620TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3621 constraints_.reset(new FakeConstraints());
3622 constraints_->AddOptional(
3623 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3624 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003625 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003626 mediastream_signaling_.SendAudioVideoStream1();
3627 SessionDescriptionInterface* offer = CreateOffer();
3628
3629 SetLocalDescriptionWithoutError(offer);
3630
3631 voice_channel_ = media_engine_->GetVoiceChannel(0);
3632
3633 ASSERT_TRUE(voice_channel_ != NULL);
3634 cricket::AudioOptions audio_options;
3635 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3636 EXPECT_TRUE(
3637 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3638}
3639
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003640// Tests that we can renegotiate new media content with ICE candidates in the
3641// new remote SDP.
3642TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003643 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003644 InitWithDtls();
3645 SetFactoryDtlsSrtp();
3646
3647 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003648 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003649 SetLocalDescriptionWithoutError(offer);
3650
3651 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3652 SetRemoteDescriptionWithoutError(answer);
3653
3654 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003655 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003656 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3657
3658 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003659 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003660 candidate1.set_component(1);
3661 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3662 candidate1);
3663 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3664 SetRemoteDescriptionWithoutError(offer);
3665
3666 answer = CreateAnswer(NULL);
3667 SetLocalDescriptionWithoutError(answer);
3668}
3669
3670// Tests that we can renegotiate new media content with ICE candidates separated
3671// from the remote SDP.
3672TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003673 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003674 InitWithDtls();
3675 SetFactoryDtlsSrtp();
3676
3677 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003678 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003679 SetLocalDescriptionWithoutError(offer);
3680
3681 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3682 SetRemoteDescriptionWithoutError(answer);
3683
3684 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003685 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003686 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3687 SetRemoteDescriptionWithoutError(offer);
3688
3689 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003690 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003691 candidate1.set_component(1);
3692 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3693 candidate1);
3694 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3695
3696 answer = CreateAnswer(NULL);
3697 SetLocalDescriptionWithoutError(answer);
3698}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00003699// Tests that RTX codec is removed from the answer when it isn't supported
3700// by local side.
3701TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
3702 Init();
3703 mediastream_signaling_.SendAudioVideoStream1();
3704 std::string offer_sdp(kSdpWithRtx);
3705
3706 SessionDescriptionInterface* offer =
3707 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
3708 EXPECT_TRUE(offer->ToString(&offer_sdp));
3709
3710 // Offer SDP contains the RTX codec.
3711 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
3712 SetRemoteDescriptionWithoutError(offer);
3713
3714 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3715 std::string answer_sdp;
3716 answer->ToString(&answer_sdp);
3717 // Answer SDP removes the unsupported RTX codec.
3718 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
3719 SetLocalDescriptionWithoutError(answer);
3720}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003721
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003722// This verifies that the voice channel after bundle has both options from video
3723// and voice channels.
3724TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3725 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3726 mediastream_signaling_.SendAudioVideoStream1();
3727
3728 PeerConnectionInterface::RTCOfferAnswerOptions options;
3729 options.use_rtp_mux = true;
3730
3731 SessionDescriptionInterface* offer = CreateOffer(options);
3732 SetLocalDescriptionWithoutError(offer);
3733
3734 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3735 rtc::Socket::Option::OPT_SNDBUF, 4000);
3736
3737 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3738 rtc::Socket::Option::OPT_RCVBUF, 8000);
3739
3740 int option_val;
3741 EXPECT_TRUE(session_->video_channel()->transport_channel()->GetOption(
3742 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3743 EXPECT_EQ(4000, option_val);
3744 EXPECT_FALSE(session_->voice_channel()->transport_channel()->GetOption(
3745 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3746
3747 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3748 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3749 EXPECT_EQ(8000, option_val);
3750 EXPECT_FALSE(session_->video_channel()->transport_channel()->GetOption(
3751 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3752
3753 EXPECT_NE(session_->voice_channel()->transport_channel(),
3754 session_->video_channel()->transport_channel());
3755
3756 mediastream_signaling_.SendAudioVideoStream2();
3757 SessionDescriptionInterface* answer =
3758 CreateRemoteAnswer(session_->local_description());
3759 SetRemoteDescriptionWithoutError(answer);
3760
3761 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3762 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3763 EXPECT_EQ(4000, option_val);
3764
3765 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3766 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3767 EXPECT_EQ(8000, option_val);
3768}
3769
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003770// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3771// currently fails because upon disconnection and reconnection OnIceComplete is
3772// called more than once without returning to IceGatheringGathering.