blob: 16ce621eb81d5e5c26cae467708a33cf49fadc23 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kwiberg0eb15ed2015-12-17 03:04:15 -080011#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070012#include <vector>
13
Henrik Kjellander15583c12016-02-10 10:53:12 +010014#include "webrtc/api/audiotrack.h"
15#include "webrtc/api/fakemediacontroller.h"
16#include "webrtc/api/fakemetricsobserver.h"
17#include "webrtc/api/jsepicecandidate.h"
18#include "webrtc/api/jsepsessiondescription.h"
19#include "webrtc/api/peerconnection.h"
20#include "webrtc/api/sctputils.h"
21#include "webrtc/api/streamcollection.h"
22#include "webrtc/api/streamcollection.h"
23#include "webrtc/api/test/fakeconstraints.h"
24#include "webrtc/api/test/fakedtlsidentitystore.h"
25#include "webrtc/api/videotrack.h"
26#include "webrtc/api/webrtcsession.h"
27#include "webrtc/api/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000028#include "webrtc/base/fakenetwork.h"
29#include "webrtc/base/firewallsocketserver.h"
30#include "webrtc/base/gunit.h"
31#include "webrtc/base/logging.h"
32#include "webrtc/base/network.h"
33#include "webrtc/base/physicalsocketserver.h"
34#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020035#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000036#include "webrtc/base/sslstreamadapter.h"
37#include "webrtc/base/stringutils.h"
38#include "webrtc/base/thread.h"
39#include "webrtc/base/virtualsocketserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080040#include "webrtc/media/base/fakemediaengine.h"
41#include "webrtc/media/base/fakevideorenderer.h"
42#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010043#include "webrtc/media/engine/fakewebrtccall.h"
kjellandera96e2d72016-02-04 23:52:28 -080044#include "webrtc/p2p/base/stunserver.h"
45#include "webrtc/p2p/base/teststunserver.h"
46#include "webrtc/p2p/base/testturnserver.h"
47#include "webrtc/p2p/base/transportchannel.h"
48#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010049#include "webrtc/pc/channelmanager.h"
50#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051
52#define MAYBE_SKIP_TEST(feature) \
53 if (!(feature())) { \
54 LOG(LS_INFO) << "Feature disabled... skipping"; \
55 return; \
56 }
57
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000060using rtc::SocketAddress;
61using rtc::scoped_ptr;
62using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000064using webrtc::CreateSessionDescriptionObserver;
65using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070066using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020067using webrtc::DtlsIdentityStoreInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070069using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070071using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072using webrtc::JsepIceCandidate;
73using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000074using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using webrtc::PeerConnectionInterface;
76using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070077using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000079using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000080using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000081using webrtc::kCreateChannelFailed;
82using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000084using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000085using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000086using webrtc::kSdpWithoutDtlsFingerprint;
87using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000089using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000090using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000092typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
93
wu@webrtc.org364f2042013-11-20 21:49:41 +000094static const int kClientAddrPort = 0;
95static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000096static const char kClientIPv6AddrHost1[] =
97 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000098static const char kClientAddrHost2[] = "22.22.22.22";
99static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000100static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
101static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000102static const char kTurnUsername[] = "test";
103static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104
105static const char kSessionVersion[] = "1";
106
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107// Media index of candidates belonging to the first media content.
108static const int kMediaContentIndex0 = 0;
109static const char kMediaContentName0[] = "audio";
110
111// Media index of candidates belonging to the second media content.
112static const int kMediaContentIndex1 = 1;
113static const char kMediaContentName1[] = "video";
114
115static const int kIceCandidatesTimeout = 10000;
116
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000117static const char kFakeDtlsFingerprint[] =
118 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
119 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
120
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000121static const char kTooLongIceUfragPwd[] =
122 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
123 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
124 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
125 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
126
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000127static const char kSdpWithRtx[] =
128 "v=0\r\n"
129 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
130 "s=-\r\n"
131 "t=0 0\r\n"
132 "a=msid-semantic: WMS stream1\r\n"
133 "m=video 9 RTP/SAVPF 0 96\r\n"
134 "c=IN IP4 0.0.0.0\r\n"
135 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
136 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
137 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
138 "a=mid:video\r\n"
139 "a=sendrecv\r\n"
140 "a=rtcp-mux\r\n"
141 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
142 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
143 "a=rtpmap:0 fake_video_codec/90000\r\n"
144 "a=rtpmap:96 rtx/90000\r\n"
145 "a=fmtp:96 apt=0\r\n";
146
deadbeefab9b2d12015-10-14 11:33:11 -0700147static const char kStream1[] = "stream1";
148static const char kVideoTrack1[] = "video1";
149static const char kAudioTrack1[] = "audio1";
150
151static const char kStream2[] = "stream2";
152static const char kVideoTrack2[] = "video2";
153static const char kAudioTrack2[] = "audio2";
154
Henrik Boström87713d02015-08-25 09:53:21 +0200155enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
156
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157class MockIceObserver : public webrtc::IceObserver {
158 public:
159 MockIceObserver()
160 : oncandidatesready_(false),
161 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
162 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
163 }
164
perkjdfb769d2016-02-09 03:09:43 -0800165 void OnIceConnectionChange(
166 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 ice_connection_state_ = new_state;
168 }
perkjdfb769d2016-02-09 03:09:43 -0800169 void OnIceGatheringChange(
170 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 // We can never transition back to "new".
172 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
173 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800174 oncandidatesready_ =
175 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176 }
177
178 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800179 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000180 switch (candidate->sdp_mline_index()) {
181 case kMediaContentIndex0:
182 mline_0_candidates_.push_back(candidate->candidate());
183 break;
184 case kMediaContentIndex1:
185 mline_1_candidates_.push_back(candidate->candidate());
186 break;
187 default:
188 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000190
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 // The ICE gathering state should always be Gathering when a candidate is
192 // received (or possibly Completed in the case of the final candidate).
193 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
194 }
195
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 bool oncandidatesready_;
197 std::vector<cricket::Candidate> mline_0_candidates_;
198 std::vector<cricket::Candidate> mline_1_candidates_;
199 PeerConnectionInterface::IceConnectionState ice_connection_state_;
200 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
201};
202
203class WebRtcSessionForTest : public webrtc::WebRtcSession {
204 public:
stefanc1aeaf02015-10-15 07:26:07 -0700205 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000206 rtc::Thread* signaling_thread,
207 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700209 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700210 : WebRtcSession(media_controller,
211 signaling_thread,
212 worker_thread,
213 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 RegisterIceObserver(ice_observer);
215 }
216 virtual ~WebRtcSessionForTest() {}
217
deadbeefcbecd352015-09-23 11:50:27 -0700218 // Note that these methods are only safe to use if the signaling thread
219 // is the same as the worker thread
220 cricket::TransportChannel* voice_rtp_transport_channel() {
221 return rtp_transport_channel(voice_channel());
222 }
223
224 cricket::TransportChannel* voice_rtcp_transport_channel() {
225 return rtcp_transport_channel(voice_channel());
226 }
227
228 cricket::TransportChannel* video_rtp_transport_channel() {
229 return rtp_transport_channel(video_channel());
230 }
231
232 cricket::TransportChannel* video_rtcp_transport_channel() {
233 return rtcp_transport_channel(video_channel());
234 }
235
236 cricket::TransportChannel* data_rtp_transport_channel() {
237 return rtp_transport_channel(data_channel());
238 }
239
240 cricket::TransportChannel* data_rtcp_transport_channel() {
241 return rtcp_transport_channel(data_channel());
242 }
243
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 using webrtc::WebRtcSession::SetAudioPlayout;
245 using webrtc::WebRtcSession::SetAudioSend;
246 using webrtc::WebRtcSession::SetCaptureDevice;
247 using webrtc::WebRtcSession::SetVideoPlayout;
248 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700249
250 private:
251 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
252 if (!ch) {
253 return nullptr;
254 }
255 return ch->transport_channel();
256 }
257
258 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
259 if (!ch) {
260 return nullptr;
261 }
262 return ch->rtcp_transport_channel();
263 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264};
265
wu@webrtc.org91053e72013-08-10 07:18:04 +0000266class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000267 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000269 enum State {
270 kInit,
271 kFailed,
272 kSucceeded,
273 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000274 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000275
276 // CreateSessionDescriptionObserver implementation.
277 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000278 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000279 state_ = kSucceeded;
280 }
281 virtual void OnFailure(const std::string& error) {
282 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283 }
284
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000285 SessionDescriptionInterface* description() { return description_.get(); }
286
287 SessionDescriptionInterface* ReleaseDescription() {
288 return description_.release();
289 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290
wu@webrtc.org91053e72013-08-10 07:18:04 +0000291 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292
wu@webrtc.org91053e72013-08-10 07:18:04 +0000293 protected:
294 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295
296 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000297 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000298 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299};
300
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000301class FakeAudioRenderer : public cricket::AudioRenderer {
302 public:
solenberg98c68862015-10-09 03:27:14 -0700303 FakeAudioRenderer() : sink_(NULL) {}
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000304 virtual ~FakeAudioRenderer() {
305 if (sink_)
306 sink_->OnClose();
307 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000308
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000309 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000310
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000311 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000312 private:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000313 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000314};
315
Henrik Boström87713d02015-08-25 09:53:21 +0200316class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700317 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
318 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 protected:
320 // TODO Investigate why ChannelManager crashes, if it's created
321 // after stun_server.
322 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700323 : media_engine_(new cricket::FakeMediaEngine()),
324 data_engine_(new cricket::FakeDataEngine()),
325 channel_manager_(
326 new cricket::ChannelManager(media_engine_,
327 data_engine_,
328 new cricket::CaptureManager(),
329 rtc::Thread::Current())),
330 fake_call_(webrtc::Call::Config()),
331 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800332 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
333 rtc::Thread::Current(),
stefanc1aeaf02015-10-15 07:26:07 -0700334 channel_manager_.get())),
335 tdesc_factory_(new cricket::TransportDescriptionFactory()),
336 desc_factory_(
337 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
338 tdesc_factory_.get())),
339 pss_(new rtc::PhysicalSocketServer),
340 vss_(new rtc::VirtualSocketServer(pss_.get())),
341 fss_(new rtc::FirewallSocketServer(vss_.get())),
342 ss_scope_(fss_.get()),
343 stun_socket_addr_(
344 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
345 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
346 stun_socket_addr_)),
347 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
348 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000349 cricket::ServerAddresses stun_servers;
350 stun_servers.insert(stun_socket_addr_);
351 allocator_.reset(new cricket::BasicPortAllocator(
352 &network_manager_,
353 stun_servers,
354 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000355 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700356 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 EXPECT_TRUE(channel_manager_->Init());
358 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000359 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 }
361
362 void AddInterface(const SocketAddress& addr) {
363 network_manager_.AddInterface(addr);
364 }
365
Henrik Boström87713d02015-08-25 09:53:21 +0200366 // If |dtls_identity_store| != null or |rtc_configuration| contains
367 // |certificates| then DTLS will be enabled unless explicitly disabled by
368 // |rtc_configuration| options. When DTLS is enabled a certificate will be
369 // used if provided, otherwise one will be generated using the
370 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000371 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200372 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200373 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000374 ASSERT_TRUE(session_.get() == NULL);
375 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700376 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700377 allocator_.get(), &observer_));
378 session_->SignalDataChannelOpenMessage.connect(
379 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800380 session_->GetOnDestroyedSignal()->connect(
381 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000382
383 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
384 observer_.ice_connection_state_);
385 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
386 observer_.ice_gathering_state_);
387
deadbeefcbecd352015-09-23 11:50:27 -0700388 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
kwiberg0eb15ed2015-12-17 03:04:15 -0800389 std::move(dtls_identity_store),
deadbeefcbecd352015-09-23 11:50:27 -0700390 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700391 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392 }
393
deadbeefab9b2d12015-10-14 11:33:11 -0700394 void OnDataChannelOpenMessage(const std::string& label,
395 const InternalDataChannelInit& config) {
396 last_data_channel_label_ = label;
397 last_data_channel_config_ = config;
398 }
399
deadbeef057ecf02016-01-20 14:30:43 -0800400 void OnSessionDestroyed() { session_destroyed_ = true; }
401
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000402 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200403 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200404 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000405 }
406
407 void InitWithIceTransport(
408 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200409 PeerConnectionInterface::RTCConfiguration configuration;
410 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200411 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000412 }
413
414 void InitWithBundlePolicy(
415 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200416 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200417 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200418 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700419 }
420
421 void InitWithRtcpMuxPolicy(
422 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
423 PeerConnectionInterface::RTCConfiguration configuration;
424 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200425 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000426 }
427
Henrik Boström87713d02015-08-25 09:53:21 +0200428 // Successfully init with DTLS; with a certificate generated and supplied or
429 // with a store that generates it for us.
430 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
431 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
432 PeerConnectionInterface::RTCConfiguration configuration;
433 if (cert_gen_method == ALREADY_GENERATED) {
434 configuration.certificates.push_back(
435 FakeDtlsIdentityStore::GenerateCertificate());
436 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
437 dtls_identity_store.reset(new FakeDtlsIdentityStore());
438 dtls_identity_store->set_should_fail(false);
439 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700440 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200441 }
kwiberg0eb15ed2015-12-17 03:04:15 -0800442 Init(std::move(dtls_identity_store), configuration);
Henrik Boström87713d02015-08-25 09:53:21 +0200443 }
444
445 // Init with DTLS with a store that will fail to generate a certificate.
446 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200447 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
448 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200449 dtls_identity_store->set_should_fail(true);
Henrik Lundin64dad832015-05-11 12:44:23 +0200450 PeerConnectionInterface::RTCConfiguration configuration;
kwiberg0eb15ed2015-12-17 03:04:15 -0800451 Init(std::move(dtls_identity_store), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000452 }
453
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000454 void InitWithDtmfCodec() {
455 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000456 const cricket::AudioCodec kTelephoneEventCodec(
457 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458 std::vector<cricket::AudioCodec> codecs;
459 codecs.push_back(kTelephoneEventCodec);
460 media_engine_->SetAudioCodecs(codecs);
461 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000462 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463 }
464
deadbeefab9b2d12015-10-14 11:33:11 -0700465 void SendAudioVideoStream1() {
466 send_stream_1_ = true;
467 send_stream_2_ = false;
468 send_audio_ = true;
469 send_video_ = true;
470 }
471
472 void SendAudioVideoStream2() {
473 send_stream_1_ = false;
474 send_stream_2_ = true;
475 send_audio_ = true;
476 send_video_ = true;
477 }
478
479 void SendAudioVideoStream1And2() {
480 send_stream_1_ = true;
481 send_stream_2_ = true;
482 send_audio_ = true;
483 send_video_ = true;
484 }
485
486 void SendNothing() {
487 send_stream_1_ = false;
488 send_stream_2_ = false;
489 send_audio_ = false;
490 send_video_ = false;
491 }
492
493 void SendAudioOnlyStream2() {
494 send_stream_1_ = false;
495 send_stream_2_ = true;
496 send_audio_ = true;
497 send_video_ = false;
498 }
499
500 void SendVideoOnlyStream2() {
501 send_stream_1_ = false;
502 send_stream_2_ = true;
503 send_audio_ = false;
504 send_video_ = true;
505 }
506
507 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
508 if (send_stream_1_ && send_audio_) {
509 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
510 kStream1);
511 }
512 if (send_stream_1_ && send_video_) {
513 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
514 kStream1);
515 }
516 if (send_stream_2_ && send_audio_) {
517 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
518 kStream2);
519 }
520 if (send_stream_2_ && send_video_) {
521 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
522 kStream2);
523 }
524 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
525 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
526 data_channel_->label(),
527 data_channel_->label());
528 }
529 }
530
531 void GetOptionsForOffer(
532 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
533 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700534 ASSERT_TRUE(ConvertRtcOptionsForOffer(rtc_options, session_options));
535
deadbeefc80741f2015-10-22 13:14:45 -0700536 AddStreamsToOptions(session_options);
537 if (rtc_options.offer_to_receive_audio ==
538 RTCOfferAnswerOptions::kUndefined) {
539 session_options->recv_audio =
540 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
541 }
542 if (rtc_options.offer_to_receive_video ==
543 RTCOfferAnswerOptions::kUndefined) {
544 session_options->recv_video =
545 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
546 }
547 session_options->bundle_enabled =
548 session_options->bundle_enabled &&
549 (session_options->has_audio() || session_options->has_video() ||
550 session_options->has_data());
551
deadbeefab9b2d12015-10-14 11:33:11 -0700552 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
553 session_options->data_channel_type = cricket::DCT_SCTP;
554 }
555 }
556
557 void GetOptionsForAnswer(const webrtc::MediaConstraintsInterface* constraints,
558 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700559 session_options->recv_audio = false;
560 session_options->recv_video = false;
561 ASSERT_TRUE(ParseConstraintsForAnswer(constraints, session_options));
562
deadbeefc80741f2015-10-22 13:14:45 -0700563 AddStreamsToOptions(session_options);
564 session_options->bundle_enabled =
565 session_options->bundle_enabled &&
566 (session_options->has_audio() || session_options->has_video() ||
567 session_options->has_data());
568
deadbeefab9b2d12015-10-14 11:33:11 -0700569 if (session_->data_channel_type() == cricket::DCT_SCTP) {
570 session_options->data_channel_type = cricket::DCT_SCTP;
571 }
572 }
573
574 // Creates a local offer and applies it. Starts ICE.
575 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576 // to decide which streams to create.
577 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000578 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000579 SetLocalDescriptionWithoutError(offer);
580 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
581 observer_.ice_gathering_state_,
582 kIceCandidatesTimeout);
583 }
584
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000585 SessionDescriptionInterface* CreateOffer() {
586 PeerConnectionInterface::RTCOfferAnswerOptions options;
587 options.offer_to_receive_audio =
588 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
589
590 return CreateOffer(options);
591 }
592
wu@webrtc.org91053e72013-08-10 07:18:04 +0000593 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000594 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000595 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000596 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700597 cricket::MediaSessionOptions session_options;
598 GetOptionsForOffer(options, &session_options);
599 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000600 EXPECT_TRUE_WAIT(
601 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000602 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000603 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000604 }
605
606 SessionDescriptionInterface* CreateAnswer(
607 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000608 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000609 = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700610 cricket::MediaSessionOptions session_options;
611 GetOptionsForAnswer(constraints, &session_options);
612 session_->CreateAnswer(observer, constraints, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000613 EXPECT_TRUE_WAIT(
614 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000615 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000616 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000617 }
618
wu@webrtc.org364f2042013-11-20 21:49:41 +0000619 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000620 return (session_->voice_channel() != NULL &&
621 session_->video_channel() != NULL);
622 }
623
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
625 ASSERT_TRUE(session_.get() != NULL);
626 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
627 ASSERT_TRUE(content != NULL);
628 const cricket::AudioContentDescription* audio_content =
629 static_cast<const cricket::AudioContentDescription*>(
630 content->description);
631 ASSERT_TRUE(audio_content != NULL);
632 ASSERT_EQ(1U, audio_content->cryptos().size());
633 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
634 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
635 audio_content->cryptos()[0].cipher_suite);
636 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
637 audio_content->protocol());
638
639 content = cricket::GetFirstVideoContent(sdp);
640 ASSERT_TRUE(content != NULL);
641 const cricket::VideoContentDescription* video_content =
642 static_cast<const cricket::VideoContentDescription*>(
643 content->description);
644 ASSERT_TRUE(video_content != NULL);
645 ASSERT_EQ(1U, video_content->cryptos().size());
646 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
647 video_content->cryptos()[0].cipher_suite);
648 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
649 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
650 video_content->protocol());
651 }
652
653 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
654 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
655 ASSERT_TRUE(content != NULL);
656 const cricket::AudioContentDescription* audio_content =
657 static_cast<const cricket::AudioContentDescription*>(
658 content->description);
659 ASSERT_TRUE(audio_content != NULL);
660 ASSERT_EQ(0U, audio_content->cryptos().size());
661
662 content = cricket::GetFirstVideoContent(sdp);
663 ASSERT_TRUE(content != NULL);
664 const cricket::VideoContentDescription* video_content =
665 static_cast<const cricket::VideoContentDescription*>(
666 content->description);
667 ASSERT_TRUE(video_content != NULL);
668 ASSERT_EQ(0U, video_content->cryptos().size());
669
670 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700671 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000672 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700673 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000674 video_content->protocol());
675 } else {
676 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
677 audio_content->protocol());
678 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
679 video_content->protocol());
680 }
681 }
682
683 // Set the internal fake description factories to do DTLS-SRTP.
684 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000685 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000687 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200688 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800689 tdesc_factory_->set_certificate(
690 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
691 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
693 }
694
695 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
696 bool expected) {
697 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
698 ASSERT_TRUE(audio != NULL);
699 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 const TransportInfo* video = sdp->GetTransportInfoByName("video");
701 ASSERT_TRUE(video != NULL);
702 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703 }
704
705 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000706 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000708 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000709 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000711 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000713 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
714 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000715 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716 // Answer should be NULL as no crypto params in offer.
717 ASSERT_TRUE(answer == NULL);
718 }
719
720 void VerifyAnswerFromCryptoOffer() {
721 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000722 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723 options.bundle_enabled = true;
724 scoped_ptr<JsepSessionDescription> offer(
725 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
726 ASSERT_TRUE(offer.get() != NULL);
727 VerifyCryptoParams(offer->description());
728 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000729 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 ASSERT_TRUE(answer.get() != NULL);
731 VerifyCryptoParams(answer->description());
732 }
733
734 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
735 const cricket::SessionDescription* desc2,
736 bool expect_equal) {
737 if (desc1->contents().size() != desc2->contents().size()) {
738 EXPECT_FALSE(expect_equal);
739 return;
740 }
741
742 const cricket::ContentInfos& contents = desc1->contents();
743 cricket::ContentInfos::const_iterator it = contents.begin();
744
745 for (; it != contents.end(); ++it) {
746 const cricket::TransportDescription* transport_desc1 =
747 desc1->GetTransportDescriptionByName(it->name);
748 const cricket::TransportDescription* transport_desc2 =
749 desc2->GetTransportDescriptionByName(it->name);
750 if (!transport_desc1 || !transport_desc2) {
751 EXPECT_FALSE(expect_equal);
752 return;
753 }
754 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
755 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
756 EXPECT_FALSE(expect_equal);
757 return;
758 }
759 }
760 EXPECT_TRUE(expect_equal);
761 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000762
763 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
764 std::string *sdp) {
765 const cricket::SessionDescription* desc = current_desc->description();
766 EXPECT_TRUE(current_desc->ToString(sdp));
767
768 const cricket::ContentInfos& contents = desc->contents();
769 cricket::ContentInfos::const_iterator it = contents.begin();
770 // Replace ufrag and pwd lines with empty strings.
771 for (; it != contents.end(); ++it) {
772 const cricket::TransportDescription* transport_desc =
773 desc->GetTransportDescriptionByName(it->name);
774 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
775 + "\r\n";
776 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
777 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000778 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000779 "", 0,
780 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000781 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000782 "", 0,
783 sdp);
784 }
785 }
786
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000787 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
788 const std::string& modified_ice_ufrag,
789 const std::string& modified_ice_pwd,
790 std::string* sdp) {
791 const cricket::SessionDescription* desc = current_desc->description();
792 EXPECT_TRUE(current_desc->ToString(sdp));
793
794 const cricket::ContentInfos& contents = desc->contents();
795 cricket::ContentInfos::const_iterator it = contents.begin();
796 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
797 // |modified_ice_pwd| strings.
798 for (; it != contents.end(); ++it) {
799 const cricket::TransportDescription* transport_desc =
800 desc->GetTransportDescriptionByName(it->name);
801 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
802 + "\r\n";
803 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
804 + "\r\n";
805 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
806 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000807 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000808 mod_ufrag.c_str(), mod_ufrag.length(),
809 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000810 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000811 mod_pwd.c_str(), mod_pwd.length(),
812 sdp);
813 }
814 }
815
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 // Creates a remote offer and and applies it as a remote description,
817 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700818 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 // to decide which local and remote streams to create.
820 void CreateAndSetRemoteOfferAndLocalAnswer() {
821 SessionDescriptionInterface* offer = CreateRemoteOffer();
822 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000823 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 SetLocalDescriptionWithoutError(answer);
825 }
826 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
827 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700828 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829 }
830 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700831 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 SetLocalDescriptionWithoutError(desc);
833 EXPECT_EQ(expected_state, session_->state());
834 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000835 void SetLocalDescriptionExpectError(const std::string& action,
836 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 SessionDescriptionInterface* desc) {
838 std::string error;
839 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000840 std::string sdp_type = "local ";
841 sdp_type.append(action);
842 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 EXPECT_NE(std::string::npos, error.find(expected_error));
844 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000845 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
846 SessionDescriptionInterface* desc) {
847 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
848 expected_error, desc);
849 }
850 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
851 SessionDescriptionInterface* desc) {
852 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
853 expected_error, desc);
854 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
856 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
857 }
858 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700859 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 SetRemoteDescriptionWithoutError(desc);
861 EXPECT_EQ(expected_state, session_->state());
862 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000863 void SetRemoteDescriptionExpectError(const std::string& action,
864 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 SessionDescriptionInterface* desc) {
866 std::string error;
867 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000868 std::string sdp_type = "remote ";
869 sdp_type.append(action);
870 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 EXPECT_NE(std::string::npos, error.find(expected_error));
872 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000873 void SetRemoteDescriptionOfferExpectError(
874 const std::string& expected_error, SessionDescriptionInterface* desc) {
875 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
876 expected_error, desc);
877 }
878 void SetRemoteDescriptionPranswerExpectError(
879 const std::string& expected_error, SessionDescriptionInterface* desc) {
880 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
881 expected_error, desc);
882 }
883 void SetRemoteDescriptionAnswerExpectError(
884 const std::string& expected_error, SessionDescriptionInterface* desc) {
885 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
886 expected_error, desc);
887 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888
889 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
890 SessionDescriptionInterface** nocrypto_answer) {
891 // Create a SDP without Crypto.
892 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000893 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 options.bundle_enabled = true;
895 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
896 ASSERT_TRUE(*offer != NULL);
897 VerifyCryptoParams((*offer)->description());
898
899 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
900 cricket::SEC_DISABLED);
901 EXPECT_TRUE(*nocrypto_answer != NULL);
902 }
903
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000904 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
905 SessionDescriptionInterface** nodtls_answer) {
906 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000907 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000908 options.bundle_enabled = true;
909
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000910 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000911 CreateRemoteOffer(options, cricket::SEC_ENABLED));
912
913 *nodtls_answer =
914 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
915 EXPECT_TRUE(*nodtls_answer != NULL);
916 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
917 VerifyCryptoParams((*nodtls_answer)->description());
918
919 SetFactoryDtlsSrtp();
920 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
921 ASSERT_TRUE(*offer != NULL);
922 VerifyFingerprintStatus((*offer)->description(), true);
923 VerifyCryptoParams((*offer)->description());
924 }
925
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 JsepSessionDescription* CreateRemoteOfferWithVersion(
927 cricket::MediaSessionOptions options,
928 cricket::SecurePolicy secure_policy,
929 const std::string& session_version,
930 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000931 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000932 const cricket::SessionDescription* cricket_desc = NULL;
933 if (current_desc) {
934 cricket_desc = current_desc->description();
935 session_id = current_desc->session_id();
936 }
937
938 desc_factory_->set_secure(secure_policy);
939 JsepSessionDescription* offer(
940 new JsepSessionDescription(JsepSessionDescription::kOffer));
941 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
942 session_id, session_version)) {
943 delete offer;
944 offer = NULL;
945 }
946 return offer;
947 }
948 JsepSessionDescription* CreateRemoteOffer(
949 cricket::MediaSessionOptions options) {
950 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
951 kSessionVersion, NULL);
952 }
953 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000954 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
955 return CreateRemoteOfferWithVersion(
956 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 }
958 JsepSessionDescription* CreateRemoteOffer(
959 cricket::MediaSessionOptions options,
960 const SessionDescriptionInterface* current_desc) {
961 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
962 kSessionVersion, current_desc);
963 }
964
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000965 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
966 const char* sctp_stream_name, int new_port,
967 cricket::MediaSessionOptions options) {
968 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000969 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
970 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000971 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
972 }
973
974 // Takes ownership of offer_basis (and deletes it).
975 JsepSessionDescription* ChangeSDPSctpPort(
976 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
977 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
978 // SessionDescription from the mutated string.
979 const char* default_port_str = "5000";
980 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000981 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000982 std::string offer_str;
983 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000984 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000985 new_port_str, strlen(new_port_str),
986 &offer_str);
987 JsepSessionDescription* offer = new JsepSessionDescription(
988 offer_basis->type());
989 delete offer_basis;
990 offer->Initialize(offer_str, NULL);
991 return offer;
992 }
993
deadbeefab9b2d12015-10-14 11:33:11 -0700994 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995 // before this function to decide which streams to create.
996 JsepSessionDescription* CreateRemoteOffer() {
997 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -0700998 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 return CreateRemoteOffer(options, session_->remote_description());
1000 }
1001
1002 JsepSessionDescription* CreateRemoteAnswer(
1003 const SessionDescriptionInterface* offer,
1004 cricket::MediaSessionOptions options,
1005 cricket::SecurePolicy policy) {
1006 desc_factory_->set_secure(policy);
1007 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001008 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 JsepSessionDescription* answer(
1010 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1011 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1012 options, NULL),
1013 session_id, kSessionVersion)) {
1014 delete answer;
1015 answer = NULL;
1016 }
1017 return answer;
1018 }
1019
1020 JsepSessionDescription* CreateRemoteAnswer(
1021 const SessionDescriptionInterface* offer,
1022 cricket::MediaSessionOptions options) {
1023 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1024 }
1025
deadbeefab9b2d12015-10-14 11:33:11 -07001026 // Creates an answer session description.
1027 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 // to decide which streams to create.
1029 JsepSessionDescription* CreateRemoteAnswer(
1030 const SessionDescriptionInterface* offer) {
1031 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001032 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001033 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1034 }
1035
1036 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001037 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001038 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001039 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001040
1041 PeerConnectionInterface::RTCOfferAnswerOptions options;
1042 options.use_rtp_mux = bundle;
1043
1044 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1046 // and answer.
1047 SetLocalDescriptionWithoutError(offer);
1048
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001049 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001050 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001051 std::string sdp;
1052 EXPECT_TRUE(answer->ToString(&sdp));
1053
1054 size_t expected_candidate_num = 2;
1055 if (!rtcp_mux) {
1056 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1057 // for rtp and rtcp.
1058 expected_candidate_num = 4;
1059 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 const std::string kRtcpMux = "a=rtcp-mux";
1061 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001062 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 kXRtcpMux.c_str(), kXRtcpMux.length(),
1064 &sdp);
1065 }
1066
1067 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1068 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069
1070 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001071 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1073 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001074 if (bundle) {
1075 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1076 } else {
1077 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 }
1079 }
1080 // Tests that we can only send DTMF when the dtmf codec is supported.
1081 void TestCanInsertDtmf(bool can) {
1082 if (can) {
1083 InitWithDtmfCodec();
1084 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001085 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001086 }
deadbeefab9b2d12015-10-14 11:33:11 -07001087 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088 CreateAndSetRemoteOfferAndLocalAnswer();
1089 EXPECT_FALSE(session_->CanInsertDtmf(""));
1090 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1091 }
1092
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001093 // Helper class to configure loopback network and verify Best
1094 // Connection using right IP protocol for TestLoopbackCall
1095 // method. LoopbackNetworkManager applies firewall rules to block
1096 // all ping traffic once ICE completed, and remove them to observe
1097 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1098 // verifies the best connection is using the right IP protocol after
1099 // initial ICE convergences.
1100
1101 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001102 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001103 LoopbackNetworkConfiguration()
1104 : test_ipv6_network_(false),
1105 test_extra_ipv4_network_(false),
1106 best_connection_after_initial_ice_converged_(1, 0) {}
1107
1108 // Used to track the expected best connection count in each IP protocol.
1109 struct ExpectedBestConnection {
1110 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1111 : ipv4_count_(ipv4_count),
1112 ipv6_count_(ipv6_count) {}
1113
1114 int ipv4_count_;
1115 int ipv6_count_;
1116 };
1117
1118 bool test_ipv6_network_;
1119 bool test_extra_ipv4_network_;
1120 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1121
1122 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001123 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001124 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1125 }
1126
1127 private:
jbauchac8869e2015-07-03 01:36:14 -07001128 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001129 const ExpectedBestConnection& expected) const {
1130 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001131 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1132 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001133 expected.ipv4_count_);
1134 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001135 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1136 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001137 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001138 // This is used in the loopback call so there is only single host to host
1139 // candidate pair.
1140 EXPECT_EQ(metrics_observer->GetEnumCounter(
1141 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1142 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001143 0);
1144 EXPECT_EQ(metrics_observer->GetEnumCounter(
1145 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1146 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001147 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001148 }
1149 };
1150
1151 class LoopbackNetworkManager {
1152 public:
1153 LoopbackNetworkManager(WebRtcSessionTest* session,
1154 const LoopbackNetworkConfiguration& config)
1155 : config_(config) {
1156 session->AddInterface(
1157 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1158 if (config_.test_extra_ipv4_network_) {
1159 session->AddInterface(
1160 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1161 }
1162 if (config_.test_ipv6_network_) {
1163 session->AddInterface(
1164 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1165 }
1166 }
1167
1168 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1169 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1170 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1171 if (config_.test_extra_ipv4_network_) {
1172 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1173 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1174 }
1175 if (config_.test_ipv6_network_) {
1176 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1177 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1178 }
1179 }
1180
1181 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1182
1183 private:
1184 LoopbackNetworkConfiguration config_;
1185 };
1186
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001187 // The method sets up a call from the session to itself, in a loopback
1188 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001189 // disconnection, and then a permanent disconnection.
1190 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001191 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1192 // While running the call, this method also checks if the session goes through
1193 // the correct sequence of ICE states when a connection is established,
1194 // broken, and re-established.
1195 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001196 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1197 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001198 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001199
stefanc1aeaf02015-10-15 07:26:07 -07001200 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001201 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001202 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001203 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001204
1205 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1206 observer_.ice_gathering_state_);
1207 SetLocalDescriptionWithoutError(offer);
1208 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1209 observer_.ice_connection_state_);
1210 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001211 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001212 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1213 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001214 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001215
1216 std::string sdp;
1217 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001218 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1219 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001220 ASSERT_TRUE(desc != NULL);
1221 SetRemoteDescriptionWithoutError(desc);
1222
1223 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001224 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001225
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001226 // The ice connection state is "Connected" too briefly to catch in a test.
1227 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001228 observer_.ice_connection_state_, kIceCandidatesTimeout);
1229 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001230
stefanc1aeaf02015-10-15 07:26:07 -07001231 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1232 LoopbackNetworkManager loopback_network_manager(this, config);
1233 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001234 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 // Adding firewall rule to block ping requests, which should cause
1236 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001237
1238 loopback_network_manager.ApplyFirewallRules(fss_.get());
1239
1240 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001241 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1242 observer_.ice_connection_state_,
1243 kIceCandidatesTimeout);
1244
jbauchac8869e2015-07-03 01:36:14 -07001245 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001246
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001247 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001248 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001249
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001250 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001251 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252 observer_.ice_connection_state_,
1253 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001254
1255 // Now we block ping requests and wait until the ICE connection transitions
1256 // to the Failed state. This will take at least 30 seconds because it must
1257 // wait for the Port to timeout.
1258 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001259
1260 loopback_network_manager.ApplyFirewallRules(fss_.get());
1261 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001262 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001263 observer_.ice_connection_state_,
1264 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265 }
1266
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001267 void TestLoopbackCall() {
1268 LoopbackNetworkConfiguration config;
1269 TestLoopbackCall(config);
1270 }
1271
stefanc1aeaf02015-10-15 07:26:07 -07001272 void TestPacketOptions() {
1273 media_controller_.reset(
1274 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1275 LoopbackNetworkConfiguration config;
1276 LoopbackNetworkManager loopback_network_manager(this, config);
1277
1278 SetupLoopbackCall();
1279
1280 uint8_t test_packet[15] = {0};
1281 rtc::PacketOptions options;
1282 options.packet_id = 10;
1283 media_engine_->GetVideoChannel(0)
1284 ->SendRtp(test_packet, sizeof(test_packet), options);
1285
1286 const int kPacketTimeout = 2000;
1287 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1288 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1289 }
1290
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1292 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001293 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1294 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1295
1296 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001297 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1298 codecs.push_back(kCNCodec1);
1299 codecs.push_back(kCNCodec2);
1300 media_engine_->SetAudioCodecs(codecs);
1301 desc_factory_->set_audio_codecs(codecs);
1302 }
1303
1304 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1305 const cricket::ContentDescription* description = content->description;
1306 ASSERT(description != NULL);
1307 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001308 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001309 ASSERT(audio_content_desc != NULL);
1310 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1311 if (audio_content_desc->codecs()[i].name == "CN")
1312 return false;
1313 }
1314 return true;
1315 }
1316
deadbeefab9b2d12015-10-14 11:33:11 -07001317 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001318 webrtc::InternalDataChannelInit dci;
deadbeefab9b2d12015-10-14 11:33:11 -07001319 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1320 data_channel_ = DataChannel::Create(
1321 session_.get(), session_->data_channel_type(), "datachannel", dci);
1322 }
1323
1324 void SetLocalDescriptionWithDataChannel() {
1325 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001326 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327 SetLocalDescriptionWithoutError(offer);
1328 }
1329
wu@webrtc.org91053e72013-08-10 07:18:04 +00001330 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001331 RTCCertificateGenerationMethod cert_gen_method,
1332 CreateSessionDescriptionRequest::Type type) {
1333 InitWithDtls(cert_gen_method);
1334 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1335 }
1336
1337 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1338 CreateSessionDescriptionRequest::Type type) {
1339 InitWithDtlsIdentityGenFail();
1340 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1341 }
1342
1343 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001344 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001345 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001346 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001347 if (type == CreateSessionDescriptionRequest::kAnswer) {
1348 cricket::MediaSessionOptions options;
1349 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001350 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001351 ASSERT_TRUE(offer.get() != NULL);
1352 SetRemoteDescriptionWithoutError(offer.release());
1353 }
1354
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001355 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001356 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001357 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001358 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001359 observers[kNumber];
1360 for (int i = 0; i < kNumber; ++i) {
1361 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1362 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001363 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001364 } else {
deadbeefab9b2d12015-10-14 11:33:11 -07001365 session_->CreateAnswer(observers[i], nullptr, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001366 }
1367 }
1368
1369 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1370 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1371 WebRtcSessionCreateSDPObserverForTest::kFailed;
1372
1373 for (int i = 0; i < kNumber; ++i) {
1374 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1375 if (success) {
1376 EXPECT_TRUE(observers[i]->description() != NULL);
1377 } else {
1378 EXPECT_TRUE(observers[i]->description() == NULL);
1379 }
1380 }
1381 }
1382
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001383 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001384 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001385 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001386 turn_server.credentials = credentials;
1387 turn_server.ports.push_back(
1388 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1389 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001390 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001391 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001392 }
1393
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001394 cricket::FakeMediaEngine* media_engine_;
1395 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001396 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001397 cricket::FakeCall fake_call_;
1398 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001399 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001400 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1401 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1402 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1403 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1404 rtc::SocketServerScope ss_scope_;
1405 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001406 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001407 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001408 rtc::FakeNetworkManager network_manager_;
1409 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001410 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001411 rtc::scoped_ptr<FakeConstraints> constraints_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001412 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413 MockIceObserver observer_;
1414 cricket::FakeVideoMediaChannel* video_channel_;
1415 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001416 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001417 // The following flags affect options created for CreateOffer/CreateAnswer.
1418 bool send_stream_1_ = false;
1419 bool send_stream_2_ = false;
1420 bool send_audio_ = false;
1421 bool send_video_ = false;
1422 rtc::scoped_refptr<DataChannel> data_channel_;
1423 // Last values received from data channel creation signal.
1424 std::string last_data_channel_label_;
1425 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001426 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427};
1428
Henrik Boström87713d02015-08-25 09:53:21 +02001429TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1430 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001431 // SDES is disabled when DTLS is on.
1432 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001433}
1434
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001435TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001436 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001437 // SDES is required if DTLS is off.
1438 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001439}
1440
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1442 TestSessionCandidatesWithBundleRtcpMux(false, false);
1443}
1444
1445// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1446// with rtcp-mux and/or bundle.
1447TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1448 TestSessionCandidatesWithBundleRtcpMux(false, true);
1449}
1450
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1452 TestSessionCandidatesWithBundleRtcpMux(true, true);
1453}
1454
1455TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001456 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1457 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001458 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001459 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001460 InitiateCall();
1461 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1462 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1463 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1464}
1465
minyuec8930ba2016-01-22 06:17:46 -08001466// Crashes on Win only. See webrtc:5411.
1467#if defined(WEBRTC_WIN)
1468#define MAYBE_TestStunError DISABLED_TestStunError
1469#else
1470#define MAYBE_TestStunError TestStunError
1471#endif
1472TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001473 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1474 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001475 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001476 rtc::FP_UDP,
1477 rtc::FD_ANY,
1478 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001479 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001480 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001482 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1484 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1485 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1486}
1487
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001488// Test session delivers no candidates gathered when constraint set to "none".
1489TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1490 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001491 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001492 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001493 InitiateCall();
1494 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1495 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1496 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1497}
1498
1499// Test session delivers only relay candidates gathered when constaint set to
1500// "relay".
1501TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1502 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1503 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001504 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001505 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001506 InitiateCall();
1507 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1508 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1509 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1510 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1511 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1512 observer_.mline_0_candidates_[i].type());
1513 }
1514 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1515 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1516 observer_.mline_1_candidates_[i].type());
1517 }
1518}
1519
1520// Test session delivers all candidates gathered when constaint set to "all".
1521TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1522 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001523 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001524 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001525 InitiateCall();
1526 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1527 // Host + STUN. By default allocator is disabled to gather relay candidates.
1528 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1529 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1530}
1531
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001532TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001533 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001534 SessionDescriptionInterface* offer = NULL;
1535 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1536 std::string unknown_action;
1537 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1538 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1539}
1540
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001541// Test creating offers and receive answers and make sure the
1542// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001543TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001544 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001545 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001546 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547 const std::string session_id_orig = offer->session_id();
1548 const std::string session_version_orig = offer->session_version();
1549 SetLocalDescriptionWithoutError(offer);
1550
deadbeefab9b2d12015-10-14 11:33:11 -07001551 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552 SessionDescriptionInterface* answer =
1553 CreateRemoteAnswer(session_->local_description());
1554 SetRemoteDescriptionWithoutError(answer);
1555
1556 video_channel_ = media_engine_->GetVideoChannel(0);
1557 voice_channel_ = media_engine_->GetVoiceChannel(0);
1558
1559 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1560 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1561
1562 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1563 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1564
1565 ASSERT_EQ(1u, video_channel_->send_streams().size());
1566 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1567 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1568 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1569
1570 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001571 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001572 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573
1574 // Verify the session id is the same and the session version is
1575 // increased.
1576 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001577 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1578 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579
1580 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001581 EXPECT_EQ(0u, video_channel_->send_streams().size());
1582 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583
deadbeefab9b2d12015-10-14 11:33:11 -07001584 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585 answer = CreateRemoteAnswer(session_->local_description());
1586 SetRemoteDescriptionWithoutError(answer);
1587
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588 // Make sure the receive streams have not changed.
1589 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1590 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1591 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1592 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1593}
1594
1595// Test receiving offers and creating answers and make sure the
1596// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001597TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001598 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001599 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001600 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001601 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602 SetRemoteDescriptionWithoutError(offer);
1603
deadbeefab9b2d12015-10-14 11:33:11 -07001604 SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001605 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001606 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 SetLocalDescriptionWithoutError(answer);
1608
1609 const std::string session_id_orig = answer->session_id();
1610 const std::string session_version_orig = answer->session_version();
1611
1612 video_channel_ = media_engine_->GetVideoChannel(0);
1613 voice_channel_ = media_engine_->GetVoiceChannel(0);
1614
1615 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1616 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1617
1618 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1619 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1620
1621 ASSERT_EQ(1u, video_channel_->send_streams().size());
1622 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1623 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1624 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1625
deadbeefab9b2d12015-10-14 11:33:11 -07001626 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001627 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628 SetRemoteDescriptionWithoutError(offer);
1629
1630 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001631 SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001632 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633
1634 // Verify the session id is the same and the session version is
1635 // increased.
1636 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001637 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1638 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 SetLocalDescriptionWithoutError(answer);
1640
1641 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1642 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1643 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1644 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1645 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1646 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1647
1648 // Make sure we have no send streams.
1649 EXPECT_EQ(0u, video_channel_->send_streams().size());
1650 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1651}
1652
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001653TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001654 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001655 media_engine_->set_fail_create_channel(true);
1656
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001657 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001658 ASSERT_TRUE(offer != NULL);
1659 // SetRemoteDescription and SetLocalDescription will take the ownership of
1660 // the offer.
1661 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001662 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001663 ASSERT_TRUE(offer != NULL);
1664 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1665}
1666
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001667//
1668// Tests for creating/setting SDP under different SDES/DTLS polices:
1669//
1670// --DTLS off and SDES on
1671// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1672// set local/remote offer/answer with crypto --> success
1673// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1674// failure
1675// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1676// failure
1677// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1678// failure
1679//
1680// --DTLS on and SDES off
1681// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1682// set local/remote offer/answer with DTLS fingerprint --> success
1683// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1684// fingerprint --> failure
1685// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1686// --> failure
1687// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1688// --> failure
1689//
1690// --Encryption disabled: DTLS off and SDES off
1691// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1692// answer without SDES or DTLS --> success
1693// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1694// answer without SDES or DTLS --> success
1695//
1696
1697// Test that we return a failure when applying a remote/local offer that doesn't
1698// have cryptos enabled when DTLS is off.
1699TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001700 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001701 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001702 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 JsepSessionDescription* offer = CreateRemoteOffer(
1704 options, cricket::SEC_DISABLED);
1705 ASSERT_TRUE(offer != NULL);
1706 VerifyNoCryptoParams(offer->description(), false);
1707 // SetRemoteDescription and SetLocalDescription will take the ownership of
1708 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001709 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1711 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001712 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713}
1714
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001715// Test that we return a failure when applying a local answer that doesn't have
1716// cryptos enabled when DTLS is off.
1717TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001718 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719 SessionDescriptionInterface* offer = NULL;
1720 SessionDescriptionInterface* answer = NULL;
1721 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1722 // SetRemoteDescription and SetLocalDescription will take the ownership of
1723 // the offer.
1724 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001725 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726}
1727
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001728// Test we will return fail when apply an remote answer that doesn't have
1729// crypto enabled when DTLS is off.
1730TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001731 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732 SessionDescriptionInterface* offer = NULL;
1733 SessionDescriptionInterface* answer = NULL;
1734 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1735 // SetRemoteDescription and SetLocalDescription will take the ownership of
1736 // the offer.
1737 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001738 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739}
1740
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001741// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1742// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001743TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001744 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001745 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001746 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747 SetFactoryDtlsSrtp();
1748 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001749 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001750 JsepSessionDescription* offer =
1751 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 ASSERT_TRUE(offer != NULL);
1753 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001754 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755
1756 // SetRemoteDescription will take the ownership of the offer.
1757 SetRemoteDescriptionWithoutError(offer);
1758
1759 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001760 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 ASSERT_TRUE(answer != NULL);
1762 VerifyFingerprintStatus(answer->description(), true);
1763 // Check that we don't have an a=crypto line in the answer.
1764 VerifyNoCryptoParams(answer->description(), true);
1765
1766 // Now set the local description, which should work, even without a=crypto.
1767 SetLocalDescriptionWithoutError(answer);
1768}
1769
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001770// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1771// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001772TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001773 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001774 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001775 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001776 SetFactoryDtlsSrtp();
1777
1778 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001779 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001780 ASSERT_TRUE(offer != NULL);
1781 VerifyFingerprintStatus(offer->description(), true);
1782 // Check that we don't have an a=crypto line in the offer.
1783 VerifyNoCryptoParams(offer->description(), true);
1784
1785 // Now set the local description, which should work, even without a=crypto.
1786 SetLocalDescriptionWithoutError(offer);
1787
1788 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001789 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001790 JsepSessionDescription* answer =
1791 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1792 ASSERT_TRUE(answer != NULL);
1793 VerifyFingerprintStatus(answer->description(), true);
1794 VerifyNoCryptoParams(answer->description(), true);
1795
1796 // SetRemoteDescription will take the ownership of the answer.
1797 SetRemoteDescriptionWithoutError(answer);
1798}
1799
1800// Test that if we support DTLS and the other side didn't offer a fingerprint,
1801// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001802TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001803 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001804 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001806 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001807 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 JsepSessionDescription* offer = CreateRemoteOffer(
1809 options, cricket::SEC_REQUIRED);
1810 ASSERT_TRUE(offer != NULL);
1811 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001812 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001814 // SetRemoteDescription will take the ownership of the offer.
1815 SetRemoteDescriptionOfferExpectError(
1816 kSdpWithoutDtlsFingerprint, offer);
1817
1818 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1819 // SetLocalDescription will take the ownership of the offer.
1820 SetLocalDescriptionOfferExpectError(
1821 kSdpWithoutDtlsFingerprint, offer);
1822}
1823
1824// Test that we return a failure when applying a local answer that doesn't have
1825// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001826TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001827 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001828 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001829 SessionDescriptionInterface* offer = NULL;
1830 SessionDescriptionInterface* answer = NULL;
1831 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1832
1833 // SetRemoteDescription and SetLocalDescription will take the ownership of
1834 // the offer and answer.
1835 SetRemoteDescriptionWithoutError(offer);
1836 SetLocalDescriptionAnswerExpectError(
1837 kSdpWithoutDtlsFingerprint, answer);
1838}
1839
1840// Test that we return a failure when applying a remote answer that doesn't have
1841// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001842TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001843 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001844 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001845 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001846 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001847 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001848 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1849 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001850 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001851 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001852
1853 // SetRemoteDescription and SetLocalDescription will take the ownership of
1854 // the offer and answer.
1855 SetLocalDescriptionWithoutError(offer);
1856 SetRemoteDescriptionAnswerExpectError(
1857 kSdpWithoutDtlsFingerprint, answer);
1858}
1859
1860// Test that we create a local offer without SDES or DTLS and accept a remote
1861// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001862TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001863 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001864 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001865 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001866
1867 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001868 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001869 ASSERT_TRUE(offer != NULL);
1870 VerifyFingerprintStatus(offer->description(), false);
1871 // Check that we don't have an a=crypto line in the offer.
1872 VerifyNoCryptoParams(offer->description(), false);
1873
1874 // Now set the local description, which should work, even without a=crypto.
1875 SetLocalDescriptionWithoutError(offer);
1876
1877 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001878 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001879 JsepSessionDescription* answer =
1880 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1881 ASSERT_TRUE(answer != NULL);
1882 VerifyFingerprintStatus(answer->description(), false);
1883 VerifyNoCryptoParams(answer->description(), false);
1884
1885 // SetRemoteDescription will take the ownership of the answer.
1886 SetRemoteDescriptionWithoutError(answer);
1887}
1888
1889// Test that we create a local answer without SDES or DTLS and accept a remote
1890// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001891TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001892 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001893 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001894
1895 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001896 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001897 JsepSessionDescription* offer =
1898 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1899 ASSERT_TRUE(offer != NULL);
1900 VerifyFingerprintStatus(offer->description(), false);
1901 VerifyNoCryptoParams(offer->description(), false);
1902
1903 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 SetRemoteDescriptionWithoutError(offer);
1905
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001906 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001907 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 ASSERT_TRUE(answer != NULL);
1909 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001910 // Check that we don't have an a=crypto line in the answer.
1911 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001913 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914 SetLocalDescriptionWithoutError(answer);
1915}
1916
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001917// Test that we can create and set an answer correctly when different
1918// SSL roles have been negotiated for different transports.
1919// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1920TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1921 SendAudioVideoStream1();
1922 InitWithDtls(GetParam());
1923 SetFactoryDtlsSrtp();
1924
1925 SessionDescriptionInterface* offer = CreateOffer();
1926 SetLocalDescriptionWithoutError(offer);
1927
1928 cricket::MediaSessionOptions options;
1929 options.recv_video = true;
1930
1931 // First, negotiate different SSL roles.
1932 SessionDescriptionInterface* answer =
1933 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1934 TransportInfo* audio_transport_info =
1935 answer->description()->GetTransportInfoByName("audio");
1936 audio_transport_info->description.connection_role =
1937 cricket::CONNECTIONROLE_ACTIVE;
1938 TransportInfo* video_transport_info =
1939 answer->description()->GetTransportInfoByName("video");
1940 video_transport_info->description.connection_role =
1941 cricket::CONNECTIONROLE_PASSIVE;
1942 SetRemoteDescriptionWithoutError(answer);
1943
1944 // Now create an offer in the reverse direction, and ensure the initial
1945 // offerer responds with an answer with correct SSL roles.
1946 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1947 kSessionVersion,
1948 session_->remote_description());
1949 SetRemoteDescriptionWithoutError(offer);
1950
1951 answer = CreateAnswer(nullptr);
1952 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1953 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1954 audio_transport_info->description.connection_role);
1955 video_transport_info = answer->description()->GetTransportInfoByName("video");
1956 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1957 video_transport_info->description.connection_role);
1958 SetLocalDescriptionWithoutError(answer);
1959
1960 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1961 // audio is transferred over to video in the answer that completes the BUNDLE
1962 // negotiation.
1963 options.bundle_enabled = true;
1964 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1965 kSessionVersion,
1966 session_->remote_description());
1967 SetRemoteDescriptionWithoutError(offer);
1968 answer = CreateAnswer(nullptr);
1969 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1970 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1971 audio_transport_info->description.connection_role);
1972 video_transport_info = answer->description()->GetTransportInfoByName("video");
1973 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1974 video_transport_info->description.connection_role);
1975 SetLocalDescriptionWithoutError(answer);
1976}
1977
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001979 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001980 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001982 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 SetLocalDescriptionWithoutError(offer);
1984
1985 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001986 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987 SetLocalDescriptionWithoutError(offer2);
1988}
1989
1990TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001991 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001992 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001993 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001994 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995 SetRemoteDescriptionWithoutError(offer);
1996
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001997 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 SetRemoteDescriptionWithoutError(offer2);
1999}
2000
2001TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002002 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002003 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002004 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002006 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002007 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2008 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009}
2010
2011TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002012 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002013 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002014 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002016 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002017 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002018 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019}
2020
2021TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002022 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002023 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002025 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002026
2027 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002028 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002029 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002030 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031
deadbeefab9b2d12015-10-14 11:33:11 -07002032 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002034 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2036
deadbeefd59daf82015-10-14 15:02:44 -07002037 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038
deadbeefab9b2d12015-10-14 11:33:11 -07002039 SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002040 SessionDescriptionInterface* answer = CreateAnswer(NULL);
deadbeefd59daf82015-10-14 15:02:44 -07002041 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042}
2043
2044TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002045 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002046 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002047 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002048 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049
2050 JsepSessionDescription* pranswer =
2051 CreateRemoteAnswer(session_->local_description());
2052 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2053
2054 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002055 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056
deadbeefab9b2d12015-10-14 11:33:11 -07002057 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 JsepSessionDescription* pranswer2 =
2059 CreateRemoteAnswer(session_->local_description());
2060 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2061
2062 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002063 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064
deadbeefab9b2d12015-10-14 11:33:11 -07002065 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002066 SessionDescriptionInterface* answer =
2067 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002068 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069}
2070
2071TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002072 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002073 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002074 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2075
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002076 SessionDescriptionInterface* answer =
2077 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002078 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2079 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080}
2081
2082TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002083 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002084 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002085 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2086
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087 SessionDescriptionInterface* answer =
2088 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002089 SetRemoteDescriptionAnswerExpectError(
2090 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091}
2092
2093TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002094 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002095 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096
2097 cricket::Candidate candidate;
2098 candidate.set_component(1);
2099 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2100
deadbeefd59daf82015-10-14 15:02:44 -07002101 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2103
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002104 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002106
2107 // Fail since we have not set a remote description.
2108 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109
2110 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2111 session_->local_description());
2112 SetRemoteDescriptionWithoutError(answer);
2113
deadbeefd59daf82015-10-14 15:02:44 -07002114 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2115 candidate.set_component(2);
2116 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2117 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2118
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119 // Verifying the candidates are copied properly from internal vector.
2120 const SessionDescriptionInterface* remote_desc =
2121 session_->remote_description();
2122 ASSERT_TRUE(remote_desc != NULL);
2123 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2124 const IceCandidateCollection* candidates =
2125 remote_desc->candidates(kMediaContentIndex0);
2126 ASSERT_EQ(2u, candidates->count());
2127 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2128 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2129 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2130 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2131
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002132 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2133 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 candidate.set_component(2);
2135 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2136 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002137 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138
2139 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2140 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2141}
2142
2143// Test that a remote candidate is added to the remote session description and
2144// that it is retained if the remote session description is changed.
2145TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002146 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147 cricket::Candidate candidate1;
2148 candidate1.set_component(1);
2149 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2150 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002151 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 CreateAndSetRemoteOfferAndLocalAnswer();
2153
2154 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2155 const SessionDescriptionInterface* remote_desc =
2156 session_->remote_description();
2157 ASSERT_TRUE(remote_desc != NULL);
2158 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2159 const IceCandidateCollection* candidates =
2160 remote_desc->candidates(kMediaContentIndex0);
2161 ASSERT_EQ(1u, candidates->count());
2162 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2163
2164 // Update the RemoteSessionDescription with a new session description and
2165 // a candidate and check that the new remote session description contains both
2166 // candidates.
2167 SessionDescriptionInterface* offer = CreateRemoteOffer();
2168 cricket::Candidate candidate2;
2169 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2170 candidate2);
2171 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2172 SetRemoteDescriptionWithoutError(offer);
2173
2174 remote_desc = session_->remote_description();
2175 ASSERT_TRUE(remote_desc != NULL);
2176 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2177 candidates = remote_desc->candidates(kMediaContentIndex0);
2178 ASSERT_EQ(2u, candidates->count());
2179 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2180 // Username and password have be updated with the TransportInfo of the
2181 // SessionDescription, won't be equal to the original one.
2182 candidate2.set_username(candidates->at(0)->candidate().username());
2183 candidate2.set_password(candidates->at(0)->candidate().password());
2184 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2185 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2186 // No need to verify the username and password.
2187 candidate1.set_username(candidates->at(1)->candidate().username());
2188 candidate1.set_password(candidates->at(1)->candidate().password());
2189 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2190
2191 // Test that the candidate is ignored if we can add the same candidate again.
2192 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2193}
2194
2195// Test that local candidates are added to the local session description and
2196// that they are retained if the local session description is changed.
2197TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002198 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002199 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002200 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201 CreateAndSetRemoteOfferAndLocalAnswer();
2202
2203 const SessionDescriptionInterface* local_desc = session_->local_description();
2204 const IceCandidateCollection* candidates =
2205 local_desc->candidates(kMediaContentIndex0);
2206 ASSERT_TRUE(candidates != NULL);
2207 EXPECT_EQ(0u, candidates->count());
2208
2209 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2210
2211 local_desc = session_->local_description();
2212 candidates = local_desc->candidates(kMediaContentIndex0);
2213 ASSERT_TRUE(candidates != NULL);
2214 EXPECT_LT(0u, candidates->count());
2215 candidates = local_desc->candidates(1);
2216 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002217 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218
2219 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002220 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221 CreateAndSetRemoteOfferAndLocalAnswer();
2222
2223 local_desc = session_->local_description();
2224 candidates = local_desc->candidates(kMediaContentIndex0);
2225 ASSERT_TRUE(candidates != NULL);
2226 EXPECT_LT(0u, candidates->count());
2227 candidates = local_desc->candidates(1);
2228 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002229 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230}
2231
2232// Test that we can set a remote session description with remote candidates.
2233TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002234 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235
2236 cricket::Candidate candidate1;
2237 candidate1.set_component(1);
2238 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2239 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002240 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002241 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242
2243 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2244 SetRemoteDescriptionWithoutError(offer);
2245
2246 const SessionDescriptionInterface* remote_desc =
2247 session_->remote_description();
2248 ASSERT_TRUE(remote_desc != NULL);
2249 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2250 const IceCandidateCollection* candidates =
2251 remote_desc->candidates(kMediaContentIndex0);
2252 ASSERT_EQ(1u, candidates->count());
2253 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2254
wu@webrtc.org91053e72013-08-10 07:18:04 +00002255 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256 SetLocalDescriptionWithoutError(answer);
2257}
2258
2259// Test that offers and answers contains ice candidates when Ice candidates have
2260// been gathered.
2261TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002262 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002263 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002264 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002265 // Ice is started but candidates are not provided until SetLocalDescription
2266 // is called.
2267 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2268 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2269 CreateAndSetRemoteOfferAndLocalAnswer();
2270 // Wait until at least one local candidate has been collected.
2271 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2272 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002273
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002274 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2275
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2277 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278
2279 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2280 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002281 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002282 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2283 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284 SetLocalDescriptionWithoutError(answer);
2285}
2286
2287// Verifies TransportProxy and media channels are created with content names
2288// present in the SessionDescription.
2289TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002290 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002291 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002292 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002293
2294 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002295 // "video". Goal is to modify these content names and verify transport
2296 // channels
2297 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298 // present in SDP.
2299 std::string sdp;
2300 EXPECT_TRUE(offer->ToString(&sdp));
2301 const std::string kAudioMid = "a=mid:audio";
2302 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2303 const std::string kVideoMid = "a=mid:video";
2304 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2305
2306 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002307 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002308 kAudioMidReplaceStr.c_str(),
2309 kAudioMidReplaceStr.length(),
2310 &sdp);
2311 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002312 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002313 kVideoMidReplaceStr.c_str(),
2314 kVideoMidReplaceStr.length(),
2315 &sdp);
2316
2317 SessionDescriptionInterface* modified_offer =
2318 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2319
2320 SetRemoteDescriptionWithoutError(modified_offer);
2321
2322 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002323 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 SetLocalDescriptionWithoutError(answer);
2325
deadbeefcbecd352015-09-23 11:50:27 -07002326 cricket::TransportChannel* voice_transport_channel =
2327 session_->voice_rtp_transport_channel();
2328 EXPECT_TRUE(voice_transport_channel != NULL);
2329 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2330 cricket::TransportChannel* video_transport_channel =
2331 session_->video_rtp_transport_channel();
2332 EXPECT_TRUE(video_transport_channel != NULL);
2333 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002334 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2335 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2336}
2337
2338// Test that an offer contains the correct media content descriptions based on
2339// the send streams when no constraints have been set.
2340TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002341 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002342 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2343
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002344 ASSERT_TRUE(offer != NULL);
2345 const cricket::ContentInfo* content =
2346 cricket::GetFirstAudioContent(offer->description());
2347 EXPECT_TRUE(content != NULL);
2348 content = cricket::GetFirstVideoContent(offer->description());
2349 EXPECT_TRUE(content == NULL);
2350}
2351
2352// Test that an offer contains the correct media content descriptions based on
2353// the send streams when no constraints have been set.
2354TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002355 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002356 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002357 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002358 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2359
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360 const cricket::ContentInfo* content =
2361 cricket::GetFirstAudioContent(offer->description());
2362 EXPECT_TRUE(content != NULL);
2363 content = cricket::GetFirstVideoContent(offer->description());
2364 EXPECT_TRUE(content == NULL);
2365
2366 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002367 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002368 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 content = cricket::GetFirstAudioContent(offer->description());
2370 EXPECT_TRUE(content != NULL);
2371 content = cricket::GetFirstVideoContent(offer->description());
2372 EXPECT_TRUE(content != NULL);
2373}
2374
2375// Test that an offer contains no media content descriptions if
2376// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2377TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002378 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002379 PeerConnectionInterface::RTCOfferAnswerOptions options;
2380 options.offer_to_receive_audio = 0;
2381 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002383 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002384 CreateOffer(options));
2385
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386 ASSERT_TRUE(offer != NULL);
2387 const cricket::ContentInfo* content =
2388 cricket::GetFirstAudioContent(offer->description());
2389 EXPECT_TRUE(content == NULL);
2390 content = cricket::GetFirstVideoContent(offer->description());
2391 EXPECT_TRUE(content == NULL);
2392}
2393
2394// Test that an offer contains only audio media content descriptions if
2395// kOfferToReceiveAudio constraints are set to true.
2396TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002397 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002398 PeerConnectionInterface::RTCOfferAnswerOptions options;
2399 options.offer_to_receive_audio =
2400 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2401
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002402 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002403 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404
2405 const cricket::ContentInfo* content =
2406 cricket::GetFirstAudioContent(offer->description());
2407 EXPECT_TRUE(content != NULL);
2408 content = cricket::GetFirstVideoContent(offer->description());
2409 EXPECT_TRUE(content == NULL);
2410}
2411
2412// Test that an offer contains audio and video media content descriptions if
2413// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2414TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002415 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002417 PeerConnectionInterface::RTCOfferAnswerOptions options;
2418 options.offer_to_receive_audio =
2419 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2420 options.offer_to_receive_video =
2421 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2422
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002423 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002424 CreateOffer(options));
2425
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426 const cricket::ContentInfo* content =
2427 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002428 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002429
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430 content = cricket::GetFirstVideoContent(offer->description());
2431 EXPECT_TRUE(content != NULL);
2432
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002433 // Sets constraints to false and verifies that audio/video contents are
2434 // removed.
2435 options.offer_to_receive_audio = 0;
2436 options.offer_to_receive_video = 0;
2437 offer.reset(CreateOffer(options));
2438
2439 content = cricket::GetFirstAudioContent(offer->description());
2440 EXPECT_TRUE(content == NULL);
2441 content = cricket::GetFirstVideoContent(offer->description());
2442 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002443}
2444
2445// Test that an answer can not be created if the last remote description is not
2446// an offer.
2447TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002448 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002449 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002450 SetLocalDescriptionWithoutError(offer);
2451 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2452 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002453 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002454}
2455
2456// Test that an answer contains the correct media content descriptions when no
2457// constraints have been set.
2458TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002459 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002461 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002463 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002464 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465 const cricket::ContentInfo* content =
2466 cricket::GetFirstAudioContent(answer->description());
2467 ASSERT_TRUE(content != NULL);
2468 EXPECT_FALSE(content->rejected);
2469
2470 content = cricket::GetFirstVideoContent(answer->description());
2471 ASSERT_TRUE(content != NULL);
2472 EXPECT_FALSE(content->rejected);
2473}
2474
2475// Test that an answer contains the correct media content descriptions when no
2476// constraints have been set and the offer only contain audio.
2477TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002478 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002479 // Create a remote offer with audio only.
2480 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002481
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002482 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002483 CreateRemoteOffer(options));
2484 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2485 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2486
2487 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002488 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002489 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002490 const cricket::ContentInfo* content =
2491 cricket::GetFirstAudioContent(answer->description());
2492 ASSERT_TRUE(content != NULL);
2493 EXPECT_FALSE(content->rejected);
2494
2495 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2496}
2497
2498// Test that an answer contains the correct media content descriptions when no
2499// constraints have been set.
2500TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002501 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002503 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002504 SetRemoteDescriptionWithoutError(offer.release());
2505 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002506 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002507 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002508 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002509 const cricket::ContentInfo* content =
2510 cricket::GetFirstAudioContent(answer->description());
2511 ASSERT_TRUE(content != NULL);
2512 EXPECT_FALSE(content->rejected);
2513
2514 content = cricket::GetFirstVideoContent(answer->description());
2515 ASSERT_TRUE(content != NULL);
2516 EXPECT_FALSE(content->rejected);
2517}
2518
2519// Test that an answer contains the correct media content descriptions when
2520// constraints have been set but no stream is sent.
2521TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002522 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002523 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002524 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525 SetRemoteDescriptionWithoutError(offer.release());
2526
2527 webrtc::FakeConstraints constraints_no_receive;
2528 constraints_no_receive.SetMandatoryReceiveAudio(false);
2529 constraints_no_receive.SetMandatoryReceiveVideo(false);
2530
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002531 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002532 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002533 const cricket::ContentInfo* content =
2534 cricket::GetFirstAudioContent(answer->description());
2535 ASSERT_TRUE(content != NULL);
2536 EXPECT_TRUE(content->rejected);
2537
2538 content = cricket::GetFirstVideoContent(answer->description());
2539 ASSERT_TRUE(content != NULL);
2540 EXPECT_TRUE(content->rejected);
2541}
2542
2543// Test that an answer contains the correct media content descriptions when
2544// constraints have been set and streams are sent.
2545TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002546 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002548 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549 SetRemoteDescriptionWithoutError(offer.release());
2550
2551 webrtc::FakeConstraints constraints_no_receive;
2552 constraints_no_receive.SetMandatoryReceiveAudio(false);
2553 constraints_no_receive.SetMandatoryReceiveVideo(false);
2554
2555 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002556 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002557 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002558 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559
2560 // TODO(perkj): Should the direction be set to SEND_ONLY?
2561 const cricket::ContentInfo* content =
2562 cricket::GetFirstAudioContent(answer->description());
2563 ASSERT_TRUE(content != NULL);
2564 EXPECT_FALSE(content->rejected);
2565
2566 // TODO(perkj): Should the direction be set to SEND_ONLY?
2567 content = cricket::GetFirstVideoContent(answer->description());
2568 ASSERT_TRUE(content != NULL);
2569 EXPECT_FALSE(content->rejected);
2570}
2571
2572TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2573 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002574 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002575 PeerConnectionInterface::RTCOfferAnswerOptions options;
2576 options.offer_to_receive_audio =
2577 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2578 options.voice_activity_detection = false;
2579
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002580 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002581 CreateOffer(options));
2582
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002583 const cricket::ContentInfo* content =
2584 cricket::GetFirstAudioContent(offer->description());
2585 EXPECT_TRUE(content != NULL);
2586 EXPECT_TRUE(VerifyNoCNCodecs(content));
2587}
2588
2589TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2590 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002591 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002592 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002593 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002594 SetRemoteDescriptionWithoutError(offer.release());
2595
2596 webrtc::FakeConstraints constraints;
2597 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002598 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002599 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600 const cricket::ContentInfo* content =
2601 cricket::GetFirstAudioContent(answer->description());
2602 ASSERT_TRUE(content != NULL);
2603 EXPECT_TRUE(VerifyNoCNCodecs(content));
2604}
2605
2606// This test verifies the call setup when remote answer with audio only and
2607// later updates with video.
2608TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002609 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002610 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2611 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2612
deadbeefab9b2d12015-10-14 11:33:11 -07002613 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002614 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002615
2616 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002617 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2618
2619 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2620 // and answer;
2621 SetLocalDescriptionWithoutError(offer);
2622 SetRemoteDescriptionWithoutError(answer);
2623
2624 video_channel_ = media_engine_->GetVideoChannel(0);
2625 voice_channel_ = media_engine_->GetVoiceChannel(0);
2626
2627 ASSERT_TRUE(video_channel_ == NULL);
2628
2629 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2630 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2631 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2632
2633 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002634 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002635 CreateAndSetRemoteOfferAndLocalAnswer();
2636
2637 video_channel_ = media_engine_->GetVideoChannel(0);
2638 voice_channel_ = media_engine_->GetVoiceChannel(0);
2639
2640 ASSERT_TRUE(video_channel_ != NULL);
2641 ASSERT_TRUE(voice_channel_ != NULL);
2642
2643 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2644 ASSERT_EQ(1u, video_channel_->send_streams().size());
2645 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2646 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2647 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2648 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2649 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2650 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2651
2652 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002653 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654 CreateAndSetRemoteOfferAndLocalAnswer();
2655
2656 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2657 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2658 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2659 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2660 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2661}
2662
2663// This test verifies the call setup when remote answer with video only and
2664// later updates with audio.
2665TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002666 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002667 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2668 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002669 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002670 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002671
2672 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002673 options.recv_audio = false;
2674 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002675 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2676 offer, options, cricket::SEC_ENABLED);
2677
2678 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2679 // and answer.
2680 SetLocalDescriptionWithoutError(offer);
2681 SetRemoteDescriptionWithoutError(answer);
2682
2683 video_channel_ = media_engine_->GetVideoChannel(0);
2684 voice_channel_ = media_engine_->GetVoiceChannel(0);
2685
2686 ASSERT_TRUE(voice_channel_ == NULL);
2687 ASSERT_TRUE(video_channel_ != NULL);
2688
2689 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2690 ASSERT_EQ(1u, video_channel_->send_streams().size());
2691 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2692
2693 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002694 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002695 CreateAndSetRemoteOfferAndLocalAnswer();
2696
2697 voice_channel_ = media_engine_->GetVoiceChannel(0);
2698 ASSERT_TRUE(voice_channel_ != NULL);
2699
2700 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2701 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2702 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2703 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2704
2705 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002706 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002707 CreateAndSetRemoteOfferAndLocalAnswer();
2708
2709 video_channel_ = media_engine_->GetVideoChannel(0);
2710 voice_channel_ = media_engine_->GetVoiceChannel(0);
2711
2712 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2713 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2714 ASSERT_EQ(1u, video_channel_->send_streams().size());
2715 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2716}
2717
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002719 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002720 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002721 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002722 VerifyCryptoParams(offer->description());
2723 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002724 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725 VerifyCryptoParams(answer->description());
2726}
2727
2728TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002729 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002730 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002731 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002732 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002733 VerifyNoCryptoParams(offer->description(), false);
2734}
2735
2736TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002737 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002738 VerifyAnswerFromNonCryptoOffer();
2739}
2740
2741TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002742 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002743 VerifyAnswerFromCryptoOffer();
2744}
2745
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002746// This test verifies that setLocalDescription fails if
2747// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2748TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002749 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002750 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002751 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2752
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002753 std::string sdp;
2754 RemoveIceUfragPwdLines(offer.get(), &sdp);
2755 SessionDescriptionInterface* modified_offer =
2756 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002757 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002758}
2759
2760// This test verifies that setRemoteDescription fails if
2761// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2762TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002763 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002764 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002765 std::string sdp;
2766 RemoveIceUfragPwdLines(offer.get(), &sdp);
2767 SessionDescriptionInterface* modified_offer =
2768 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002769 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002770}
2771
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002772// This test verifies that setLocalDescription fails if local offer has
2773// too short ice ufrag and pwd strings.
2774TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002775 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002776 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002777 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2778
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002779 std::string sdp;
2780 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2781 // recommended values of 4 and 22 bytes respectively.
2782 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2783 SessionDescriptionInterface* modified_offer =
2784 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2785 std::string error;
2786 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2787
2788 // Test with string greater than 256.
2789 sdp.clear();
2790 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2791 &sdp);
2792 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2793 NULL);
2794 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2795}
2796
2797// This test verifies that setRemoteDescription fails if remote offer has
2798// too short ice ufrag and pwd strings.
2799TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002800 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002801 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002802 std::string sdp;
2803 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2804 // recommended values of 4 and 22 bytes respectively.
2805 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2806 SessionDescriptionInterface* modified_offer =
2807 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2808 std::string error;
2809 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2810
2811 sdp.clear();
2812 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2813 &sdp);
2814 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2815 NULL);
2816 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2817}
2818
Honghai Zhang04e91462015-12-11 14:26:22 -08002819// Test that if the remote offer indicates the peer requested ICE restart (via
2820// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2821TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002822 Init();
2823 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2824
2825 // Create the first offer.
2826 std::string sdp;
2827 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2828 "abcdefghijklmnopqrstuvwx", &sdp);
2829 SessionDescriptionInterface* offer1 =
2830 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2831 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2832 0, "", "", "relay", 0, "");
2833 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2834 candidate1);
2835 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2836 SetRemoteDescriptionWithoutError(offer1);
2837 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2838
2839 // The second offer has the same ufrag and pwd but different address.
2840 sdp.clear();
2841 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2842 "abcdefghijklmnopqrstuvwx", &sdp);
2843 SessionDescriptionInterface* offer2 =
2844 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2845 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2846 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2847 candidate1);
2848 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2849 SetRemoteDescriptionWithoutError(offer2);
2850 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2851
2852 // The third offer has a different ufrag and different address.
2853 sdp.clear();
2854 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2855 "abcdefghijklmnopqrstuvwx", &sdp);
2856 SessionDescriptionInterface* offer3 =
2857 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2858 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2859 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2860 candidate1);
2861 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2862 SetRemoteDescriptionWithoutError(offer3);
2863 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2864
2865 // The fourth offer has no candidate but a different ufrag/pwd.
2866 sdp.clear();
2867 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2868 "abcdefghijklmnopqrstuvyz", &sdp);
2869 SessionDescriptionInterface* offer4 =
2870 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2871 SetRemoteDescriptionWithoutError(offer4);
2872 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2873}
2874
Honghai Zhang04e91462015-12-11 14:26:22 -08002875// Test that if the remote answer indicates the peer requested ICE restart (via
2876// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2877TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2878 Init();
2879 SessionDescriptionInterface* offer = CreateOffer();
2880 SetLocalDescriptionWithoutError(offer);
2881 scoped_ptr<SessionDescriptionInterface> answer(CreateRemoteAnswer(offer));
2882
2883 // Create the first answer.
2884 std::string sdp;
2885 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2886 "abcdefghijklmnopqrstuvwx", &sdp);
2887 SessionDescriptionInterface* answer1 =
2888 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2889 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2890 0, "", "", "relay", 0, "");
2891 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2892 candidate1);
2893 EXPECT_TRUE(answer1->AddCandidate(&ice_candidate1));
2894 SetRemoteDescriptionWithoutError(answer1);
2895 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2896
2897 // The second answer has the same ufrag and pwd but different address.
2898 sdp.clear();
2899 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2900 "abcdefghijklmnopqrstuvwx", &sdp);
2901 SessionDescriptionInterface* answer2 =
2902 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2903 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2904 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2905 candidate1);
2906 EXPECT_TRUE(answer2->AddCandidate(&ice_candidate2));
2907 SetRemoteDescriptionWithoutError(answer2);
2908 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2909
2910 // The third answer has a different ufrag and different address.
2911 sdp.clear();
2912 ModifyIceUfragPwdLines(answer.get(), "0123456789012333",
2913 "abcdefghijklmnopqrstuvwx", &sdp);
2914 SessionDescriptionInterface* answer3 =
2915 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2916 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2917 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2918 candidate1);
2919 EXPECT_TRUE(answer3->AddCandidate(&ice_candidate3));
2920 SetRemoteDescriptionWithoutError(answer3);
2921 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2922
2923 // The fourth answer has no candidate but a different ufrag/pwd.
2924 sdp.clear();
2925 ModifyIceUfragPwdLines(answer.get(), "0123456789012444",
2926 "abcdefghijklmnopqrstuvyz", &sdp);
2927 SessionDescriptionInterface* offer4 =
2928 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2929 SetRemoteDescriptionWithoutError(offer4);
2930 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2931}
2932
Donald Curtisd4f769d2015-05-28 09:48:21 -07002933// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002934// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002935TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2936 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2937
2938 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002939 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002940
2941 PeerConnectionInterface::RTCOfferAnswerOptions options;
2942 options.use_rtp_mux = true;
2943
2944 SessionDescriptionInterface* offer = CreateRemoteOffer();
2945 SetRemoteDescriptionWithoutError(offer);
2946
2947 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2948 SetLocalDescriptionWithoutError(answer);
2949
deadbeefcbecd352015-09-23 11:50:27 -07002950 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2951 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002952
deadbeefcbecd352015-09-23 11:50:27 -07002953 cricket::BaseChannel* voice_channel = session_->voice_channel();
2954 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002955
2956 // Checks if one of the transport channels contains a connection using a given
2957 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002958 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002959 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002960 session_->GetChannelTransportStats(voice_channel, &stats);
2961 for (auto& kv : stats.transport_stats) {
2962 for (auto& chan_stat : kv.second.channel_stats) {
2963 for (auto& conn_info : chan_stat.connection_infos) {
2964 if (conn_info.remote_candidate.address().port() == port) {
2965 return true;
2966 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002967 }
2968 }
2969 }
2970 return false;
2971 };
2972
2973 EXPECT_FALSE(connection_with_remote_port(5000));
2974 EXPECT_FALSE(connection_with_remote_port(5001));
2975 EXPECT_FALSE(connection_with_remote_port(6000));
2976
2977 // The way the *_WAIT checks work is they only wait if the condition fails,
2978 // which does not help in the case where state is not changing. This is
2979 // problematic in this test since we want to verify that adding a video
2980 // candidate does _not_ change state. So we interleave candidates and assume
2981 // that messages are executed in the order they were posted.
2982
2983 // First audio candidate.
2984 cricket::Candidate candidate0;
2985 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2986 candidate0.set_component(1);
2987 candidate0.set_protocol("udp");
2988 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2989 candidate0);
2990 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2991
2992 // Video candidate.
2993 cricket::Candidate candidate1;
2994 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2995 candidate1.set_component(1);
2996 candidate1.set_protocol("udp");
2997 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2998 candidate1);
2999 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3000
3001 // Second audio candidate.
3002 cricket::Candidate candidate2;
3003 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3004 candidate2.set_component(1);
3005 candidate2.set_protocol("udp");
3006 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3007 candidate2);
3008 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3009
3010 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3011 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3012
3013 // No need here for a _WAIT check since we are checking that state hasn't
3014 // changed: if this is false we would be doing waits for nothing and if this
3015 // is true then there will be no messages processed anyways.
3016 EXPECT_FALSE(connection_with_remote_port(6000));
3017}
3018
deadbeefcbecd352015-09-23 11:50:27 -07003019// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003020TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3021 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003022 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003023
3024 PeerConnectionInterface::RTCOfferAnswerOptions options;
3025 options.use_rtp_mux = true;
3026
3027 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003028 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003029
deadbeefcbecd352015-09-23 11:50:27 -07003030 EXPECT_NE(session_->voice_rtp_transport_channel(),
3031 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003032
deadbeefab9b2d12015-10-14 11:33:11 -07003033 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003034 SessionDescriptionInterface* answer =
3035 CreateRemoteAnswer(session_->local_description());
3036 SetRemoteDescriptionWithoutError(answer);
3037
deadbeefcbecd352015-09-23 11:50:27 -07003038 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3039 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003040}
3041
deadbeefcbecd352015-09-23 11:50:27 -07003042// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003043TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3044 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003045 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003046
Donald Curtis0e209b02015-03-24 09:29:54 -07003047 PeerConnectionInterface::RTCOfferAnswerOptions options;
3048 options.use_rtp_mux = true;
3049
3050 SessionDescriptionInterface* offer = CreateOffer(options);
3051 SetLocalDescriptionWithoutError(offer);
3052
deadbeefcbecd352015-09-23 11:50:27 -07003053 EXPECT_NE(session_->voice_rtp_transport_channel(),
3054 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003055
deadbeefab9b2d12015-10-14 11:33:11 -07003056 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003057
3058 // Remove BUNDLE from the answer.
3059 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3060 CreateRemoteAnswer(session_->local_description()));
3061 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3062 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3063 JsepSessionDescription* modified_answer =
3064 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3065 modified_answer->Initialize(answer_copy, "1", "1");
3066 SetRemoteDescriptionWithoutError(modified_answer); //
3067
deadbeefcbecd352015-09-23 11:50:27 -07003068 EXPECT_NE(session_->voice_rtp_transport_channel(),
3069 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003070}
3071
3072// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3073TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3074 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003075 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003076
3077 PeerConnectionInterface::RTCOfferAnswerOptions options;
3078 options.use_rtp_mux = true;
3079
3080 SessionDescriptionInterface* offer = CreateOffer(options);
3081 SetLocalDescriptionWithoutError(offer);
3082
deadbeefcbecd352015-09-23 11:50:27 -07003083 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3084 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003085
deadbeefab9b2d12015-10-14 11:33:11 -07003086 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003087 SessionDescriptionInterface* answer =
3088 CreateRemoteAnswer(session_->local_description());
3089 SetRemoteDescriptionWithoutError(answer);
3090
deadbeefcbecd352015-09-23 11:50:27 -07003091 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3092 session_->video_rtp_transport_channel());
3093}
3094
3095// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3096// audio content in the answer.
3097TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3098 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003099 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003100
3101 PeerConnectionInterface::RTCOfferAnswerOptions options;
3102 options.use_rtp_mux = true;
3103
3104 SessionDescriptionInterface* offer = CreateOffer(options);
3105 SetLocalDescriptionWithoutError(offer);
3106
3107 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3108 session_->video_rtp_transport_channel());
3109
deadbeefab9b2d12015-10-14 11:33:11 -07003110 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003111 cricket::MediaSessionOptions recv_options;
3112 recv_options.recv_audio = false;
3113 recv_options.recv_video = true;
3114 SessionDescriptionInterface* answer =
3115 CreateRemoteAnswer(session_->local_description(), recv_options);
3116 SetRemoteDescriptionWithoutError(answer);
3117
deadbeefd59daf82015-10-14 15:02:44 -07003118 EXPECT_TRUE(nullptr == session_->voice_channel());
3119 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003120
deadbeefd59daf82015-10-14 15:02:44 -07003121 session_->Close();
3122 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3123 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3124 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3125 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003126}
3127
3128// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3129TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3130 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003131 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003132
Donald Curtis0e209b02015-03-24 09:29:54 -07003133 PeerConnectionInterface::RTCOfferAnswerOptions options;
3134 options.use_rtp_mux = true;
3135
3136 SessionDescriptionInterface* offer = CreateOffer(options);
3137 SetLocalDescriptionWithoutError(offer);
3138
deadbeefcbecd352015-09-23 11:50:27 -07003139 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3140 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003141
deadbeefab9b2d12015-10-14 11:33:11 -07003142 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003143
3144 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003145 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003146 CreateRemoteAnswer(session_->local_description()));
3147 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3148 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3149 JsepSessionDescription* modified_answer =
3150 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3151 modified_answer->Initialize(answer_copy, "1", "1");
3152 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003153
deadbeefcbecd352015-09-23 11:50:27 -07003154 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3155 session_->video_rtp_transport_channel());
3156}
3157
3158// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3159TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3160 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003161 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003162
3163 SessionDescriptionInterface* offer = CreateRemoteOffer();
3164 SetRemoteDescriptionWithoutError(offer);
3165
3166 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3167 session_->video_rtp_transport_channel());
3168
deadbeefab9b2d12015-10-14 11:33:11 -07003169 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003170 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
3171 SetLocalDescriptionWithoutError(answer);
3172
3173 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3174 session_->video_rtp_transport_channel());
3175}
3176
3177// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3178TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3179 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003180 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003181
3182 // Remove BUNDLE from the offer.
3183 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3184 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3185 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3186 JsepSessionDescription* modified_offer =
3187 new JsepSessionDescription(JsepSessionDescription::kOffer);
3188 modified_offer->Initialize(offer_copy, "1", "1");
3189
3190 // Expect an error when applying the remote description
3191 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3192 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003193}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003194
Peter Thatcher4eddf182015-04-30 10:55:59 -07003195// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003196TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3197 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003198 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003199
Donald Curtis0e209b02015-03-24 09:29:54 -07003200 PeerConnectionInterface::RTCOfferAnswerOptions options;
3201 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003202
Donald Curtis0e209b02015-03-24 09:29:54 -07003203 SessionDescriptionInterface* offer = CreateOffer(options);
3204 SetLocalDescriptionWithoutError(offer);
3205
deadbeefcbecd352015-09-23 11:50:27 -07003206 EXPECT_NE(session_->voice_rtp_transport_channel(),
3207 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003208
deadbeefab9b2d12015-10-14 11:33:11 -07003209 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003210 SessionDescriptionInterface* answer =
3211 CreateRemoteAnswer(session_->local_description());
3212 SetRemoteDescriptionWithoutError(answer);
3213
3214 // This should lead to an audio-only call but isn't implemented
3215 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003216 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3217 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003218}
3219
deadbeefcbecd352015-09-23 11:50:27 -07003220// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003221TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3222 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003223 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003224 PeerConnectionInterface::RTCOfferAnswerOptions options;
3225 options.use_rtp_mux = true;
3226
3227 SessionDescriptionInterface* offer = CreateOffer(options);
3228 SetLocalDescriptionWithoutError(offer);
3229
deadbeefcbecd352015-09-23 11:50:27 -07003230 EXPECT_NE(session_->voice_rtp_transport_channel(),
3231 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003232
deadbeefab9b2d12015-10-14 11:33:11 -07003233 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003234
3235 // Remove BUNDLE from the answer.
3236 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3237 CreateRemoteAnswer(session_->local_description()));
3238 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3239 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3240 JsepSessionDescription* modified_answer =
3241 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3242 modified_answer->Initialize(answer_copy, "1", "1");
3243 SetRemoteDescriptionWithoutError(modified_answer); //
3244
deadbeefcbecd352015-09-23 11:50:27 -07003245 EXPECT_NE(session_->voice_rtp_transport_channel(),
3246 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003247}
3248
Peter Thatcher4eddf182015-04-30 10:55:59 -07003249// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3250TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3251 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003252 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003253
3254 PeerConnectionInterface::RTCOfferAnswerOptions options;
3255 options.use_rtp_mux = true;
3256
3257 SessionDescriptionInterface* offer = CreateOffer(options);
3258 SetRemoteDescriptionWithoutError(offer);
3259
deadbeefcbecd352015-09-23 11:50:27 -07003260 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3261 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003262}
3263
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003264TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3265 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003266 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003267
3268 PeerConnectionInterface::RTCOfferAnswerOptions options;
3269 SessionDescriptionInterface* offer = CreateOffer(options);
3270 SetLocalDescriptionWithoutError(offer);
3271
deadbeefcbecd352015-09-23 11:50:27 -07003272 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3273 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003274
deadbeefab9b2d12015-10-14 11:33:11 -07003275 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003276 SessionDescriptionInterface* answer =
3277 CreateRemoteAnswer(session_->local_description());
3278 SetRemoteDescriptionWithoutError(answer);
3279
deadbeefcbecd352015-09-23 11:50:27 -07003280 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3281 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003282}
3283
3284TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3285 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003286 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003287
3288 PeerConnectionInterface::RTCOfferAnswerOptions options;
3289 SessionDescriptionInterface* offer = CreateOffer(options);
3290 SetLocalDescriptionWithoutError(offer);
3291
deadbeefcbecd352015-09-23 11:50:27 -07003292 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3293 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003294
deadbeefab9b2d12015-10-14 11:33:11 -07003295 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003296 SessionDescriptionInterface* answer =
3297 CreateRemoteAnswer(session_->local_description());
3298 SetRemoteDescriptionWithoutError(answer);
3299
deadbeefcbecd352015-09-23 11:50:27 -07003300 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3301 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003302}
3303
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003304// This test verifies that SetLocalDescription and SetRemoteDescription fails
3305// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3306TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003307 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003308 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003309
3310 PeerConnectionInterface::RTCOfferAnswerOptions options;
3311 options.use_rtp_mux = true;
3312
3313 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003314 std::string offer_str;
3315 offer->ToString(&offer_str);
3316 // Disable rtcp-mux
3317 const std::string rtcp_mux = "rtcp-mux";
3318 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003319 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003320 xrtcp_mux.c_str(), xrtcp_mux.length(),
3321 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003322 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003323 new JsepSessionDescription(JsepSessionDescription::kOffer);
3324 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003325 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003326 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003327 new JsepSessionDescription(JsepSessionDescription::kOffer);
3328 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003329 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003330 // Trying unmodified SDP.
3331 SetLocalDescriptionWithoutError(offer);
3332}
3333
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003334TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003335 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003336 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003337 CreateAndSetRemoteOfferAndLocalAnswer();
3338 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3339 ASSERT_TRUE(channel != NULL);
3340 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003341 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003342 double volume;
3343 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3344 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003345 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003346 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3347 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003348 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003349 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3350 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003351}
3352
3353TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003354 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003355 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003356 CreateAndSetRemoteOfferAndLocalAnswer();
3357 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3358 ASSERT_TRUE(channel != NULL);
3359 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003360 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003361 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3362
3363 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003364 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003365
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003366 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003367 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003368 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003369 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003370 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003371
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003372 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003373 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003374 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003375 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003376 EXPECT_TRUE(renderer->sink() == NULL);
3377}
3378
3379TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003380 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003381 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003382 CreateAndSetRemoteOfferAndLocalAnswer();
3383 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3384 ASSERT_TRUE(channel != NULL);
3385 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003386 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003387
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003388 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003389 cricket::AudioOptions options;
3390 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3391 EXPECT_TRUE(renderer->sink() != NULL);
3392
3393 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3394 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3395 // SetSink(NULL) callback afterwards.
3396 renderer.reset();
3397
3398 // This will trigger SetSink(NULL) if no OnClose() callback.
3399 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003400}
3401
3402TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003403 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003404 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003405 CreateAndSetRemoteOfferAndLocalAnswer();
3406 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3407 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003408 ASSERT_LT(0u, channel->sinks().size());
3409 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003410 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003411 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003412 cricket::FakeVideoRenderer renderer;
3413 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003414 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003415 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003416 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003417}
3418
3419TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003420 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003421 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003422 CreateAndSetRemoteOfferAndLocalAnswer();
3423 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3424 ASSERT_TRUE(channel != NULL);
3425 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003426 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003427 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3428 cricket::VideoOptions* options = NULL;
3429 session_->SetVideoSend(send_ssrc, false, options);
3430 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3431 session_->SetVideoSend(send_ssrc, true, options);
3432 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3433}
3434
3435TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3436 TestCanInsertDtmf(false);
3437}
3438
3439TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3440 TestCanInsertDtmf(true);
3441}
3442
3443TEST_F(WebRtcSessionTest, InsertDtmf) {
3444 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003445 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003446 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003447 CreateAndSetRemoteOfferAndLocalAnswer();
3448 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3449 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3450
3451 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003452 const int expected_duration = 90;
3453 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3454 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3455 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3456
3457 // Verify
3458 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003459 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003460 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003461 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003462 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003463 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003464 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003465 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003466}
3467
deadbeefd59daf82015-10-14 15:02:44 -07003468// This test verifies the |initial_offerer| flag when session initiates the
3469// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003470TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003471 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003472 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003473 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003474 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3475 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003476 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003477 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003478 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003479}
3480
deadbeefd59daf82015-10-14 15:02:44 -07003481// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003482TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003483 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003484 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003485 SessionDescriptionInterface* offer = CreateRemoteOffer();
3486 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003487 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003488
deadbeefd59daf82015-10-14 15:02:44 -07003489 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003491 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003492}
3493
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003494// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3495TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003496 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003497 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003498 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003499 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003500 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501 CreateRemoteAnswer(session_->local_description()));
3502
3503 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3504 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003505 JsepSessionDescription* modified_answer =
3506 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003507
3508 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3509 answer->session_id(),
3510 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003511 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003512
wu@webrtc.org4e393072014-04-07 17:04:35 +00003513 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003514 std::string sdp;
3515 EXPECT_TRUE(answer->ToString(&sdp));
3516 const std::string kAudioMid = "a=mid:audio";
3517 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003518 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003519 kAudioMidReplaceStr.c_str(),
3520 kAudioMidReplaceStr.length(),
3521 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003522 SessionDescriptionInterface* modified_answer1 =
3523 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003524 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003525
wu@webrtc.org4e393072014-04-07 17:04:35 +00003526 // Different media types.
3527 EXPECT_TRUE(answer->ToString(&sdp));
3528 const std::string kAudioMline = "m=audio";
3529 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003530 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003531 kAudioMlineReplaceStr.c_str(),
3532 kAudioMlineReplaceStr.length(),
3533 &sdp);
3534 SessionDescriptionInterface* modified_answer2 =
3535 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3536 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3537
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003538 SetRemoteDescriptionWithoutError(answer.release());
3539}
3540
3541// Verifying remote offer and local answer have matching m-lines as per
3542// RFC 3264.
3543TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003544 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003545 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003546 SessionDescriptionInterface* offer = CreateRemoteOffer();
3547 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003548 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003549
3550 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3551 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003552 JsepSessionDescription* modified_answer =
3553 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003554
3555 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3556 answer->session_id(),
3557 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003558 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003559 SetLocalDescriptionWithoutError(answer);
3560}
3561
3562// This test verifies that WebRtcSession does not start candidate allocation
3563// before SetLocalDescription is called.
3564TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003565 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003566 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003567 SessionDescriptionInterface* offer = CreateRemoteOffer();
3568 cricket::Candidate candidate;
3569 candidate.set_component(1);
3570 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3571 candidate);
3572 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3573 cricket::Candidate candidate1;
3574 candidate1.set_component(1);
3575 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3576 candidate1);
3577 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3578 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003579 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3580 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003581
3582 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003583 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003584 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3585 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3586
wu@webrtc.org91053e72013-08-10 07:18:04 +00003587 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003588 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003589 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3590}
3591
3592// This test verifies that crypto parameter is updated in local session
3593// description as per security policy set in MediaSessionDescriptionFactory.
3594TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003595 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003596 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003597 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003598
3599 // Making sure SetLocalDescription correctly sets crypto value in
3600 // SessionDescription object after de-serialization of sdp string. The value
3601 // will be set as per MediaSessionDescriptionFactory.
3602 std::string offer_str;
3603 offer->ToString(&offer_str);
3604 SessionDescriptionInterface* jsep_offer_str =
3605 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3606 SetLocalDescriptionWithoutError(jsep_offer_str);
3607 EXPECT_TRUE(session_->voice_channel()->secure_required());
3608 EXPECT_TRUE(session_->video_channel()->secure_required());
3609}
3610
3611// This test verifies the crypto parameter when security is disabled.
3612TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003613 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003614 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003615 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003616 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003617
3618 // Making sure SetLocalDescription correctly sets crypto value in
3619 // SessionDescription object after de-serialization of sdp string. The value
3620 // will be set as per MediaSessionDescriptionFactory.
3621 std::string offer_str;
3622 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003623 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003624 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3625 SetLocalDescriptionWithoutError(jsep_offer_str);
3626 EXPECT_FALSE(session_->voice_channel()->secure_required());
3627 EXPECT_FALSE(session_->video_channel()->secure_required());
3628}
3629
3630// This test verifies that an answer contains new ufrag and password if an offer
3631// with new ufrag and password is received.
3632TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003633 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003634 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003635 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003636 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003637 CreateRemoteOffer(options));
3638 SetRemoteDescriptionWithoutError(offer.release());
3639
deadbeefab9b2d12015-10-14 11:33:11 -07003640 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003641 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003642 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003643 SetLocalDescriptionWithoutError(answer.release());
3644
3645 // Receive an offer with new ufrag and password.
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003646 options.audio_transport_options.ice_restart = true;
3647 options.video_transport_options.ice_restart = true;
3648 options.data_transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003649 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003650 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003651 SetRemoteDescriptionWithoutError(updated_offer1.release());
3652
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003653 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003654 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003655
3656 CompareIceUfragAndPassword(updated_answer1->description(),
3657 session_->local_description()->description(),
3658 false);
3659
3660 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003661}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003662
wu@webrtc.org91053e72013-08-10 07:18:04 +00003663// This test verifies that an answer contains old ufrag and password if an offer
3664// with old ufrag and password is received.
3665TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003666 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003667 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003668 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003669 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003670 CreateRemoteOffer(options));
3671 SetRemoteDescriptionWithoutError(offer.release());
3672
deadbeefab9b2d12015-10-14 11:33:11 -07003673 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003674 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003675 CreateAnswer(NULL));
3676 SetLocalDescriptionWithoutError(answer.release());
3677
3678 // Receive an offer without changed ufrag or password.
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003679 options.audio_transport_options.ice_restart = false;
3680 options.video_transport_options.ice_restart = false;
3681 options.data_transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003682 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003683 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003684 SetRemoteDescriptionWithoutError(updated_offer2.release());
3685
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003686 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003687 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003688
3689 CompareIceUfragAndPassword(updated_answer2->description(),
3690 session_->local_description()->description(),
3691 true);
3692
3693 SetLocalDescriptionWithoutError(updated_answer2.release());
3694}
3695
3696TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003697 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003698 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003699 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003700 const std::string session_id_orig = offer->session_id();
3701 const std::string session_version_orig = offer->session_version();
3702 SetLocalDescriptionWithoutError(offer);
3703
3704 video_channel_ = media_engine_->GetVideoChannel(0);
3705 video_channel_->set_fail_set_send_codecs(true);
3706
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003707 SessionDescriptionInterface* answer =
3708 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003709 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003710
3711 // Test that after a content error, setting any description will
3712 // result in an error.
3713 video_channel_->set_fail_set_send_codecs(false);
3714 answer = CreateRemoteAnswer(session_->local_description());
3715 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3716 offer = CreateRemoteOffer();
3717 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003718}
3719
3720// Runs the loopback call test with BUNDLE and STUN disabled.
3721TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3722 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003723 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003724 cricket::PORTALLOCATOR_DISABLE_STUN |
3725 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003726 TestLoopbackCall();
3727}
3728
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003729TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003730 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003731 cricket::PORTALLOCATOR_DISABLE_STUN |
3732 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3733 cricket::PORTALLOCATOR_DISABLE_RELAY);
3734
3735 // best connection is IPv6 since it has higher network preference.
3736 LoopbackNetworkConfiguration config;
3737 config.test_ipv6_network_ = true;
3738 config.best_connection_after_initial_ice_converged_ =
3739 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3740
3741 TestLoopbackCall(config);
3742}
3743
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003744// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003745TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003746 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3747 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003748 TestLoopbackCall();
3749}
3750
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003751TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3752 constraints_.reset(new FakeConstraints());
3753 constraints_->AddOptional(
3754 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003755 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003756
3757 SetLocalDescriptionWithDataChannel();
3758 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3759}
3760
Henrik Boström87713d02015-08-25 09:53:21 +02003761TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003762 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003763
3764 constraints_.reset(new FakeConstraints());
3765 constraints_->AddOptional(
3766 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003767 options_.disable_sctp_data_channels = false;
3768
Henrik Boström87713d02015-08-25 09:53:21 +02003769 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003770
3771 SetLocalDescriptionWithDataChannel();
3772 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3773}
3774
Henrik Boström87713d02015-08-25 09:53:21 +02003775TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003776 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003777
Henrik Boström87713d02015-08-25 09:53:21 +02003778 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003779
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003780 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003781 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003782 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3783}
3784
Henrik Boström87713d02015-08-25 09:53:21 +02003785TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003786 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003787 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003788 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003789
3790 // Create remote offer with SCTP.
3791 cricket::MediaSessionOptions options;
3792 options.data_channel_type = cricket::DCT_SCTP;
3793 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003794 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003795 SetRemoteDescriptionWithoutError(offer);
3796
3797 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003798 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003799 EXPECT_TRUE(answer != NULL);
3800 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3801 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003802}
3803
Henrik Boström87713d02015-08-25 09:53:21 +02003804TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003805 constraints_.reset(new FakeConstraints());
3806 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003807 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003808 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003809
3810 SetLocalDescriptionWithDataChannel();
3811 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3812}
3813
Henrik Boström87713d02015-08-25 09:53:21 +02003814TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003815 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003816
Henrik Boström87713d02015-08-25 09:53:21 +02003817 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003818
3819 SetLocalDescriptionWithDataChannel();
3820 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3821}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003822
Henrik Boström87713d02015-08-25 09:53:21 +02003823TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003824 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003825 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003826 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003827
3828 SetLocalDescriptionWithDataChannel();
3829 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3830}
3831
Henrik Boström87713d02015-08-25 09:53:21 +02003832TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003833 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003834 const int new_send_port = 9998;
3835 const int new_recv_port = 7775;
3836
Henrik Boström87713d02015-08-25 09:53:21 +02003837 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003838 SetFactoryDtlsSrtp();
3839
3840 // By default, don't actually add the codecs to desc_factory_; they don't
3841 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3842 // let the session description get parsed. That'll get the proper codecs
3843 // into the stream.
3844 cricket::MediaSessionOptions options;
3845 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3846 "stream1", new_send_port, options);
3847
3848 // SetRemoteDescription will take the ownership of the offer.
3849 SetRemoteDescriptionWithoutError(offer);
3850
3851 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3852 new_recv_port, CreateAnswer(NULL));
3853 ASSERT_TRUE(answer != NULL);
3854
3855 // Now set the local description, which'll take ownership of the answer.
3856 SetLocalDescriptionWithoutError(answer);
3857
3858 // TEST PLAN: Set the port number to something new, set it in the SDP,
3859 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003860 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003861 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003862
3863 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3864 int portnum = -1;
3865 ASSERT_TRUE(ch != NULL);
3866 ASSERT_EQ(1UL, ch->send_codecs().size());
3867 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003868 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003869 ch->send_codecs()[0].name.c_str()));
3870 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3871 &portnum));
3872 EXPECT_EQ(new_send_port, portnum);
3873
3874 ASSERT_EQ(1UL, ch->recv_codecs().size());
3875 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003876 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003877 ch->recv_codecs()[0].name.c_str()));
3878 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3879 &portnum));
3880 EXPECT_EQ(new_recv_port, portnum);
3881}
3882
deadbeefab9b2d12015-10-14 11:33:11 -07003883// Verifies that when a session's DataChannel receives an OPEN message,
3884// WebRtcSession signals the DataChannel creation request with the expected
3885// config.
3886TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3887 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3888
3889 InitWithDtls(GetParam());
3890
3891 SetLocalDescriptionWithDataChannel();
3892 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3893
3894 webrtc::DataChannelInit config;
3895 config.id = 1;
3896 rtc::Buffer payload;
3897 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3898 cricket::ReceiveDataParams params;
3899 params.ssrc = config.id;
3900 params.type = cricket::DMT_CONTROL;
3901
3902 cricket::DataChannel* data_channel = session_->data_channel();
3903 data_channel->SignalDataReceived(data_channel, params, payload);
3904
3905 EXPECT_EQ("a", last_data_channel_label_);
3906 EXPECT_EQ(config.id, last_data_channel_config_.id);
3907 EXPECT_FALSE(last_data_channel_config_.negotiated);
3908 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3909 last_data_channel_config_.open_handshake_role);
3910}
3911
3912TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003913 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3914 FakeDtlsIdentityStore::GenerateCertificate();
3915
3916 PeerConnectionInterface::RTCConfiguration configuration;
3917 configuration.certificates.push_back(certificate);
3918 Init(nullptr, configuration);
3919 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3920
3921 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3922}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003923
Henrik Boström87713d02015-08-25 09:53:21 +02003924// Verifies that CreateOffer succeeds when CreateOffer is called before async
3925// identity generation is finished (even if a certificate is provided this is
3926// an async op).
3927TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3928 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3929 InitWithDtls(GetParam());
3930
Henrik Boströmd8281982015-08-27 10:12:24 +02003931 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003932 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003933 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3934
wu@webrtc.org91053e72013-08-10 07:18:04 +00003935 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003936 VerifyNoCryptoParams(offer->description(), true);
3937 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003938}
3939
3940// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003941// identity generation is finished (even if a certificate is provided this is
3942// an async op).
3943TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003944 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003945 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003946 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003947
3948 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003949 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003950 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003951 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003952 ASSERT_TRUE(offer.get() != NULL);
3953 SetRemoteDescriptionWithoutError(offer.release());
3954
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003955 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003956 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003957 VerifyNoCryptoParams(answer->description(), true);
3958 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003959}
3960
3961// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003962// identity generation is finished (even if a certificate is provided this is
3963// an async op).
3964TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003965 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003966 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003967
Henrik Boströmd8281982015-08-27 10:12:24 +02003968 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003969
3970 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003971 EXPECT_TRUE(offer != NULL);
3972}
3973
3974// Verifies that CreateOffer fails when CreateOffer is called after async
3975// identity generation fails.
3976TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003977 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003978 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003979
Henrik Boströmd8281982015-08-27 10:12:24 +02003980 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003981
3982 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003983 EXPECT_TRUE(offer == NULL);
3984}
3985
3986// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3987// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003988TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003989 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003990 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07003991 VerifyMultipleAsyncCreateDescription(GetParam(),
3992 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003993}
3994
3995// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3996// before async identity generation fails.
3997TEST_F(WebRtcSessionTest,
3998 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003999 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004000 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4001 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004002}
4003
4004// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4005// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004006TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004007 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004008 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004009 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004010 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004011}
4012
4013// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4014// before async identity generation fails.
4015TEST_F(WebRtcSessionTest,
4016 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004017 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004018 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4019 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004020}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004021
4022// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4023// offer has no SDES crypto but only DTLS fingerprint.
4024TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4025 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004026 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004027 // Create a remote offer with secured transport disabled.
4028 cricket::MediaSessionOptions options;
4029 JsepSessionDescription* offer(CreateRemoteOffer(
4030 options, cricket::SEC_DISABLED));
4031 // Adds a DTLS fingerprint to the remote offer.
4032 cricket::SessionDescription* sdp = offer->description();
4033 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4034 ASSERT_TRUE(audio != NULL);
4035 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4036 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004037 rtc::SSLFingerprint::CreateFromRfc4572(
4038 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004039 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004040 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004041}
4042
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004043TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
4044 constraints_.reset(new FakeConstraints());
4045 constraints_->AddOptional(
4046 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4047 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004048 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004049 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004050 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004051
4052 SetLocalDescriptionWithoutError(offer);
4053
4054 video_channel_ = media_engine_->GetVideoChannel(0);
4055
4056 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004057 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004058 EXPECT_EQ(rtc::Optional<bool>(true), video_options.suspend_below_min_bitrate);
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004059}
4060
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004061TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
4062 constraints_.reset(new FakeConstraints());
4063 constraints_->AddOptional(
4064 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
4065 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004066 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004067 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004068 SessionDescriptionInterface* offer = CreateOffer();
4069
4070 SetLocalDescriptionWithoutError(offer);
4071
4072 voice_channel_ = media_engine_->GetVoiceChannel(0);
4073
4074 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004075 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004076 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004077}
4078
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004079// Tests that we can renegotiate new media content with ICE candidates in the
4080// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004081TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004082 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004083 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004084 SetFactoryDtlsSrtp();
4085
deadbeefab9b2d12015-10-14 11:33:11 -07004086 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004087 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004088 SetLocalDescriptionWithoutError(offer);
4089
4090 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4091 SetRemoteDescriptionWithoutError(answer);
4092
4093 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004094 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004095 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4096
4097 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004098 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004099 candidate1.set_component(1);
4100 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4101 candidate1);
4102 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4103 SetRemoteDescriptionWithoutError(offer);
4104
4105 answer = CreateAnswer(NULL);
4106 SetLocalDescriptionWithoutError(answer);
4107}
4108
4109// Tests that we can renegotiate new media content with ICE candidates separated
4110// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004111TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004112 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004113 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004114 SetFactoryDtlsSrtp();
4115
deadbeefab9b2d12015-10-14 11:33:11 -07004116 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004117 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004118 SetLocalDescriptionWithoutError(offer);
4119
4120 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4121 SetRemoteDescriptionWithoutError(answer);
4122
4123 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004124 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004125 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4126 SetRemoteDescriptionWithoutError(offer);
4127
4128 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004129 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004130 candidate1.set_component(1);
4131 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4132 candidate1);
4133 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4134
4135 answer = CreateAnswer(NULL);
4136 SetLocalDescriptionWithoutError(answer);
4137}
honghaiz7f777492016-02-02 21:54:01 -08004138
4139// Flaky on Win and Mac only. See webrtc:4943
4140#if defined(WEBRTC_WIN) || defined(WEBRTC_MAC)
4141#define MAYBE_TestRtxRemovedByCreateAnswer DISABLED_TestRtxRemovedByCreateAnswer
4142#else
4143#define MAYBE_TestRtxRemovedByCreateAnswer TestRtxRemovedByCreateAnswer
4144#endif
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004145// Tests that RTX codec is removed from the answer when it isn't supported
4146// by local side.
honghaiz7f777492016-02-02 21:54:01 -08004147TEST_F(WebRtcSessionTest, MAYBE_TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004148 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004149 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004150 std::string offer_sdp(kSdpWithRtx);
4151
4152 SessionDescriptionInterface* offer =
4153 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4154 EXPECT_TRUE(offer->ToString(&offer_sdp));
4155
4156 // Offer SDP contains the RTX codec.
4157 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4158 SetRemoteDescriptionWithoutError(offer);
4159
4160 SessionDescriptionInterface* answer = CreateAnswer(NULL);
4161 std::string answer_sdp;
4162 answer->ToString(&answer_sdp);
4163 // Answer SDP removes the unsupported RTX codec.
4164 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4165 SetLocalDescriptionWithoutError(answer);
4166}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004167
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004168// This verifies that the voice channel after bundle has both options from video
4169// and voice channels.
4170TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4171 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004172 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004173
4174 PeerConnectionInterface::RTCOfferAnswerOptions options;
4175 options.use_rtp_mux = true;
4176
4177 SessionDescriptionInterface* offer = CreateOffer(options);
4178 SetLocalDescriptionWithoutError(offer);
4179
4180 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4181 rtc::Socket::Option::OPT_SNDBUF, 4000);
4182
4183 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4184 rtc::Socket::Option::OPT_RCVBUF, 8000);
4185
4186 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004187 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004188 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4189 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004190 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004191 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4192
deadbeefcbecd352015-09-23 11:50:27 -07004193 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004194 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4195 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004196 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004197 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4198
deadbeefcbecd352015-09-23 11:50:27 -07004199 EXPECT_NE(session_->voice_rtp_transport_channel(),
4200 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004201
deadbeefab9b2d12015-10-14 11:33:11 -07004202 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004203 SessionDescriptionInterface* answer =
4204 CreateRemoteAnswer(session_->local_description());
4205 SetRemoteDescriptionWithoutError(answer);
4206
deadbeefcbecd352015-09-23 11:50:27 -07004207 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004208 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4209 EXPECT_EQ(4000, option_val);
4210
deadbeefcbecd352015-09-23 11:50:27 -07004211 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004212 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4213 EXPECT_EQ(8000, option_val);
4214}
4215
tommi0f620f42015-07-09 03:25:02 -07004216// Test creating a session, request multiple offers, destroy the session
4217// and make sure we got success/failure callbacks for all of the requests.
4218// Background: crbug.com/507307
4219TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4220 Init();
4221
4222 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4223 PeerConnectionInterface::RTCOfferAnswerOptions options;
4224 options.offer_to_receive_audio =
4225 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004226 cricket::MediaSessionOptions session_options;
4227 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004228
4229 for (auto& o : observers) {
4230 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004231 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004232 }
4233
4234 session_.reset();
4235
tommi0f620f42015-07-09 03:25:02 -07004236 for (auto& o : observers) {
4237 // We expect to have received a notification now even if the session was
4238 // terminated. The offer creation may or may not have succeeded, but we
4239 // must have received a notification which, so the only invalid state
4240 // is kInit.
4241 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4242 }
4243}
4244
stefanc1aeaf02015-10-15 07:26:07 -07004245TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4246 TestPacketOptions();
4247}
4248
deadbeef057ecf02016-01-20 14:30:43 -08004249// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4250// is destroyed.
4251TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4252 Init();
4253 session_.reset();
4254 EXPECT_TRUE(session_destroyed_);
4255}
4256
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004257// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4258// currently fails because upon disconnection and reconnection OnIceComplete is
4259// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004260
deadbeefcbecd352015-09-23 11:50:27 -07004261INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4262 WebRtcSessionTest,
4263 testing::Values(ALREADY_GENERATED,
4264 DTLS_IDENTITY_STORE));