blob: 9267c4c6a9da99da2bfee00557a6a6c76e261130 [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
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159// Add some extra |newlines| to the |message| after |line|.
160static void InjectAfter(const std::string& line,
161 const std::string& newlines,
162 std::string* message) {
163 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000164 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 tmp.c_str(), tmp.length(), message);
166}
167
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000168class FakeMetricsObserver : public webrtc::MetricsObserverInterface {
169 public:
170 FakeMetricsObserver() { Reset(); }
171 void Reset() {
172 memset(peer_connection_metrics_counters_, 0,
173 sizeof(peer_connection_metrics_counters_));
174 memset(peer_connection_metrics_name_, 0,
175 sizeof(peer_connection_metrics_name_));
176 }
177
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000178 void IncrementCounter(webrtc::PeerConnectionMetricsCounter type) override {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000179 peer_connection_metrics_counters_[type]++;
180 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000181 void AddHistogramSample(webrtc::PeerConnectionMetricsName type,
182 int value) override {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000183 ASSERT(peer_connection_metrics_name_[type] == 0);
184 peer_connection_metrics_name_[type] = value;
185 }
186
187 int peer_connection_metrics_counters_
188 [webrtc::kPeerConnectionMetricsCounter_Max];
189 int peer_connection_metrics_name_[webrtc::kPeerConnectionMetricsCounter_Max];
190
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000191 int AddRef() override { return 1; }
192 int Release() override { return 1; }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000193};
194
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195class MockIceObserver : public webrtc::IceObserver {
196 public:
197 MockIceObserver()
198 : oncandidatesready_(false),
199 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
200 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
201 }
202
203 virtual void OnIceConnectionChange(
204 PeerConnectionInterface::IceConnectionState new_state) {
205 ice_connection_state_ = new_state;
206 }
207 virtual void OnIceGatheringChange(
208 PeerConnectionInterface::IceGatheringState new_state) {
209 // We can never transition back to "new".
210 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
211 ice_gathering_state_ = new_state;
212
213 // oncandidatesready_ really means "ICE gathering is complete".
214 // This if statement ensures that this value remains correct when we
215 // transition from kIceGatheringComplete to kIceGatheringGathering.
216 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
217 oncandidatesready_ = false;
218 }
219 }
220
221 // Found a new candidate.
222 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000223 switch (candidate->sdp_mline_index()) {
224 case kMediaContentIndex0:
225 mline_0_candidates_.push_back(candidate->candidate());
226 break;
227 case kMediaContentIndex1:
228 mline_1_candidates_.push_back(candidate->candidate());
229 break;
230 default:
231 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000233
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 // The ICE gathering state should always be Gathering when a candidate is
235 // received (or possibly Completed in the case of the final candidate).
236 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
237 }
238
239 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
240 virtual void OnIceComplete() {
241 EXPECT_FALSE(oncandidatesready_);
242 oncandidatesready_ = true;
243
244 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
245 // be called approximately simultaneously. For ease of testing, this
246 // check additionally requires that they be called in the above order.
247 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
248 ice_gathering_state_);
249 }
250
251 bool oncandidatesready_;
252 std::vector<cricket::Candidate> mline_0_candidates_;
253 std::vector<cricket::Candidate> mline_1_candidates_;
254 PeerConnectionInterface::IceConnectionState ice_connection_state_;
255 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
256};
257
258class WebRtcSessionForTest : public webrtc::WebRtcSession {
259 public:
260 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000261 rtc::Thread* signaling_thread,
262 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263 cricket::PortAllocator* port_allocator,
264 webrtc::IceObserver* ice_observer,
265 webrtc::MediaStreamSignaling* mediastream_signaling)
266 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
267 mediastream_signaling) {
268 RegisterIceObserver(ice_observer);
269 }
270 virtual ~WebRtcSessionForTest() {}
271
272 using cricket::BaseSession::GetTransportProxy;
273 using webrtc::WebRtcSession::SetAudioPlayout;
274 using webrtc::WebRtcSession::SetAudioSend;
275 using webrtc::WebRtcSession::SetCaptureDevice;
276 using webrtc::WebRtcSession::SetVideoPlayout;
277 using webrtc::WebRtcSession::SetVideoSend;
278};
279
wu@webrtc.org91053e72013-08-10 07:18:04 +0000280class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000281 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000283 enum State {
284 kInit,
285 kFailed,
286 kSucceeded,
287 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000288 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000289
290 // CreateSessionDescriptionObserver implementation.
291 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000292 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000293 state_ = kSucceeded;
294 }
295 virtual void OnFailure(const std::string& error) {
296 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297 }
298
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000299 SessionDescriptionInterface* description() { return description_.get(); }
300
301 SessionDescriptionInterface* ReleaseDescription() {
302 return description_.release();
303 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304
wu@webrtc.org91053e72013-08-10 07:18:04 +0000305 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306
wu@webrtc.org91053e72013-08-10 07:18:04 +0000307 protected:
308 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309
310 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000311 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000312 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313};
314
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000315class FakeAudioRenderer : public cricket::AudioRenderer {
316 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000317 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
318 virtual ~FakeAudioRenderer() {
319 if (sink_)
320 sink_->OnClose();
321 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000322
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000323 void AddChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000324 ASSERT(channel_id_ == -1);
325 channel_id_ = channel_id;
326 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000327 void RemoveChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000328 ASSERT(channel_id == channel_id_);
329 channel_id_ = -1;
330 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000331 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000332
333 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000334 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000335 private:
336 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000337 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000338};
339
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340class WebRtcSessionTest : public testing::Test {
341 protected:
342 // TODO Investigate why ChannelManager crashes, if it's created
343 // after stun_server.
344 WebRtcSessionTest()
345 : media_engine_(new cricket::FakeMediaEngine()),
346 data_engine_(new cricket::FakeDataEngine()),
347 device_manager_(new cricket::FakeDeviceManager()),
348 channel_manager_(new cricket::ChannelManager(
349 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000350 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 tdesc_factory_(new cricket::TransportDescriptionFactory()),
352 desc_factory_(new cricket::MediaSessionDescriptionFactory(
353 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000354 pss_(new rtc::PhysicalSocketServer),
355 vss_(new rtc::VirtualSocketServer(pss_.get())),
356 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000358 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000359 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000360 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
361 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000362 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000363 mediastream_signaling_(channel_manager_.get()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000365
366 cricket::ServerAddresses stun_servers;
367 stun_servers.insert(stun_socket_addr_);
368 allocator_.reset(new cricket::BasicPortAllocator(
369 &network_manager_,
370 stun_servers,
371 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000372 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373 cricket::PORTALLOCATOR_DISABLE_RELAY |
jiayl@webrtc.orgdacdd942015-01-23 17:33:34 +0000374 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
375 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376 EXPECT_TRUE(channel_manager_->Init());
377 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000378 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 }
380
381 void AddInterface(const SocketAddress& addr) {
382 network_manager_.AddInterface(addr);
383 }
384
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000385 void Init(
386 DTLSIdentityServiceInterface* identity_service,
387 PeerConnectionInterface::IceTransportsType ice_transport_type,
388 PeerConnectionInterface::BundlePolicy bundle_policy) {
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(),
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000402 identity_service, ice_transport_type,
403 bundle_policy));
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000404 session_->set_metrics_observer(&metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405 }
406
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000407 void Init() {
408 Init(NULL, PeerConnectionInterface::kAll,
409 PeerConnectionInterface::kBundlePolicyBalanced);
410 }
411
412 void InitWithIceTransport(
413 PeerConnectionInterface::IceTransportsType ice_transport_type) {
414 Init(NULL, ice_transport_type,
415 PeerConnectionInterface::kBundlePolicyBalanced);
416 }
417
418 void InitWithBundlePolicy(
419 PeerConnectionInterface::BundlePolicy bundle_policy) {
420 Init(NULL, PeerConnectionInterface::kAll, bundle_policy);
421 }
422
423 void InitWithDtls(bool identity_request_should_fail = false) {
424 FakeIdentityService* identity_service = new FakeIdentityService();
425 identity_service->set_should_fail(identity_request_should_fail);
426 Init(identity_service,
427 PeerConnectionInterface::kAll,
428 PeerConnectionInterface::kBundlePolicyBalanced);
429 }
430
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431 void InitWithDtmfCodec() {
432 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000433 const cricket::AudioCodec kTelephoneEventCodec(
434 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000435 std::vector<cricket::AudioCodec> codecs;
436 codecs.push_back(kTelephoneEventCodec);
437 media_engine_->SetAudioCodecs(codecs);
438 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000439 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440 }
441
442 // Creates a local offer and applies it. Starts ice.
443 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
444 // to decide which streams to create.
445 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000446 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447 SetLocalDescriptionWithoutError(offer);
448 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
449 observer_.ice_gathering_state_,
450 kIceCandidatesTimeout);
451 }
452
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000453 SessionDescriptionInterface* CreateOffer() {
454 PeerConnectionInterface::RTCOfferAnswerOptions options;
455 options.offer_to_receive_audio =
456 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
457
458 return CreateOffer(options);
459 }
460
wu@webrtc.org91053e72013-08-10 07:18:04 +0000461 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000462 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000463 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000464 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000465 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000466 EXPECT_TRUE_WAIT(
467 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000468 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000469 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000470 }
471
472 SessionDescriptionInterface* CreateAnswer(
473 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000474 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000475 = new WebRtcSessionCreateSDPObserverForTest();
476 session_->CreateAnswer(observer, constraints);
477 EXPECT_TRUE_WAIT(
478 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000479 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000480 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000481 }
482
wu@webrtc.org364f2042013-11-20 21:49:41 +0000483 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484 return (session_->voice_channel() != NULL &&
485 session_->video_channel() != NULL);
486 }
487
wu@webrtc.org364f2042013-11-20 21:49:41 +0000488 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000489 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
490 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
491 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
492 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
493 }
494
495 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
496 ASSERT_TRUE(session_.get() != NULL);
497 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
498 ASSERT_TRUE(content != NULL);
499 const cricket::AudioContentDescription* audio_content =
500 static_cast<const cricket::AudioContentDescription*>(
501 content->description);
502 ASSERT_TRUE(audio_content != NULL);
503 ASSERT_EQ(1U, audio_content->cryptos().size());
504 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
505 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
506 audio_content->cryptos()[0].cipher_suite);
507 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
508 audio_content->protocol());
509
510 content = cricket::GetFirstVideoContent(sdp);
511 ASSERT_TRUE(content != NULL);
512 const cricket::VideoContentDescription* video_content =
513 static_cast<const cricket::VideoContentDescription*>(
514 content->description);
515 ASSERT_TRUE(video_content != NULL);
516 ASSERT_EQ(1U, video_content->cryptos().size());
517 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
518 video_content->cryptos()[0].cipher_suite);
519 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
520 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
521 video_content->protocol());
522 }
523
524 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
525 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
526 ASSERT_TRUE(content != NULL);
527 const cricket::AudioContentDescription* audio_content =
528 static_cast<const cricket::AudioContentDescription*>(
529 content->description);
530 ASSERT_TRUE(audio_content != NULL);
531 ASSERT_EQ(0U, audio_content->cryptos().size());
532
533 content = cricket::GetFirstVideoContent(sdp);
534 ASSERT_TRUE(content != NULL);
535 const cricket::VideoContentDescription* video_content =
536 static_cast<const cricket::VideoContentDescription*>(
537 content->description);
538 ASSERT_TRUE(video_content != NULL);
539 ASSERT_EQ(0U, video_content->cryptos().size());
540
541 if (dtls) {
542 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
543 audio_content->protocol());
544 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
545 video_content->protocol());
546 } else {
547 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
548 audio_content->protocol());
549 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
550 video_content->protocol());
551 }
552 }
553
554 // Set the internal fake description factories to do DTLS-SRTP.
555 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000556 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000558 rtc::ToString(rtc::CreateRandomId());
559 identity_.reset(rtc::SSLIdentity::Generate(identity_name));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000560 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
562 }
563
564 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
565 bool expected) {
566 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
567 ASSERT_TRUE(audio != NULL);
568 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000569 const TransportInfo* video = sdp->GetTransportInfoByName("video");
570 ASSERT_TRUE(video != NULL);
571 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 }
573
574 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000575 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000577 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000578 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000579 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000580 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000582 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
583 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000584 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000585 // Answer should be NULL as no crypto params in offer.
586 ASSERT_TRUE(answer == NULL);
587 }
588
589 void VerifyAnswerFromCryptoOffer() {
590 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000591 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592 options.bundle_enabled = true;
593 scoped_ptr<JsepSessionDescription> offer(
594 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
595 ASSERT_TRUE(offer.get() != NULL);
596 VerifyCryptoParams(offer->description());
597 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000598 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000599 ASSERT_TRUE(answer.get() != NULL);
600 VerifyCryptoParams(answer->description());
601 }
602
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000603 void SetAndVerifyNumUnsignalledRecvStreams(
604 int value_set, int value_expected) {
605 constraints_.reset(new FakeConstraints());
606 constraints_->AddOptional(
607 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
608 value_set);
609 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000610 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000611 mediastream_signaling_.SendAudioVideoStream1();
612 SessionDescriptionInterface* offer = CreateOffer();
613
614 SetLocalDescriptionWithoutError(offer);
615
616 video_channel_ = media_engine_->GetVideoChannel(0);
617
618 ASSERT_TRUE(video_channel_ != NULL);
619 cricket::VideoOptions video_options;
620 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
621 EXPECT_EQ(value_expected,
622 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
623 }
624
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000625 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
626 const cricket::SessionDescription* desc2,
627 bool expect_equal) {
628 if (desc1->contents().size() != desc2->contents().size()) {
629 EXPECT_FALSE(expect_equal);
630 return;
631 }
632
633 const cricket::ContentInfos& contents = desc1->contents();
634 cricket::ContentInfos::const_iterator it = contents.begin();
635
636 for (; it != contents.end(); ++it) {
637 const cricket::TransportDescription* transport_desc1 =
638 desc1->GetTransportDescriptionByName(it->name);
639 const cricket::TransportDescription* transport_desc2 =
640 desc2->GetTransportDescriptionByName(it->name);
641 if (!transport_desc1 || !transport_desc2) {
642 EXPECT_FALSE(expect_equal);
643 return;
644 }
645 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
646 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
647 EXPECT_FALSE(expect_equal);
648 return;
649 }
650 }
651 EXPECT_TRUE(expect_equal);
652 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000653
654 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
655 std::string *sdp) {
656 const cricket::SessionDescription* desc = current_desc->description();
657 EXPECT_TRUE(current_desc->ToString(sdp));
658
659 const cricket::ContentInfos& contents = desc->contents();
660 cricket::ContentInfos::const_iterator it = contents.begin();
661 // Replace ufrag and pwd lines with empty strings.
662 for (; it != contents.end(); ++it) {
663 const cricket::TransportDescription* transport_desc =
664 desc->GetTransportDescriptionByName(it->name);
665 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
666 + "\r\n";
667 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
668 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000669 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000670 "", 0,
671 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000672 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000673 "", 0,
674 sdp);
675 }
676 }
677
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000678 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
679 const std::string& modified_ice_ufrag,
680 const std::string& modified_ice_pwd,
681 std::string* sdp) {
682 const cricket::SessionDescription* desc = current_desc->description();
683 EXPECT_TRUE(current_desc->ToString(sdp));
684
685 const cricket::ContentInfos& contents = desc->contents();
686 cricket::ContentInfos::const_iterator it = contents.begin();
687 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
688 // |modified_ice_pwd| strings.
689 for (; it != contents.end(); ++it) {
690 const cricket::TransportDescription* transport_desc =
691 desc->GetTransportDescriptionByName(it->name);
692 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
693 + "\r\n";
694 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
695 + "\r\n";
696 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
697 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000698 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000699 mod_ufrag.c_str(), mod_ufrag.length(),
700 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000701 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000702 mod_pwd.c_str(), mod_pwd.length(),
703 sdp);
704 }
705 }
706
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 // Creates a remote offer and and applies it as a remote description,
708 // creates a local answer and applies is as a local description.
709 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
710 // to decide which local and remote streams to create.
711 void CreateAndSetRemoteOfferAndLocalAnswer() {
712 SessionDescriptionInterface* offer = CreateRemoteOffer();
713 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000714 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715 SetLocalDescriptionWithoutError(answer);
716 }
717 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
718 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
719 }
720 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
721 BaseSession::State expected_state) {
722 SetLocalDescriptionWithoutError(desc);
723 EXPECT_EQ(expected_state, session_->state());
724 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000725 void SetLocalDescriptionExpectError(const std::string& action,
726 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727 SessionDescriptionInterface* desc) {
728 std::string error;
729 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000730 std::string sdp_type = "local ";
731 sdp_type.append(action);
732 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733 EXPECT_NE(std::string::npos, error.find(expected_error));
734 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000735 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
736 SessionDescriptionInterface* desc) {
737 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
738 expected_error, desc);
739 }
740 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
741 SessionDescriptionInterface* desc) {
742 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
743 expected_error, desc);
744 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
746 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
747 }
748 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
749 BaseSession::State expected_state) {
750 SetRemoteDescriptionWithoutError(desc);
751 EXPECT_EQ(expected_state, session_->state());
752 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000753 void SetRemoteDescriptionExpectError(const std::string& action,
754 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755 SessionDescriptionInterface* desc) {
756 std::string error;
757 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000758 std::string sdp_type = "remote ";
759 sdp_type.append(action);
760 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 EXPECT_NE(std::string::npos, error.find(expected_error));
762 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000763 void SetRemoteDescriptionOfferExpectError(
764 const std::string& expected_error, SessionDescriptionInterface* desc) {
765 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
766 expected_error, desc);
767 }
768 void SetRemoteDescriptionPranswerExpectError(
769 const std::string& expected_error, SessionDescriptionInterface* desc) {
770 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
771 expected_error, desc);
772 }
773 void SetRemoteDescriptionAnswerExpectError(
774 const std::string& expected_error, SessionDescriptionInterface* desc) {
775 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
776 expected_error, desc);
777 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778
779 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
780 SessionDescriptionInterface** nocrypto_answer) {
781 // Create a SDP without Crypto.
782 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000783 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 options.bundle_enabled = true;
785 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
786 ASSERT_TRUE(*offer != NULL);
787 VerifyCryptoParams((*offer)->description());
788
789 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
790 cricket::SEC_DISABLED);
791 EXPECT_TRUE(*nocrypto_answer != NULL);
792 }
793
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000794 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
795 SessionDescriptionInterface** nodtls_answer) {
796 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000797 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000798 options.bundle_enabled = true;
799
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000800 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000801 CreateRemoteOffer(options, cricket::SEC_ENABLED));
802
803 *nodtls_answer =
804 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
805 EXPECT_TRUE(*nodtls_answer != NULL);
806 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
807 VerifyCryptoParams((*nodtls_answer)->description());
808
809 SetFactoryDtlsSrtp();
810 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
811 ASSERT_TRUE(*offer != NULL);
812 VerifyFingerprintStatus((*offer)->description(), true);
813 VerifyCryptoParams((*offer)->description());
814 }
815
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 JsepSessionDescription* CreateRemoteOfferWithVersion(
817 cricket::MediaSessionOptions options,
818 cricket::SecurePolicy secure_policy,
819 const std::string& session_version,
820 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000821 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 const cricket::SessionDescription* cricket_desc = NULL;
823 if (current_desc) {
824 cricket_desc = current_desc->description();
825 session_id = current_desc->session_id();
826 }
827
828 desc_factory_->set_secure(secure_policy);
829 JsepSessionDescription* offer(
830 new JsepSessionDescription(JsepSessionDescription::kOffer));
831 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
832 session_id, session_version)) {
833 delete offer;
834 offer = NULL;
835 }
836 return offer;
837 }
838 JsepSessionDescription* CreateRemoteOffer(
839 cricket::MediaSessionOptions options) {
840 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
841 kSessionVersion, NULL);
842 }
843 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000844 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
845 return CreateRemoteOfferWithVersion(
846 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 }
848 JsepSessionDescription* CreateRemoteOffer(
849 cricket::MediaSessionOptions options,
850 const SessionDescriptionInterface* current_desc) {
851 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
852 kSessionVersion, current_desc);
853 }
854
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000855 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
856 const char* sctp_stream_name, int new_port,
857 cricket::MediaSessionOptions options) {
858 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000859 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
860 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000861 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
862 }
863
864 // Takes ownership of offer_basis (and deletes it).
865 JsepSessionDescription* ChangeSDPSctpPort(
866 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
867 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
868 // SessionDescription from the mutated string.
869 const char* default_port_str = "5000";
870 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000871 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000872 std::string offer_str;
873 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000874 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000875 new_port_str, strlen(new_port_str),
876 &offer_str);
877 JsepSessionDescription* offer = new JsepSessionDescription(
878 offer_basis->type());
879 delete offer_basis;
880 offer->Initialize(offer_str, NULL);
881 return offer;
882 }
883
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
885 // before this function to decide which streams to create.
886 JsepSessionDescription* CreateRemoteOffer() {
887 cricket::MediaSessionOptions options;
888 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
889 return CreateRemoteOffer(options, session_->remote_description());
890 }
891
892 JsepSessionDescription* CreateRemoteAnswer(
893 const SessionDescriptionInterface* offer,
894 cricket::MediaSessionOptions options,
895 cricket::SecurePolicy policy) {
896 desc_factory_->set_secure(policy);
897 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000898 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 JsepSessionDescription* answer(
900 new JsepSessionDescription(JsepSessionDescription::kAnswer));
901 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
902 options, NULL),
903 session_id, kSessionVersion)) {
904 delete answer;
905 answer = NULL;
906 }
907 return answer;
908 }
909
910 JsepSessionDescription* CreateRemoteAnswer(
911 const SessionDescriptionInterface* offer,
912 cricket::MediaSessionOptions options) {
913 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
914 }
915
916 // Creates an answer session description with streams based on
917 // |mediastream_signaling_|. Call
918 // mediastream_signaling_.UseOptionsWithStreamX() before this function
919 // to decide which streams to create.
920 JsepSessionDescription* CreateRemoteAnswer(
921 const SessionDescriptionInterface* offer) {
922 cricket::MediaSessionOptions options;
923 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
924 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
925 }
926
927 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000928 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000929 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000931
932 PeerConnectionInterface::RTCOfferAnswerOptions options;
933 options.use_rtp_mux = bundle;
934
935 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
937 // and answer.
938 SetLocalDescriptionWithoutError(offer);
939
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000940 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000941 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 std::string sdp;
943 EXPECT_TRUE(answer->ToString(&sdp));
944
945 size_t expected_candidate_num = 2;
946 if (!rtcp_mux) {
947 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
948 // for rtp and rtcp.
949 expected_candidate_num = 4;
950 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 const std::string kRtcpMux = "a=rtcp-mux";
952 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000953 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 kXRtcpMux.c_str(), kXRtcpMux.length(),
955 &sdp);
956 }
957
958 SessionDescriptionInterface* new_answer = CreateSessionDescription(
959 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960
961 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000962 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
964 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
965 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
966 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
967 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
968 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
969 if (bundle) {
970 EXPECT_TRUE(c0.IsEquivalent(c1));
971 } else {
972 EXPECT_FALSE(c0.IsEquivalent(c1));
973 }
974 }
975 }
976 // Tests that we can only send DTMF when the dtmf codec is supported.
977 void TestCanInsertDtmf(bool can) {
978 if (can) {
979 InitWithDtmfCodec();
980 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000981 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 }
983 mediastream_signaling_.SendAudioVideoStream1();
984 CreateAndSetRemoteOfferAndLocalAnswer();
985 EXPECT_FALSE(session_->CanInsertDtmf(""));
986 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
987 }
988
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000989 // Helper class to configure loopback network and verify Best
990 // Connection using right IP protocol for TestLoopbackCall
991 // method. LoopbackNetworkManager applies firewall rules to block
992 // all ping traffic once ICE completed, and remove them to observe
993 // ICE reconnected again. This LoopbackNetworkConfiguration struct
994 // verifies the best connection is using the right IP protocol after
995 // initial ICE convergences.
996
997 class LoopbackNetworkConfiguration {
998 public:
999 LoopbackNetworkConfiguration()
1000 : test_ipv6_network_(false),
1001 test_extra_ipv4_network_(false),
1002 best_connection_after_initial_ice_converged_(1, 0) {}
1003
1004 // Used to track the expected best connection count in each IP protocol.
1005 struct ExpectedBestConnection {
1006 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1007 : ipv4_count_(ipv4_count),
1008 ipv6_count_(ipv6_count) {}
1009
1010 int ipv4_count_;
1011 int ipv6_count_;
1012 };
1013
1014 bool test_ipv6_network_;
1015 bool test_extra_ipv4_network_;
1016 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1017
1018 void VerifyBestConnectionAfterIceConverge(
1019 const FakeMetricsObserver& metrics_observer) const {
1020 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1021 }
1022
1023 private:
1024 void Verify(const FakeMetricsObserver& metrics_observer,
1025 const ExpectedBestConnection& expected) const {
1026 EXPECT_EQ(
1027 metrics_observer
1028 .peer_connection_metrics_counters_[webrtc::kBestConnections_IPv4],
1029 expected.ipv4_count_);
1030 EXPECT_EQ(
1031 metrics_observer
1032 .peer_connection_metrics_counters_[webrtc::kBestConnections_IPv6],
1033 expected.ipv6_count_);
1034 }
1035 };
1036
1037 class LoopbackNetworkManager {
1038 public:
1039 LoopbackNetworkManager(WebRtcSessionTest* session,
1040 const LoopbackNetworkConfiguration& config)
1041 : config_(config) {
1042 session->AddInterface(
1043 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1044 if (config_.test_extra_ipv4_network_) {
1045 session->AddInterface(
1046 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1047 }
1048 if (config_.test_ipv6_network_) {
1049 session->AddInterface(
1050 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1051 }
1052 }
1053
1054 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1055 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1056 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1057 if (config_.test_extra_ipv4_network_) {
1058 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1059 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1060 }
1061 if (config_.test_ipv6_network_) {
1062 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1063 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1064 }
1065 }
1066
1067 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1068
1069 private:
1070 LoopbackNetworkConfiguration config_;
1071 };
1072
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073 // The method sets up a call from the session to itself, in a loopback
1074 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001075 // disconnection, and then a permanent disconnection.
1076 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001077 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1078 // While running the call, this method also checks if the session goes through
1079 // the correct sequence of ICE states when a connection is established,
1080 // broken, and re-established.
1081 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001082 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1083 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001085
1086 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1087 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001088 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001090 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001091
1092 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1093 observer_.ice_gathering_state_);
1094 SetLocalDescriptionWithoutError(offer);
1095 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1096 observer_.ice_connection_state_);
1097 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1098 observer_.ice_gathering_state_,
1099 kIceCandidatesTimeout);
1100 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1101 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1102 observer_.ice_gathering_state_,
1103 kIceCandidatesTimeout);
1104
1105 std::string sdp;
1106 offer->ToString(&sdp);
1107 SessionDescriptionInterface* desc =
1108 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
1109 ASSERT_TRUE(desc != NULL);
1110 SetRemoteDescriptionWithoutError(desc);
1111
1112 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1113 observer_.ice_connection_state_,
1114 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001115
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001116 // The ice connection state is "Connected" too briefly to catch in a test.
1117 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001118 observer_.ice_connection_state_,
1119 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001120
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001121 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001122 // Adding firewall rule to block ping requests, which should cause
1123 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001124
1125 loopback_network_manager.ApplyFirewallRules(fss_.get());
1126
1127 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001128 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1129 observer_.ice_connection_state_,
1130 kIceCandidatesTimeout);
1131
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001132 metrics_observer_.Reset();
1133
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001135 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136 // Session is automatically calling OnSignalingReady after creation of
1137 // new portallocator session which will allocate new set of candidates.
1138
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001139 LOG(LS_INFO) << "Firewall Rules cleared";
1140
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001141 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142 observer_.ice_connection_state_,
1143 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001144
1145 // Now we block ping requests and wait until the ICE connection transitions
1146 // to the Failed state. This will take at least 30 seconds because it must
1147 // wait for the Port to timeout.
1148 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001149
1150 loopback_network_manager.ApplyFirewallRules(fss_.get());
1151 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001152 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001153 observer_.ice_connection_state_,
1154 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001155 }
1156
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001157 void TestLoopbackCall() {
1158 LoopbackNetworkConfiguration config;
1159 TestLoopbackCall(config);
1160 }
1161
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001162 void VerifyTransportType(const std::string& content_name,
1163 cricket::TransportProtocol protocol) {
1164 const cricket::Transport* transport = session_->GetTransport(content_name);
1165 ASSERT_TRUE(transport != NULL);
1166 EXPECT_EQ(protocol, transport->protocol());
1167 }
1168
1169 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1170 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001171 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1172 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1173
1174 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001175 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1176 codecs.push_back(kCNCodec1);
1177 codecs.push_back(kCNCodec2);
1178 media_engine_->SetAudioCodecs(codecs);
1179 desc_factory_->set_audio_codecs(codecs);
1180 }
1181
1182 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1183 const cricket::ContentDescription* description = content->description;
1184 ASSERT(description != NULL);
1185 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001186 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001187 ASSERT(audio_content_desc != NULL);
1188 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1189 if (audio_content_desc->codecs()[i].name == "CN")
1190 return false;
1191 }
1192 return true;
1193 }
1194
1195 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001196 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001197 dci.reliable = false;
1198 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001199 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001200 SetLocalDescriptionWithoutError(offer);
1201 }
1202
wu@webrtc.org91053e72013-08-10 07:18:04 +00001203 void VerifyMultipleAsyncCreateDescription(
1204 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001205 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001206 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001207 if (type == CreateSessionDescriptionRequest::kAnswer) {
1208 cricket::MediaSessionOptions options;
1209 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001210 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001211 ASSERT_TRUE(offer.get() != NULL);
1212 SetRemoteDescriptionWithoutError(offer.release());
1213 }
1214
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001215 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001216 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001217 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001218 observers[kNumber];
1219 for (int i = 0; i < kNumber; ++i) {
1220 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1221 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001222 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001223 } else {
1224 session_->CreateAnswer(observers[i], NULL);
1225 }
1226 }
1227
1228 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1229 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1230 WebRtcSessionCreateSDPObserverForTest::kFailed;
1231
1232 for (int i = 0; i < kNumber; ++i) {
1233 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1234 if (success) {
1235 EXPECT_TRUE(observers[i]->description() != NULL);
1236 } else {
1237 EXPECT_TRUE(observers[i]->description() == NULL);
1238 }
1239 }
1240 }
1241
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001242 void ConfigureAllocatorWithTurn() {
1243 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1244 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1245 relay_server.credentials = credentials;
1246 relay_server.ports.push_back(cricket::ProtocolAddress(
1247 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1248 allocator_->AddRelay(relay_server);
1249 allocator_->set_step_delay(cricket::kMinimumStepDelay);
1250 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
jiayl@webrtc.orgdacdd942015-01-23 17:33:34 +00001251 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
1252 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001253 }
1254
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255 cricket::FakeMediaEngine* media_engine_;
1256 cricket::FakeDataEngine* data_engine_;
1257 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001258 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1259 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1260 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1261 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1262 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1263 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1264 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1265 rtc::SocketServerScope ss_scope_;
1266 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001267 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001268 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001269 rtc::FakeNetworkManager network_manager_;
1270 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001271 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001272 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001274 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 MockIceObserver observer_;
1276 cricket::FakeVideoMediaChannel* video_channel_;
1277 cricket::FakeVoiceMediaChannel* voice_channel_;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001278 FakeMetricsObserver metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001279};
1280
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001281TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1282 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001283 // SDES is disabled when DTLS is on.
1284 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001285}
1286
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001287TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001288 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001289 // SDES is required if DTLS is off.
1290 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001291}
1292
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001293TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1294 TestSessionCandidatesWithBundleRtcpMux(false, false);
1295}
1296
1297// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1298// with rtcp-mux and/or bundle.
1299TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1300 TestSessionCandidatesWithBundleRtcpMux(false, true);
1301}
1302
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001303TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1304 TestSessionCandidatesWithBundleRtcpMux(true, true);
1305}
1306
1307TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001308 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1309 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001310 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001311 mediastream_signaling_.SendAudioVideoStream1();
1312 InitiateCall();
1313 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1314 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1315 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1316}
1317
1318TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001319 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1320 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001321 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001322 rtc::FP_UDP,
1323 rtc::FD_ANY,
1324 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001325 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326 mediastream_signaling_.SendAudioVideoStream1();
1327 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001328 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1330 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1331 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1332}
1333
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001334// Test session delivers no candidates gathered when constraint set to "none".
1335TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1336 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001337 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001338 mediastream_signaling_.SendAudioVideoStream1();
1339 InitiateCall();
1340 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1341 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1342 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1343}
1344
1345// Test session delivers only relay candidates gathered when constaint set to
1346// "relay".
1347TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1348 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1349 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001350 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001351 mediastream_signaling_.SendAudioVideoStream1();
1352 InitiateCall();
1353 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1354 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1355 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1356 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1357 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1358 observer_.mline_0_candidates_[i].type());
1359 }
1360 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1361 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1362 observer_.mline_1_candidates_[i].type());
1363 }
1364}
1365
1366// Test session delivers all candidates gathered when constaint set to "all".
1367TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1368 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001369 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001370 mediastream_signaling_.SendAudioVideoStream1();
1371 InitiateCall();
1372 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1373 // Host + STUN. By default allocator is disabled to gather relay candidates.
1374 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1375 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1376}
1377
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001378TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001379 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001380 SessionDescriptionInterface* offer = NULL;
1381 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1382 std::string unknown_action;
1383 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1384 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1385}
1386
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001387// Test creating offers and receive answers and make sure the
1388// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001389TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001390 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001391 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001392 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001393 const std::string session_id_orig = offer->session_id();
1394 const std::string session_version_orig = offer->session_version();
1395 SetLocalDescriptionWithoutError(offer);
1396
1397 mediastream_signaling_.SendAudioVideoStream2();
1398 SessionDescriptionInterface* answer =
1399 CreateRemoteAnswer(session_->local_description());
1400 SetRemoteDescriptionWithoutError(answer);
1401
1402 video_channel_ = media_engine_->GetVideoChannel(0);
1403 voice_channel_ = media_engine_->GetVoiceChannel(0);
1404
1405 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1406 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1407
1408 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1409 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1410
1411 ASSERT_EQ(1u, video_channel_->send_streams().size());
1412 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1413 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1414 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1415
1416 // Create new offer without send streams.
1417 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001418 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001419
1420 // Verify the session id is the same and the session version is
1421 // increased.
1422 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001423 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1424 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001425
1426 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001427 EXPECT_EQ(0u, video_channel_->send_streams().size());
1428 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001429
1430 mediastream_signaling_.SendAudioVideoStream2();
1431 answer = CreateRemoteAnswer(session_->local_description());
1432 SetRemoteDescriptionWithoutError(answer);
1433
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001434 // Make sure the receive streams have not changed.
1435 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1436 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1437 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1438 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1439}
1440
1441// Test receiving offers and creating answers and make sure the
1442// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001443TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001444 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001445 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001446 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001447 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448 SetRemoteDescriptionWithoutError(offer);
1449
1450 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001451 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001452 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001453 SetLocalDescriptionWithoutError(answer);
1454
1455 const std::string session_id_orig = answer->session_id();
1456 const std::string session_version_orig = answer->session_version();
1457
1458 video_channel_ = media_engine_->GetVideoChannel(0);
1459 voice_channel_ = media_engine_->GetVoiceChannel(0);
1460
1461 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1462 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1463
1464 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1465 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1466
1467 ASSERT_EQ(1u, video_channel_->send_streams().size());
1468 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1469 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1470 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1471
1472 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001473 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474 SetRemoteDescriptionWithoutError(offer);
1475
1476 // Answer by turning off all send streams.
1477 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001478 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001479
1480 // Verify the session id is the same and the session version is
1481 // increased.
1482 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001483 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1484 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001485 SetLocalDescriptionWithoutError(answer);
1486
1487 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1488 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1489 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1490 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1491 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1492 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1493
1494 // Make sure we have no send streams.
1495 EXPECT_EQ(0u, video_channel_->send_streams().size());
1496 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1497}
1498
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001499TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001500 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001501 media_engine_->set_fail_create_channel(true);
1502
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001503 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001504 ASSERT_TRUE(offer != NULL);
1505 // SetRemoteDescription and SetLocalDescription will take the ownership of
1506 // the offer.
1507 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001508 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001509 ASSERT_TRUE(offer != NULL);
1510 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1511}
1512
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001513//
1514// Tests for creating/setting SDP under different SDES/DTLS polices:
1515//
1516// --DTLS off and SDES on
1517// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1518// set local/remote offer/answer with crypto --> success
1519// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1520// failure
1521// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1522// failure
1523// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1524// failure
1525//
1526// --DTLS on and SDES off
1527// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1528// set local/remote offer/answer with DTLS fingerprint --> success
1529// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1530// fingerprint --> failure
1531// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1532// --> failure
1533// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1534// --> failure
1535//
1536// --Encryption disabled: DTLS off and SDES off
1537// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1538// answer without SDES or DTLS --> success
1539// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1540// answer without SDES or DTLS --> success
1541//
1542
1543// Test that we return a failure when applying a remote/local offer that doesn't
1544// have cryptos enabled when DTLS is off.
1545TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001546 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001548 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001549 JsepSessionDescription* offer = CreateRemoteOffer(
1550 options, cricket::SEC_DISABLED);
1551 ASSERT_TRUE(offer != NULL);
1552 VerifyNoCryptoParams(offer->description(), false);
1553 // SetRemoteDescription and SetLocalDescription will take the ownership of
1554 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001555 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1557 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001558 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559}
1560
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001561// Test that we return a failure when applying a local answer that doesn't have
1562// cryptos enabled when DTLS is off.
1563TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001564 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565 SessionDescriptionInterface* offer = NULL;
1566 SessionDescriptionInterface* answer = NULL;
1567 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1568 // SetRemoteDescription and SetLocalDescription will take the ownership of
1569 // the offer.
1570 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001571 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572}
1573
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001574// Test we will return fail when apply an remote answer that doesn't have
1575// crypto enabled when DTLS is off.
1576TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001577 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578 SessionDescriptionInterface* offer = NULL;
1579 SessionDescriptionInterface* answer = NULL;
1580 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1581 // SetRemoteDescription and SetLocalDescription will take the ownership of
1582 // the offer.
1583 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001584 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585}
1586
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001587// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1588// and that we return an answer with a DTLS fingerprint.
1589TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001590 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592 InitWithDtls();
1593 SetFactoryDtlsSrtp();
1594 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001595 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001596 JsepSessionDescription* offer =
1597 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 ASSERT_TRUE(offer != NULL);
1599 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001600 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601
1602 // SetRemoteDescription will take the ownership of the offer.
1603 SetRemoteDescriptionWithoutError(offer);
1604
1605 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001606 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 ASSERT_TRUE(answer != NULL);
1608 VerifyFingerprintStatus(answer->description(), true);
1609 // Check that we don't have an a=crypto line in the answer.
1610 VerifyNoCryptoParams(answer->description(), true);
1611
1612 // Now set the local description, which should work, even without a=crypto.
1613 SetLocalDescriptionWithoutError(answer);
1614}
1615
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001616// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1617// and then we accept a remote answer with a DTLS fingerprint successfully.
1618TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001619 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001620 mediastream_signaling_.SendAudioVideoStream1();
1621 InitWithDtls();
1622 SetFactoryDtlsSrtp();
1623
1624 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001625 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001626 ASSERT_TRUE(offer != NULL);
1627 VerifyFingerprintStatus(offer->description(), true);
1628 // Check that we don't have an a=crypto line in the offer.
1629 VerifyNoCryptoParams(offer->description(), true);
1630
1631 // Now set the local description, which should work, even without a=crypto.
1632 SetLocalDescriptionWithoutError(offer);
1633
1634 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001635 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001636 JsepSessionDescription* answer =
1637 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1638 ASSERT_TRUE(answer != NULL);
1639 VerifyFingerprintStatus(answer->description(), true);
1640 VerifyNoCryptoParams(answer->description(), true);
1641
1642 // SetRemoteDescription will take the ownership of the answer.
1643 SetRemoteDescriptionWithoutError(answer);
1644}
1645
1646// Test that if we support DTLS and the other side didn't offer a fingerprint,
1647// we will fail to set the remote description.
1648TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001649 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650 InitWithDtls();
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 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 JsepSessionDescription* offer = CreateRemoteOffer(
1655 options, cricket::SEC_REQUIRED);
1656 ASSERT_TRUE(offer != NULL);
1657 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001658 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001660 // SetRemoteDescription will take the ownership of the offer.
1661 SetRemoteDescriptionOfferExpectError(
1662 kSdpWithoutDtlsFingerprint, offer);
1663
1664 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1665 // SetLocalDescription will take the ownership of the offer.
1666 SetLocalDescriptionOfferExpectError(
1667 kSdpWithoutDtlsFingerprint, offer);
1668}
1669
1670// Test that we return a failure when applying a local answer that doesn't have
1671// a DTLS fingerprint when DTLS is required.
1672TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001673 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001674 InitWithDtls();
1675 SessionDescriptionInterface* offer = NULL;
1676 SessionDescriptionInterface* answer = NULL;
1677 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1678
1679 // SetRemoteDescription and SetLocalDescription will take the ownership of
1680 // the offer and answer.
1681 SetRemoteDescriptionWithoutError(offer);
1682 SetLocalDescriptionAnswerExpectError(
1683 kSdpWithoutDtlsFingerprint, answer);
1684}
1685
1686// Test that we return a failure when applying a remote answer that doesn't have
1687// a DTLS fingerprint when DTLS is required.
1688TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001689 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001690 InitWithDtls();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001691 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001692 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001693 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001694 JsepSessionDescription* answer =
1695 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1696
1697 // SetRemoteDescription and SetLocalDescription will take the ownership of
1698 // the offer and answer.
1699 SetLocalDescriptionWithoutError(offer);
1700 SetRemoteDescriptionAnswerExpectError(
1701 kSdpWithoutDtlsFingerprint, answer);
1702}
1703
1704// Test that we create a local offer without SDES or DTLS and accept a remote
1705// answer without SDES or DTLS when encryption is disabled.
1706TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1707 mediastream_signaling_.SendAudioVideoStream1();
1708 options_.disable_encryption = true;
1709 InitWithDtls();
1710
1711 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001712 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001713 ASSERT_TRUE(offer != NULL);
1714 VerifyFingerprintStatus(offer->description(), false);
1715 // Check that we don't have an a=crypto line in the offer.
1716 VerifyNoCryptoParams(offer->description(), false);
1717
1718 // Now set the local description, which should work, even without a=crypto.
1719 SetLocalDescriptionWithoutError(offer);
1720
1721 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001722 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001723 JsepSessionDescription* answer =
1724 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1725 ASSERT_TRUE(answer != NULL);
1726 VerifyFingerprintStatus(answer->description(), false);
1727 VerifyNoCryptoParams(answer->description(), false);
1728
1729 // SetRemoteDescription will take the ownership of the answer.
1730 SetRemoteDescriptionWithoutError(answer);
1731}
1732
1733// Test that we create a local answer without SDES or DTLS and accept a remote
1734// offer without SDES or DTLS when encryption is disabled.
1735TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1736 options_.disable_encryption = true;
1737 InitWithDtls();
1738
1739 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001740 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001741 JsepSessionDescription* offer =
1742 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1743 ASSERT_TRUE(offer != NULL);
1744 VerifyFingerprintStatus(offer->description(), false);
1745 VerifyNoCryptoParams(offer->description(), false);
1746
1747 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 SetRemoteDescriptionWithoutError(offer);
1749
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001750 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001751 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 ASSERT_TRUE(answer != NULL);
1753 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001754 // Check that we don't have an a=crypto line in the answer.
1755 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001757 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 SetLocalDescriptionWithoutError(answer);
1759}
1760
1761TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001762 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 mediastream_signaling_.SendNothing();
1764 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001765 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 SetLocalDescriptionWithoutError(offer);
1767
1768 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001769 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770 SetLocalDescriptionWithoutError(offer2);
1771}
1772
1773TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001774 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 mediastream_signaling_.SendNothing();
1776 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001777 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 SetRemoteDescriptionWithoutError(offer);
1779
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001780 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 SetRemoteDescriptionWithoutError(offer2);
1782}
1783
1784TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001785 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001787 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001789 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001790 SetRemoteDescriptionOfferExpectError(
1791 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792}
1793
1794TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001795 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001797 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001799 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001800 SetLocalDescriptionOfferExpectError(
1801 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802}
1803
1804TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001805 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806 mediastream_signaling_.SendNothing();
1807 SessionDescriptionInterface* offer = CreateRemoteOffer();
1808 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1809
1810 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001811 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1813 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1814
1815 mediastream_signaling_.SendAudioVideoStream1();
1816 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001817 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1819
1820 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1821
1822 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001823 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1825}
1826
1827TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001828 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001830 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1832
1833 JsepSessionDescription* pranswer =
1834 CreateRemoteAnswer(session_->local_description());
1835 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1836
1837 SetRemoteDescriptionExpectState(pranswer,
1838 BaseSession::STATE_RECEIVEDPRACCEPT);
1839
1840 mediastream_signaling_.SendAudioVideoStream1();
1841 JsepSessionDescription* pranswer2 =
1842 CreateRemoteAnswer(session_->local_description());
1843 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1844
1845 SetRemoteDescriptionExpectState(pranswer2,
1846 BaseSession::STATE_RECEIVEDPRACCEPT);
1847
1848 mediastream_signaling_.SendAudioVideoStream2();
1849 SessionDescriptionInterface* answer =
1850 CreateRemoteAnswer(session_->local_description());
1851 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1852}
1853
1854TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001855 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001857 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1858
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 SessionDescriptionInterface* answer =
1860 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001861 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1862 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863}
1864
1865TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001866 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001868 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1869
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001870 SessionDescriptionInterface* answer =
1871 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001872 SetRemoteDescriptionAnswerExpectError(
1873 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001874}
1875
1876TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001877 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001878 mediastream_signaling_.SendAudioVideoStream1();
1879
1880 cricket::Candidate candidate;
1881 candidate.set_component(1);
1882 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1883
1884 // Fail since we have not set a offer description.
1885 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1886
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001887 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001888 SetLocalDescriptionWithoutError(offer);
1889 // Candidate should be allowed to add before remote description.
1890 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1891 candidate.set_component(2);
1892 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1893 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1894
1895 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1896 session_->local_description());
1897 SetRemoteDescriptionWithoutError(answer);
1898
1899 // Verifying the candidates are copied properly from internal vector.
1900 const SessionDescriptionInterface* remote_desc =
1901 session_->remote_description();
1902 ASSERT_TRUE(remote_desc != NULL);
1903 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1904 const IceCandidateCollection* candidates =
1905 remote_desc->candidates(kMediaContentIndex0);
1906 ASSERT_EQ(2u, candidates->count());
1907 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1908 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1909 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1910 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1911
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001912 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1913 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914 candidate.set_component(2);
1915 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1916 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001917 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001918
1919 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1920 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1921}
1922
1923// Test that a remote candidate is added to the remote session description and
1924// that it is retained if the remote session description is changed.
1925TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001926 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927 cricket::Candidate candidate1;
1928 candidate1.set_component(1);
1929 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1930 candidate1);
1931 mediastream_signaling_.SendAudioVideoStream1();
1932 CreateAndSetRemoteOfferAndLocalAnswer();
1933
1934 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1935 const SessionDescriptionInterface* remote_desc =
1936 session_->remote_description();
1937 ASSERT_TRUE(remote_desc != NULL);
1938 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1939 const IceCandidateCollection* candidates =
1940 remote_desc->candidates(kMediaContentIndex0);
1941 ASSERT_EQ(1u, candidates->count());
1942 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1943
1944 // Update the RemoteSessionDescription with a new session description and
1945 // a candidate and check that the new remote session description contains both
1946 // candidates.
1947 SessionDescriptionInterface* offer = CreateRemoteOffer();
1948 cricket::Candidate candidate2;
1949 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1950 candidate2);
1951 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1952 SetRemoteDescriptionWithoutError(offer);
1953
1954 remote_desc = session_->remote_description();
1955 ASSERT_TRUE(remote_desc != NULL);
1956 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1957 candidates = remote_desc->candidates(kMediaContentIndex0);
1958 ASSERT_EQ(2u, candidates->count());
1959 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1960 // Username and password have be updated with the TransportInfo of the
1961 // SessionDescription, won't be equal to the original one.
1962 candidate2.set_username(candidates->at(0)->candidate().username());
1963 candidate2.set_password(candidates->at(0)->candidate().password());
1964 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1965 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1966 // No need to verify the username and password.
1967 candidate1.set_username(candidates->at(1)->candidate().username());
1968 candidate1.set_password(candidates->at(1)->candidate().password());
1969 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1970
1971 // Test that the candidate is ignored if we can add the same candidate again.
1972 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1973}
1974
1975// Test that local candidates are added to the local session description and
1976// that they are retained if the local session description is changed.
1977TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001978 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001979 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 mediastream_signaling_.SendAudioVideoStream1();
1981 CreateAndSetRemoteOfferAndLocalAnswer();
1982
1983 const SessionDescriptionInterface* local_desc = session_->local_description();
1984 const IceCandidateCollection* candidates =
1985 local_desc->candidates(kMediaContentIndex0);
1986 ASSERT_TRUE(candidates != NULL);
1987 EXPECT_EQ(0u, candidates->count());
1988
1989 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1990
1991 local_desc = session_->local_description();
1992 candidates = local_desc->candidates(kMediaContentIndex0);
1993 ASSERT_TRUE(candidates != NULL);
1994 EXPECT_LT(0u, candidates->count());
1995 candidates = local_desc->candidates(1);
1996 ASSERT_TRUE(candidates != NULL);
1997 EXPECT_LT(0u, candidates->count());
1998
1999 // Update the session descriptions.
2000 mediastream_signaling_.SendAudioVideoStream1();
2001 CreateAndSetRemoteOfferAndLocalAnswer();
2002
2003 local_desc = session_->local_description();
2004 candidates = local_desc->candidates(kMediaContentIndex0);
2005 ASSERT_TRUE(candidates != NULL);
2006 EXPECT_LT(0u, candidates->count());
2007 candidates = local_desc->candidates(1);
2008 ASSERT_TRUE(candidates != NULL);
2009 EXPECT_LT(0u, candidates->count());
2010}
2011
2012// Test that we can set a remote session description with remote candidates.
2013TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002014 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015
2016 cricket::Candidate candidate1;
2017 candidate1.set_component(1);
2018 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2019 candidate1);
2020 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002021 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022
2023 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2024 SetRemoteDescriptionWithoutError(offer);
2025
2026 const SessionDescriptionInterface* remote_desc =
2027 session_->remote_description();
2028 ASSERT_TRUE(remote_desc != NULL);
2029 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2030 const IceCandidateCollection* candidates =
2031 remote_desc->candidates(kMediaContentIndex0);
2032 ASSERT_EQ(1u, candidates->count());
2033 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2034
wu@webrtc.org91053e72013-08-10 07:18:04 +00002035 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036 SetLocalDescriptionWithoutError(answer);
2037}
2038
2039// Test that offers and answers contains ice candidates when Ice candidates have
2040// been gathered.
2041TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002042 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002043 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044 mediastream_signaling_.SendAudioVideoStream1();
2045 // Ice is started but candidates are not provided until SetLocalDescription
2046 // is called.
2047 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2048 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2049 CreateAndSetRemoteOfferAndLocalAnswer();
2050 // Wait until at least one local candidate has been collected.
2051 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2052 kIceCandidatesTimeout);
2053 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
2054 kIceCandidatesTimeout);
2055
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002056 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2057
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2059 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2060 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
2061 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
2062
2063 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2064 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002065 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002066 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2067 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2068 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
2069 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
2070 SetLocalDescriptionWithoutError(answer);
2071}
2072
2073// Verifies TransportProxy and media channels are created with content names
2074// present in the SessionDescription.
2075TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002076 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002078 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079
2080 // CreateOffer creates session description with the content names "audio" and
2081 // "video". Goal is to modify these content names and verify transport channel
2082 // proxy in the BaseSession, as proxies are created with the content names
2083 // present in SDP.
2084 std::string sdp;
2085 EXPECT_TRUE(offer->ToString(&sdp));
2086 const std::string kAudioMid = "a=mid:audio";
2087 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2088 const std::string kVideoMid = "a=mid:video";
2089 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2090
2091 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002092 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093 kAudioMidReplaceStr.c_str(),
2094 kAudioMidReplaceStr.length(),
2095 &sdp);
2096 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002097 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098 kVideoMidReplaceStr.c_str(),
2099 kVideoMidReplaceStr.length(),
2100 &sdp);
2101
2102 SessionDescriptionInterface* modified_offer =
2103 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2104
2105 SetRemoteDescriptionWithoutError(modified_offer);
2106
2107 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002108 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109 SetLocalDescriptionWithoutError(answer);
2110
2111 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
2112 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
2113 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2114 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2115}
2116
2117// Test that an offer contains the correct media content descriptions based on
2118// the send streams when no constraints have been set.
2119TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002120 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002121 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2122
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123 ASSERT_TRUE(offer != NULL);
2124 const cricket::ContentInfo* content =
2125 cricket::GetFirstAudioContent(offer->description());
2126 EXPECT_TRUE(content != NULL);
2127 content = cricket::GetFirstVideoContent(offer->description());
2128 EXPECT_TRUE(content == NULL);
2129}
2130
2131// Test that an offer contains the correct media content descriptions based on
2132// the send streams when no constraints have been set.
2133TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002134 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 // Test Audio only offer.
2136 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002137 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2138
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139 const cricket::ContentInfo* content =
2140 cricket::GetFirstAudioContent(offer->description());
2141 EXPECT_TRUE(content != NULL);
2142 content = cricket::GetFirstVideoContent(offer->description());
2143 EXPECT_TRUE(content == NULL);
2144
2145 // Test Audio / Video offer.
2146 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002147 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148 content = cricket::GetFirstAudioContent(offer->description());
2149 EXPECT_TRUE(content != NULL);
2150 content = cricket::GetFirstVideoContent(offer->description());
2151 EXPECT_TRUE(content != NULL);
2152}
2153
2154// Test that an offer contains no media content descriptions if
2155// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2156TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002157 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002158 PeerConnectionInterface::RTCOfferAnswerOptions options;
2159 options.offer_to_receive_audio = 0;
2160 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002162 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002163 CreateOffer(options));
2164
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165 ASSERT_TRUE(offer != NULL);
2166 const cricket::ContentInfo* content =
2167 cricket::GetFirstAudioContent(offer->description());
2168 EXPECT_TRUE(content == NULL);
2169 content = cricket::GetFirstVideoContent(offer->description());
2170 EXPECT_TRUE(content == NULL);
2171}
2172
2173// Test that an offer contains only audio media content descriptions if
2174// kOfferToReceiveAudio constraints are set to true.
2175TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002176 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002177 PeerConnectionInterface::RTCOfferAnswerOptions options;
2178 options.offer_to_receive_audio =
2179 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2180
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002181 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002182 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183
2184 const cricket::ContentInfo* content =
2185 cricket::GetFirstAudioContent(offer->description());
2186 EXPECT_TRUE(content != NULL);
2187 content = cricket::GetFirstVideoContent(offer->description());
2188 EXPECT_TRUE(content == NULL);
2189}
2190
2191// Test that an offer contains audio and video media content descriptions if
2192// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2193TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002194 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002195 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002196 PeerConnectionInterface::RTCOfferAnswerOptions options;
2197 options.offer_to_receive_audio =
2198 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2199 options.offer_to_receive_video =
2200 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2201
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002202 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002203 CreateOffer(options));
2204
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002205 const cricket::ContentInfo* content =
2206 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002207 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002208
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002209 content = cricket::GetFirstVideoContent(offer->description());
2210 EXPECT_TRUE(content != NULL);
2211
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002212 // Sets constraints to false and verifies that audio/video contents are
2213 // removed.
2214 options.offer_to_receive_audio = 0;
2215 options.offer_to_receive_video = 0;
2216 offer.reset(CreateOffer(options));
2217
2218 content = cricket::GetFirstAudioContent(offer->description());
2219 EXPECT_TRUE(content == NULL);
2220 content = cricket::GetFirstVideoContent(offer->description());
2221 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002222}
2223
2224// Test that an answer can not be created if the last remote description is not
2225// an offer.
2226TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002227 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002228 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229 SetLocalDescriptionWithoutError(offer);
2230 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2231 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002232 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233}
2234
2235// Test that an answer contains the correct media content descriptions when no
2236// constraints have been set.
2237TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002238 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002240 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002241 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002242 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002243 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002244 const cricket::ContentInfo* content =
2245 cricket::GetFirstAudioContent(answer->description());
2246 ASSERT_TRUE(content != NULL);
2247 EXPECT_FALSE(content->rejected);
2248
2249 content = cricket::GetFirstVideoContent(answer->description());
2250 ASSERT_TRUE(content != NULL);
2251 EXPECT_FALSE(content->rejected);
2252}
2253
2254// Test that an answer contains the correct media content descriptions when no
2255// constraints have been set and the offer only contain audio.
2256TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002257 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002258 // Create a remote offer with audio only.
2259 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002260
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002261 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 CreateRemoteOffer(options));
2263 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2264 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2265
2266 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002267 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002268 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269 const cricket::ContentInfo* content =
2270 cricket::GetFirstAudioContent(answer->description());
2271 ASSERT_TRUE(content != NULL);
2272 EXPECT_FALSE(content->rejected);
2273
2274 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2275}
2276
2277// Test that an answer contains the correct media content descriptions when no
2278// constraints have been set.
2279TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002280 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002282 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 SetRemoteDescriptionWithoutError(offer.release());
2284 // Test with a stream with tracks.
2285 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002286 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002287 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288 const cricket::ContentInfo* content =
2289 cricket::GetFirstAudioContent(answer->description());
2290 ASSERT_TRUE(content != NULL);
2291 EXPECT_FALSE(content->rejected);
2292
2293 content = cricket::GetFirstVideoContent(answer->description());
2294 ASSERT_TRUE(content != NULL);
2295 EXPECT_FALSE(content->rejected);
2296}
2297
2298// Test that an answer contains the correct media content descriptions when
2299// constraints have been set but no stream is sent.
2300TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002301 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002303 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002304 SetRemoteDescriptionWithoutError(offer.release());
2305
2306 webrtc::FakeConstraints constraints_no_receive;
2307 constraints_no_receive.SetMandatoryReceiveAudio(false);
2308 constraints_no_receive.SetMandatoryReceiveVideo(false);
2309
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002310 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002311 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002312 const cricket::ContentInfo* content =
2313 cricket::GetFirstAudioContent(answer->description());
2314 ASSERT_TRUE(content != NULL);
2315 EXPECT_TRUE(content->rejected);
2316
2317 content = cricket::GetFirstVideoContent(answer->description());
2318 ASSERT_TRUE(content != NULL);
2319 EXPECT_TRUE(content->rejected);
2320}
2321
2322// Test that an answer contains the correct media content descriptions when
2323// constraints have been set and streams are sent.
2324TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002325 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002327 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328 SetRemoteDescriptionWithoutError(offer.release());
2329
2330 webrtc::FakeConstraints constraints_no_receive;
2331 constraints_no_receive.SetMandatoryReceiveAudio(false);
2332 constraints_no_receive.SetMandatoryReceiveVideo(false);
2333
2334 // Test with a stream with tracks.
2335 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002336 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002337 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338
2339 // TODO(perkj): Should the direction be set to SEND_ONLY?
2340 const cricket::ContentInfo* content =
2341 cricket::GetFirstAudioContent(answer->description());
2342 ASSERT_TRUE(content != NULL);
2343 EXPECT_FALSE(content->rejected);
2344
2345 // TODO(perkj): Should the direction be set to SEND_ONLY?
2346 content = cricket::GetFirstVideoContent(answer->description());
2347 ASSERT_TRUE(content != NULL);
2348 EXPECT_FALSE(content->rejected);
2349}
2350
2351TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2352 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002353 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002354 PeerConnectionInterface::RTCOfferAnswerOptions options;
2355 options.offer_to_receive_audio =
2356 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2357 options.voice_activity_detection = false;
2358
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002359 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002360 CreateOffer(options));
2361
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362 const cricket::ContentInfo* content =
2363 cricket::GetFirstAudioContent(offer->description());
2364 EXPECT_TRUE(content != NULL);
2365 EXPECT_TRUE(VerifyNoCNCodecs(content));
2366}
2367
2368TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2369 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002370 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002372 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373 SetRemoteDescriptionWithoutError(offer.release());
2374
2375 webrtc::FakeConstraints constraints;
2376 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002377 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002378 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379 const cricket::ContentInfo* content =
2380 cricket::GetFirstAudioContent(answer->description());
2381 ASSERT_TRUE(content != NULL);
2382 EXPECT_TRUE(VerifyNoCNCodecs(content));
2383}
2384
2385// This test verifies the call setup when remote answer with audio only and
2386// later updates with video.
2387TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002388 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2390 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2391
2392 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002393 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394
2395 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2397
2398 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2399 // and answer;
2400 SetLocalDescriptionWithoutError(offer);
2401 SetRemoteDescriptionWithoutError(answer);
2402
2403 video_channel_ = media_engine_->GetVideoChannel(0);
2404 voice_channel_ = media_engine_->GetVoiceChannel(0);
2405
2406 ASSERT_TRUE(video_channel_ == NULL);
2407
2408 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2409 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2410 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2411
2412 // Let the remote end update the session descriptions, with Audio and Video.
2413 mediastream_signaling_.SendAudioVideoStream2();
2414 CreateAndSetRemoteOfferAndLocalAnswer();
2415
2416 video_channel_ = media_engine_->GetVideoChannel(0);
2417 voice_channel_ = media_engine_->GetVoiceChannel(0);
2418
2419 ASSERT_TRUE(video_channel_ != NULL);
2420 ASSERT_TRUE(voice_channel_ != NULL);
2421
2422 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2423 ASSERT_EQ(1u, video_channel_->send_streams().size());
2424 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2425 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2426 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2427 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2428 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2429 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2430
2431 // Change session back to audio only.
2432 mediastream_signaling_.UseOptionsAudioOnly();
2433 CreateAndSetRemoteOfferAndLocalAnswer();
2434
2435 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2436 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2437 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2438 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2439 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2440}
2441
2442// This test verifies the call setup when remote answer with video only and
2443// later updates with audio.
2444TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002445 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002446 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2447 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2448 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002449 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002450
2451 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002452 options.recv_audio = false;
2453 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002454 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2455 offer, options, cricket::SEC_ENABLED);
2456
2457 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2458 // and answer.
2459 SetLocalDescriptionWithoutError(offer);
2460 SetRemoteDescriptionWithoutError(answer);
2461
2462 video_channel_ = media_engine_->GetVideoChannel(0);
2463 voice_channel_ = media_engine_->GetVoiceChannel(0);
2464
2465 ASSERT_TRUE(voice_channel_ == NULL);
2466 ASSERT_TRUE(video_channel_ != NULL);
2467
2468 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2469 ASSERT_EQ(1u, video_channel_->send_streams().size());
2470 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2471
2472 // Update the session descriptions, with Audio and Video.
2473 mediastream_signaling_.SendAudioVideoStream2();
2474 CreateAndSetRemoteOfferAndLocalAnswer();
2475
2476 voice_channel_ = media_engine_->GetVoiceChannel(0);
2477 ASSERT_TRUE(voice_channel_ != NULL);
2478
2479 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2480 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2481 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2482 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2483
2484 // Change session back to video only.
2485 mediastream_signaling_.UseOptionsVideoOnly();
2486 CreateAndSetRemoteOfferAndLocalAnswer();
2487
2488 video_channel_ = media_engine_->GetVideoChannel(0);
2489 voice_channel_ = media_engine_->GetVoiceChannel(0);
2490
2491 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2492 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2493 ASSERT_EQ(1u, video_channel_->send_streams().size());
2494 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2495}
2496
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002498 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002499 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002500 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002501 VerifyCryptoParams(offer->description());
2502 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002503 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002504 VerifyCryptoParams(answer->description());
2505}
2506
2507TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002508 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002509 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002510 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002511 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002512 VerifyNoCryptoParams(offer->description(), false);
2513}
2514
2515TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002516 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002517 VerifyAnswerFromNonCryptoOffer();
2518}
2519
2520TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002521 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002522 VerifyAnswerFromCryptoOffer();
2523}
2524
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002525// This test verifies that setLocalDescription fails if
2526// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2527TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002528 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002529 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002530 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2531
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002532 std::string sdp;
2533 RemoveIceUfragPwdLines(offer.get(), &sdp);
2534 SessionDescriptionInterface* modified_offer =
2535 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002536 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002537}
2538
2539// This test verifies that setRemoteDescription fails if
2540// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2541TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002542 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002543 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002544 std::string sdp;
2545 RemoveIceUfragPwdLines(offer.get(), &sdp);
2546 SessionDescriptionInterface* modified_offer =
2547 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002548 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002549}
2550
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002551// This test verifies that setLocalDescription fails if local offer has
2552// too short ice ufrag and pwd strings.
2553TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002554 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002555 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
2556 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002557 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2558
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002559 std::string sdp;
2560 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2561 // recommended values of 4 and 22 bytes respectively.
2562 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2563 SessionDescriptionInterface* modified_offer =
2564 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2565 std::string error;
2566 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2567
2568 // Test with string greater than 256.
2569 sdp.clear();
2570 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2571 &sdp);
2572 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2573 NULL);
2574 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2575}
2576
2577// This test verifies that setRemoteDescription fails if remote offer has
2578// too short ice ufrag and pwd strings.
2579TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002580 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002581 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002582 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002583 std::string sdp;
2584 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2585 // recommended values of 4 and 22 bytes respectively.
2586 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2587 SessionDescriptionInterface* modified_offer =
2588 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2589 std::string error;
2590 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2591
2592 sdp.clear();
2593 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2594 &sdp);
2595 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2596 NULL);
2597 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2598}
2599
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) {
2601 // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in
2602 // local description is removed by the application, BUNDLE flag should be
2603 // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002604 Init();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002605 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2606 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002607 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2608
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002609 cricket::SessionDescription* offer_copy =
2610 offer->description()->Copy();
2611 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2612 JsepSessionDescription* modified_offer =
2613 new JsepSessionDescription(JsepSessionDescription::kOffer);
2614 modified_offer->Initialize(offer_copy, "1", "1");
2615
2616 SetLocalDescriptionWithoutError(modified_offer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002617 EXPECT_FALSE(allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002618}
2619
2620TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002621 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002622 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002623 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2624 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002625
2626 PeerConnectionInterface::RTCOfferAnswerOptions options;
2627 options.use_rtp_mux = true;
2628
2629 SessionDescriptionInterface* offer = CreateOffer(options);
2630
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002631 SetLocalDescriptionWithoutError(offer);
2632 mediastream_signaling_.SendAudioVideoStream2();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002633 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002634 CreateRemoteAnswer(session_->local_description()));
2635 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2636 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2637 JsepSessionDescription* modified_answer =
2638 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2639 modified_answer->Initialize(answer_copy, "1", "1");
2640 SetRemoteDescriptionWithoutError(modified_answer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002641 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2642 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002643
2644 video_channel_ = media_engine_->GetVideoChannel(0);
2645 voice_channel_ = media_engine_->GetVoiceChannel(0);
2646
2647 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2648 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
2649
2650 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2651 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
2652
2653 ASSERT_EQ(1u, video_channel_->send_streams().size());
2654 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
2655 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2656 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
2657}
2658
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002659// This test verifies that SetLocalDescription and SetRemoteDescription fails
2660// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2661TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002662 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002663 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002664 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2665 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002666
2667 PeerConnectionInterface::RTCOfferAnswerOptions options;
2668 options.use_rtp_mux = true;
2669
2670 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002671 std::string offer_str;
2672 offer->ToString(&offer_str);
2673 // Disable rtcp-mux
2674 const std::string rtcp_mux = "rtcp-mux";
2675 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002676 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002677 xrtcp_mux.c_str(), xrtcp_mux.length(),
2678 &offer_str);
2679 JsepSessionDescription *local_offer =
2680 new JsepSessionDescription(JsepSessionDescription::kOffer);
2681 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002682 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002683 JsepSessionDescription *remote_offer =
2684 new JsepSessionDescription(JsepSessionDescription::kOffer);
2685 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002686 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002687 // Trying unmodified SDP.
2688 SetLocalDescriptionWithoutError(offer);
2689}
2690
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002691TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002692 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002693 mediastream_signaling_.SendAudioVideoStream1();
2694 CreateAndSetRemoteOfferAndLocalAnswer();
2695 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2696 ASSERT_TRUE(channel != NULL);
2697 ASSERT_EQ(1u, channel->recv_streams().size());
2698 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2699 double left_vol, right_vol;
2700 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2701 EXPECT_EQ(1, left_vol);
2702 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002703 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002704 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002705 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2706 EXPECT_EQ(0, left_vol);
2707 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002708 EXPECT_EQ(0, renderer->channel_id());
2709 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2711 EXPECT_EQ(1, left_vol);
2712 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002713 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002714}
2715
2716TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002717 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718 mediastream_signaling_.SendAudioVideoStream1();
2719 CreateAndSetRemoteOfferAndLocalAnswer();
2720 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2721 ASSERT_TRUE(channel != NULL);
2722 ASSERT_EQ(1u, channel->send_streams().size());
2723 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2724 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2725
2726 cricket::AudioOptions options;
2727 options.echo_cancellation.Set(true);
2728
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002729 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002730 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002731 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2732 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002733 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002734 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002735
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002736 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002737 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002738 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2739 bool value;
2740 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2741 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002742 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002743 EXPECT_TRUE(renderer->sink() == NULL);
2744}
2745
2746TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002747 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002748 mediastream_signaling_.SendAudioVideoStream1();
2749 CreateAndSetRemoteOfferAndLocalAnswer();
2750 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2751 ASSERT_TRUE(channel != NULL);
2752 ASSERT_EQ(1u, channel->send_streams().size());
2753 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2754
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002755 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002756 cricket::AudioOptions options;
2757 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
2758 EXPECT_TRUE(renderer->sink() != NULL);
2759
2760 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
2761 // will invalidate the |renderer_| pointer in the sink and prevent getting a
2762 // SetSink(NULL) callback afterwards.
2763 renderer.reset();
2764
2765 // This will trigger SetSink(NULL) if no OnClose() callback.
2766 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002767}
2768
2769TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002770 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002771 mediastream_signaling_.SendAudioVideoStream1();
2772 CreateAndSetRemoteOfferAndLocalAnswer();
2773 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2774 ASSERT_TRUE(channel != NULL);
2775 ASSERT_LT(0u, channel->renderers().size());
2776 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2777 ASSERT_EQ(1u, channel->recv_streams().size());
2778 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2779 cricket::FakeVideoRenderer renderer;
2780 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2781 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2782 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2783 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2784}
2785
2786TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002787 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002788 mediastream_signaling_.SendAudioVideoStream1();
2789 CreateAndSetRemoteOfferAndLocalAnswer();
2790 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2791 ASSERT_TRUE(channel != NULL);
2792 ASSERT_EQ(1u, channel->send_streams().size());
2793 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2794 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2795 cricket::VideoOptions* options = NULL;
2796 session_->SetVideoSend(send_ssrc, false, options);
2797 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2798 session_->SetVideoSend(send_ssrc, true, options);
2799 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2800}
2801
2802TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2803 TestCanInsertDtmf(false);
2804}
2805
2806TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2807 TestCanInsertDtmf(true);
2808}
2809
2810TEST_F(WebRtcSessionTest, InsertDtmf) {
2811 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002812 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002813 mediastream_signaling_.SendAudioVideoStream1();
2814 CreateAndSetRemoteOfferAndLocalAnswer();
2815 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2816 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2817
2818 // Insert DTMF
2819 const int expected_flags = DF_SEND;
2820 const int expected_duration = 90;
2821 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2822 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2823 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2824
2825 // Verify
2826 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2827 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2828 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2829 expected_duration, expected_flags));
2830 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2831 expected_duration, expected_flags));
2832 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2833 expected_duration, expected_flags));
2834}
2835
2836// This test verifies the |initiator| flag when session initiates the call.
2837TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002838 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002839 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002840 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002841 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2842 SetLocalDescriptionWithoutError(offer);
2843 EXPECT_TRUE(session_->initiator());
2844 SetRemoteDescriptionWithoutError(answer);
2845 EXPECT_TRUE(session_->initiator());
2846}
2847
2848// This test verifies the |initiator| flag when session receives the call.
2849TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002850 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002851 EXPECT_FALSE(session_->initiator());
2852 SessionDescriptionInterface* offer = CreateRemoteOffer();
2853 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002854 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002855
2856 EXPECT_FALSE(session_->initiator());
2857 SetLocalDescriptionWithoutError(answer);
2858 EXPECT_FALSE(session_->initiator());
2859}
2860
2861// This test verifies the ice protocol type at initiator of the call
2862// if |a=ice-options:google-ice| is present in answer.
2863TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002864 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002865 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002866 SessionDescriptionInterface* offer = CreateOffer();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002867 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002868 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002869 SetLocalDescriptionWithoutError(offer);
2870 std::string sdp;
2871 EXPECT_TRUE(answer->ToString(&sdp));
2872 // Adding ice-options to the session level.
2873 InjectAfter("t=0 0\r\n",
2874 "a=ice-options:google-ice\r\n",
2875 &sdp);
2876 SessionDescriptionInterface* answer_with_gice =
2877 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00002878 // Default offer is ICEPROTO_RFC5245, so we expect responder with
2879 // only gice to fail.
2880 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed, answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002881}
2882
2883// This test verifies the ice protocol type at initiator of the call
2884// if ICE RFC5245 is supported in answer.
2885TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002886 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002887 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002888 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002889 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2890 SetLocalDescriptionWithoutError(offer);
2891
2892 SetRemoteDescriptionWithoutError(answer);
2893 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2894 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2895}
2896
2897// This test verifies the ice protocol type at receiver side of the call if
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002898// receiver decides to use ice RFC 5245.
2899TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002900 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002901 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002902 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002903 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002904 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002905 SetLocalDescriptionWithoutError(answer);
2906 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2907 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2908}
2909
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002910// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2911TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002912 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002913 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002914 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002915 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002916 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002917 CreateRemoteAnswer(session_->local_description()));
2918
2919 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2920 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002921 JsepSessionDescription* modified_answer =
2922 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002923
2924 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2925 answer->session_id(),
2926 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002927 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002928
wu@webrtc.org4e393072014-04-07 17:04:35 +00002929 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002930 std::string sdp;
2931 EXPECT_TRUE(answer->ToString(&sdp));
2932 const std::string kAudioMid = "a=mid:audio";
2933 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002934 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002935 kAudioMidReplaceStr.c_str(),
2936 kAudioMidReplaceStr.length(),
2937 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002938 SessionDescriptionInterface* modified_answer1 =
2939 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002940 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002941
wu@webrtc.org4e393072014-04-07 17:04:35 +00002942 // Different media types.
2943 EXPECT_TRUE(answer->ToString(&sdp));
2944 const std::string kAudioMline = "m=audio";
2945 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002946 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00002947 kAudioMlineReplaceStr.c_str(),
2948 kAudioMlineReplaceStr.length(),
2949 &sdp);
2950 SessionDescriptionInterface* modified_answer2 =
2951 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2952 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
2953
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002954 SetRemoteDescriptionWithoutError(answer.release());
2955}
2956
2957// Verifying remote offer and local answer have matching m-lines as per
2958// RFC 3264.
2959TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002960 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002961 mediastream_signaling_.SendAudioVideoStream1();
2962 SessionDescriptionInterface* offer = CreateRemoteOffer();
2963 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002964 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002965
2966 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2967 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002968 JsepSessionDescription* modified_answer =
2969 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002970
2971 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2972 answer->session_id(),
2973 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002974 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002975 SetLocalDescriptionWithoutError(answer);
2976}
2977
2978// This test verifies that WebRtcSession does not start candidate allocation
2979// before SetLocalDescription is called.
2980TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002981 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002982 mediastream_signaling_.SendAudioVideoStream1();
2983 SessionDescriptionInterface* offer = CreateRemoteOffer();
2984 cricket::Candidate candidate;
2985 candidate.set_component(1);
2986 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2987 candidate);
2988 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2989 cricket::Candidate candidate1;
2990 candidate1.set_component(1);
2991 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2992 candidate1);
2993 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2994 SetRemoteDescriptionWithoutError(offer);
2995 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
2996 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
2997
2998 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002999 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003000 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3001 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3002
wu@webrtc.org91053e72013-08-10 07:18:04 +00003003 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003004 SetLocalDescriptionWithoutError(answer);
3005 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
3006 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
3007 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3008}
3009
3010// This test verifies that crypto parameter is updated in local session
3011// description as per security policy set in MediaSessionDescriptionFactory.
3012TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003013 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003014 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003015 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003016
3017 // Making sure SetLocalDescription correctly sets crypto value in
3018 // SessionDescription object after de-serialization of sdp string. The value
3019 // will be set as per MediaSessionDescriptionFactory.
3020 std::string offer_str;
3021 offer->ToString(&offer_str);
3022 SessionDescriptionInterface* jsep_offer_str =
3023 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3024 SetLocalDescriptionWithoutError(jsep_offer_str);
3025 EXPECT_TRUE(session_->voice_channel()->secure_required());
3026 EXPECT_TRUE(session_->video_channel()->secure_required());
3027}
3028
3029// This test verifies the crypto parameter when security is disabled.
3030TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003031 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003032 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003033 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003034 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003035
3036 // Making sure SetLocalDescription correctly sets crypto value in
3037 // SessionDescription object after de-serialization of sdp string. The value
3038 // will be set as per MediaSessionDescriptionFactory.
3039 std::string offer_str;
3040 offer->ToString(&offer_str);
3041 SessionDescriptionInterface *jsep_offer_str =
3042 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3043 SetLocalDescriptionWithoutError(jsep_offer_str);
3044 EXPECT_FALSE(session_->voice_channel()->secure_required());
3045 EXPECT_FALSE(session_->video_channel()->secure_required());
3046}
3047
3048// This test verifies that an answer contains new ufrag and password if an offer
3049// with new ufrag and password is received.
3050TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003051 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003052 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003053 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003054 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003055 CreateRemoteOffer(options));
3056 SetRemoteDescriptionWithoutError(offer.release());
3057
3058 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003059 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003060 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003061 SetLocalDescriptionWithoutError(answer.release());
3062
3063 // Receive an offer with new ufrag and password.
3064 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003065 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003066 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003067 SetRemoteDescriptionWithoutError(updated_offer1.release());
3068
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003069 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003070 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003071
3072 CompareIceUfragAndPassword(updated_answer1->description(),
3073 session_->local_description()->description(),
3074 false);
3075
3076 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003077}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003078
wu@webrtc.org91053e72013-08-10 07:18:04 +00003079// This test verifies that an answer contains old ufrag and password if an offer
3080// with old ufrag and password is received.
3081TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003082 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003083 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003084 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003085 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003086 CreateRemoteOffer(options));
3087 SetRemoteDescriptionWithoutError(offer.release());
3088
3089 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003090 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003091 CreateAnswer(NULL));
3092 SetLocalDescriptionWithoutError(answer.release());
3093
3094 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003095 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003096 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003097 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003098 SetRemoteDescriptionWithoutError(updated_offer2.release());
3099
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003100 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003101 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003102
3103 CompareIceUfragAndPassword(updated_answer2->description(),
3104 session_->local_description()->description(),
3105 true);
3106
3107 SetLocalDescriptionWithoutError(updated_answer2.release());
3108}
3109
3110TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003111 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003112 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003113 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003114 const std::string session_id_orig = offer->session_id();
3115 const std::string session_version_orig = offer->session_version();
3116 SetLocalDescriptionWithoutError(offer);
3117
3118 video_channel_ = media_engine_->GetVideoChannel(0);
3119 video_channel_->set_fail_set_send_codecs(true);
3120
3121 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003122 SessionDescriptionInterface* answer =
3123 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003124 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003125}
3126
3127// Runs the loopback call test with BUNDLE and STUN disabled.
3128TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3129 // Lets try with only UDP ports.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003130 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003131 cricket::PORTALLOCATOR_DISABLE_TCP |
3132 cricket::PORTALLOCATOR_DISABLE_STUN |
3133 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003134 TestLoopbackCall();
3135}
3136
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003137TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
3138 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3139 cricket::PORTALLOCATOR_DISABLE_TCP |
3140 cricket::PORTALLOCATOR_DISABLE_STUN |
3141 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3142 cricket::PORTALLOCATOR_DISABLE_RELAY);
3143
3144 // best connection is IPv6 since it has higher network preference.
3145 LoopbackNetworkConfiguration config;
3146 config.test_ipv6_network_ = true;
3147 config.best_connection_after_initial_ice_converged_ =
3148 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3149
3150 TestLoopbackCall(config);
3151}
3152
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003153// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003154TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003155 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003156 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003157 cricket::PORTALLOCATOR_DISABLE_TCP |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003158 cricket::PORTALLOCATOR_DISABLE_RELAY);
3159 TestLoopbackCall();
3160}
3161
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003162TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003163 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003164 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003165 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003166
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003167 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3168 std::string error_code_str = "ERROR_CONTENT";
3169 std::string error_desc = "Fake session error description.";
3170 session_->SetError(error_code, error_desc);
3171
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003172 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3173 SessionDescriptionInterface* answer =
3174 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003175
3176 std::string action;
3177 std::ostringstream session_error_msg;
3178 session_error_msg << kSessionError << error_code_str << ". ";
3179 session_error_msg << kSessionErrorDesc << error_desc << ".";
3180 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3181 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003182}
3183
3184TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3185 constraints_.reset(new FakeConstraints());
3186 constraints_->AddOptional(
3187 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003188 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003189
3190 SetLocalDescriptionWithDataChannel();
3191 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3192}
3193
3194TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003195 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003196
3197 constraints_.reset(new FakeConstraints());
3198 constraints_->AddOptional(
3199 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003200 options_.disable_sctp_data_channels = false;
3201
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003202 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003203
3204 SetLocalDescriptionWithDataChannel();
3205 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3206}
3207
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003208TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003209 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003210
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003211 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003212
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003213 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003214 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003215 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3216}
3217
3218TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003219 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003220 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003221 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003222
3223 // Create remote offer with SCTP.
3224 cricket::MediaSessionOptions options;
3225 options.data_channel_type = cricket::DCT_SCTP;
3226 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003227 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003228 SetRemoteDescriptionWithoutError(offer);
3229
3230 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003231 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003232 EXPECT_TRUE(answer != NULL);
3233 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3234 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003235}
3236
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003237TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3238 constraints_.reset(new FakeConstraints());
3239 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003240 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003241 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003242
3243 SetLocalDescriptionWithDataChannel();
3244 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3245}
3246
3247TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003248 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003249
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003250 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003251
3252 SetLocalDescriptionWithDataChannel();
3253 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3254}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003255
wu@webrtc.org97077a32013-10-25 21:18:33 +00003256TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003257 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003258 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003259 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003260
3261 SetLocalDescriptionWithDataChannel();
3262 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3263}
3264
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003265TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003266 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003267 const int new_send_port = 9998;
3268 const int new_recv_port = 7775;
3269
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003270 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003271 SetFactoryDtlsSrtp();
3272
3273 // By default, don't actually add the codecs to desc_factory_; they don't
3274 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3275 // let the session description get parsed. That'll get the proper codecs
3276 // into the stream.
3277 cricket::MediaSessionOptions options;
3278 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3279 "stream1", new_send_port, options);
3280
3281 // SetRemoteDescription will take the ownership of the offer.
3282 SetRemoteDescriptionWithoutError(offer);
3283
3284 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3285 new_recv_port, CreateAnswer(NULL));
3286 ASSERT_TRUE(answer != NULL);
3287
3288 // Now set the local description, which'll take ownership of the answer.
3289 SetLocalDescriptionWithoutError(answer);
3290
3291 // TEST PLAN: Set the port number to something new, set it in the SDP,
3292 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003293 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003294 dci.reliable = true;
3295 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003296 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003297 session_->CreateDataChannel("datachannel", &dci);
3298
3299 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3300 int portnum = -1;
3301 ASSERT_TRUE(ch != NULL);
3302 ASSERT_EQ(1UL, ch->send_codecs().size());
3303 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
3304 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3305 ch->send_codecs()[0].name.c_str()));
3306 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3307 &portnum));
3308 EXPECT_EQ(new_send_port, portnum);
3309
3310 ASSERT_EQ(1UL, ch->recv_codecs().size());
3311 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
3312 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3313 ch->recv_codecs()[0].name.c_str()));
3314 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3315 &portnum));
3316 EXPECT_EQ(new_recv_port, portnum);
3317}
3318
wu@webrtc.org91053e72013-08-10 07:18:04 +00003319// Verifies that CreateOffer succeeds when CreateOffer is called before async
3320// identity generation is finished.
3321TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003322 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003323 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003324
3325 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003326 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003327 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3328
wu@webrtc.org91053e72013-08-10 07:18:04 +00003329 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003330 VerifyNoCryptoParams(offer->description(), true);
3331 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003332}
3333
3334// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3335// identity generation is finished.
3336TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003337 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003338 InitWithDtls();
3339 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003340
3341 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003342 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003343 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003344 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003345 ASSERT_TRUE(offer.get() != NULL);
3346 SetRemoteDescriptionWithoutError(offer.release());
3347
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003348 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003349 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003350 VerifyNoCryptoParams(answer->description(), true);
3351 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003352}
3353
3354// Verifies that CreateOffer succeeds when CreateOffer is called after async
3355// identity generation is finished.
3356TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003357 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003358 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003359
3360 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003361
3362 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003363 EXPECT_TRUE(offer != NULL);
3364}
3365
3366// Verifies that CreateOffer fails when CreateOffer is called after async
3367// identity generation fails.
3368TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003369 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003370 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003371
3372 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003373
3374 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003375 EXPECT_TRUE(offer == NULL);
3376}
3377
3378// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3379// before async identity generation is finished.
3380TEST_F(WebRtcSessionTest,
3381 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003382 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003383 VerifyMultipleAsyncCreateDescription(
3384 true, CreateSessionDescriptionRequest::kOffer);
3385}
3386
3387// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3388// before async identity generation fails.
3389TEST_F(WebRtcSessionTest,
3390 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003391 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003392 VerifyMultipleAsyncCreateDescription(
3393 false, CreateSessionDescriptionRequest::kOffer);
3394}
3395
3396// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3397// before async identity generation is finished.
3398TEST_F(WebRtcSessionTest,
3399 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003400 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003401 VerifyMultipleAsyncCreateDescription(
3402 true, CreateSessionDescriptionRequest::kAnswer);
3403}
3404
3405// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3406// before async identity generation fails.
3407TEST_F(WebRtcSessionTest,
3408 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003409 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003410 VerifyMultipleAsyncCreateDescription(
3411 false, CreateSessionDescriptionRequest::kAnswer);
3412}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003413
3414// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3415// offer has no SDES crypto but only DTLS fingerprint.
3416TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3417 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003418 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003419 // Create a remote offer with secured transport disabled.
3420 cricket::MediaSessionOptions options;
3421 JsepSessionDescription* offer(CreateRemoteOffer(
3422 options, cricket::SEC_DISABLED));
3423 // Adds a DTLS fingerprint to the remote offer.
3424 cricket::SessionDescription* sdp = offer->description();
3425 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3426 ASSERT_TRUE(audio != NULL);
3427 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3428 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003429 rtc::SSLFingerprint::CreateFromRfc4572(
3430 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003431 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003432 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003433}
3434
wu@webrtc.orgde305012013-10-31 15:40:38 +00003435// This test verifies DSCP is properly applied on the media channels.
3436TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3437 constraints_.reset(new FakeConstraints());
3438 constraints_->AddOptional(
3439 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003440 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003441 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003442 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003443
3444 SetLocalDescriptionWithoutError(offer);
3445
3446 video_channel_ = media_engine_->GetVideoChannel(0);
3447 voice_channel_ = media_engine_->GetVoiceChannel(0);
3448
3449 ASSERT_TRUE(video_channel_ != NULL);
3450 ASSERT_TRUE(voice_channel_ != NULL);
3451 cricket::AudioOptions audio_options;
3452 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3453 cricket::VideoOptions video_options;
3454 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3455 EXPECT_TRUE(audio_options.dscp.IsSet());
3456 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3457 EXPECT_TRUE(video_options.dscp.IsSet());
3458 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3459}
3460
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003461TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3462 constraints_.reset(new FakeConstraints());
3463 constraints_->AddOptional(
3464 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3465 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003466 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003467 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003468 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003469
3470 SetLocalDescriptionWithoutError(offer);
3471
3472 video_channel_ = media_engine_->GetVideoChannel(0);
3473
3474 ASSERT_TRUE(video_channel_ != NULL);
3475 cricket::VideoOptions video_options;
3476 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3477 EXPECT_TRUE(
3478 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3479}
3480
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003481TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3482 // Number of unsignalled receiving streams should be between 0 and
3483 // kMaxUnsignalledRecvStreams.
3484 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3485 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3486 kMaxUnsignalledRecvStreams);
3487 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3488}
3489
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003490TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3491 constraints_.reset(new FakeConstraints());
3492 constraints_->AddOptional(
3493 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3494 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003495 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003496 mediastream_signaling_.SendAudioVideoStream1();
3497 SessionDescriptionInterface* offer = CreateOffer();
3498
3499 SetLocalDescriptionWithoutError(offer);
3500
3501 voice_channel_ = media_engine_->GetVoiceChannel(0);
3502
3503 ASSERT_TRUE(voice_channel_ != NULL);
3504 cricket::AudioOptions audio_options;
3505 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3506 EXPECT_TRUE(
3507 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3508}
3509
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003510// Tests that we can renegotiate new media content with ICE candidates in the
3511// new remote SDP.
3512TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003513 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003514 InitWithDtls();
3515 SetFactoryDtlsSrtp();
3516
3517 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003518 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003519 SetLocalDescriptionWithoutError(offer);
3520
3521 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3522 SetRemoteDescriptionWithoutError(answer);
3523
3524 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003525 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003526 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3527
3528 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003529 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003530 candidate1.set_component(1);
3531 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3532 candidate1);
3533 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3534 SetRemoteDescriptionWithoutError(offer);
3535
3536 answer = CreateAnswer(NULL);
3537 SetLocalDescriptionWithoutError(answer);
3538}
3539
3540// Tests that we can renegotiate new media content with ICE candidates separated
3541// from the remote SDP.
3542TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003543 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003544 InitWithDtls();
3545 SetFactoryDtlsSrtp();
3546
3547 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003548 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003549 SetLocalDescriptionWithoutError(offer);
3550
3551 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3552 SetRemoteDescriptionWithoutError(answer);
3553
3554 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003555 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003556 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3557 SetRemoteDescriptionWithoutError(offer);
3558
3559 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003560 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003561 candidate1.set_component(1);
3562 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3563 candidate1);
3564 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3565
3566 answer = CreateAnswer(NULL);
3567 SetLocalDescriptionWithoutError(answer);
3568}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00003569// Tests that RTX codec is removed from the answer when it isn't supported
3570// by local side.
3571TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
3572 Init();
3573 mediastream_signaling_.SendAudioVideoStream1();
3574 std::string offer_sdp(kSdpWithRtx);
3575
3576 SessionDescriptionInterface* offer =
3577 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
3578 EXPECT_TRUE(offer->ToString(&offer_sdp));
3579
3580 // Offer SDP contains the RTX codec.
3581 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
3582 SetRemoteDescriptionWithoutError(offer);
3583
3584 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3585 std::string answer_sdp;
3586 answer->ToString(&answer_sdp);
3587 // Answer SDP removes the unsupported RTX codec.
3588 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
3589 SetLocalDescriptionWithoutError(answer);
3590}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003591
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003592// This verifies that the voice channel after bundle has both options from video
3593// and voice channels.
3594TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3595 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3596 mediastream_signaling_.SendAudioVideoStream1();
3597
3598 PeerConnectionInterface::RTCOfferAnswerOptions options;
3599 options.use_rtp_mux = true;
3600
3601 SessionDescriptionInterface* offer = CreateOffer(options);
3602 SetLocalDescriptionWithoutError(offer);
3603
3604 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3605 rtc::Socket::Option::OPT_SNDBUF, 4000);
3606
3607 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3608 rtc::Socket::Option::OPT_RCVBUF, 8000);
3609
3610 int option_val;
3611 EXPECT_TRUE(session_->video_channel()->transport_channel()->GetOption(
3612 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3613 EXPECT_EQ(4000, option_val);
3614 EXPECT_FALSE(session_->voice_channel()->transport_channel()->GetOption(
3615 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3616
3617 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3618 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3619 EXPECT_EQ(8000, option_val);
3620 EXPECT_FALSE(session_->video_channel()->transport_channel()->GetOption(
3621 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3622
3623 EXPECT_NE(session_->voice_channel()->transport_channel(),
3624 session_->video_channel()->transport_channel());
3625
3626 mediastream_signaling_.SendAudioVideoStream2();
3627 SessionDescriptionInterface* answer =
3628 CreateRemoteAnswer(session_->local_description());
3629 SetRemoteDescriptionWithoutError(answer);
3630
3631 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3632 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3633 EXPECT_EQ(4000, option_val);
3634
3635 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3636 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3637 EXPECT_EQ(8000, option_val);
3638}
3639
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003640// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3641// currently fails because upon disconnection and reconnection OnIceComplete is
3642// called more than once without returning to IceGatheringGathering.