blob: fc0d0cc7ed1f8a9d4decce18649f43e9495a652c [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
deadbeef0ed85b22016-02-23 17:24:52 -0800734 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
735 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800737 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738 }
739
740 const cricket::ContentInfos& contents = desc1->contents();
741 cricket::ContentInfos::const_iterator it = contents.begin();
742
743 for (; it != contents.end(); ++it) {
744 const cricket::TransportDescription* transport_desc1 =
745 desc1->GetTransportDescriptionByName(it->name);
746 const cricket::TransportDescription* transport_desc2 =
747 desc2->GetTransportDescriptionByName(it->name);
748 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800749 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000750 }
751 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
752 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800753 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 }
755 }
deadbeef0ed85b22016-02-23 17:24:52 -0800756 return true;
757 }
758
759 // Compares ufrag/password only for the specified |media_type|.
760 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
761 const cricket::SessionDescription* desc2,
762 cricket::MediaType media_type) {
763 if (desc1->contents().size() != desc2->contents().size()) {
764 return false;
765 }
766
767 const cricket::ContentInfo* cinfo =
768 cricket::GetFirstMediaContent(desc1->contents(), media_type);
769 const cricket::TransportDescription* transport_desc1 =
770 desc1->GetTransportDescriptionByName(cinfo->name);
771 const cricket::TransportDescription* transport_desc2 =
772 desc2->GetTransportDescriptionByName(cinfo->name);
773 if (!transport_desc1 || !transport_desc2) {
774 return false;
775 }
776 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
777 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
778 return false;
779 }
780 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000782
783 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
784 std::string *sdp) {
785 const cricket::SessionDescription* desc = current_desc->description();
786 EXPECT_TRUE(current_desc->ToString(sdp));
787
788 const cricket::ContentInfos& contents = desc->contents();
789 cricket::ContentInfos::const_iterator it = contents.begin();
790 // Replace ufrag and pwd lines with empty strings.
791 for (; it != contents.end(); ++it) {
792 const cricket::TransportDescription* transport_desc =
793 desc->GetTransportDescriptionByName(it->name);
794 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
795 + "\r\n";
796 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
797 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000798 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000799 "", 0,
800 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000801 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000802 "", 0,
803 sdp);
804 }
805 }
806
deadbeef0ed85b22016-02-23 17:24:52 -0800807 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
808 const std::string& ufrag,
809 const std::string& pwd) {
810 cricket::SessionDescription* desc = current_desc->description();
811 for (TransportInfo& transport_info : desc->transport_infos()) {
812 cricket::TransportDescription& transport_desc =
813 transport_info.description;
814 transport_desc.ice_ufrag = ufrag;
815 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000816 }
817 }
818
deadbeef0ed85b22016-02-23 17:24:52 -0800819 // Sets ufrag/pwd for specified |media_type|.
820 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
821 cricket::MediaType media_type,
822 const std::string& ufrag,
823 const std::string& pwd) {
824 cricket::SessionDescription* desc = current_desc->description();
825 const cricket::ContentInfo* cinfo =
826 cricket::GetFirstMediaContent(desc->contents(), media_type);
827 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
828 cricket::TransportDescription* transport_desc =
829 &transport_info->description;
830 transport_desc->ice_ufrag = ufrag;
831 transport_desc->ice_pwd = pwd;
832 }
833
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 // Creates a remote offer and and applies it as a remote description,
835 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700836 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 // to decide which local and remote streams to create.
838 void CreateAndSetRemoteOfferAndLocalAnswer() {
839 SessionDescriptionInterface* offer = CreateRemoteOffer();
840 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000841 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 SetLocalDescriptionWithoutError(answer);
843 }
844 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
845 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700846 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 }
848 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700849 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 SetLocalDescriptionWithoutError(desc);
851 EXPECT_EQ(expected_state, session_->state());
852 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000853 void SetLocalDescriptionExpectError(const std::string& action,
854 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 SessionDescriptionInterface* desc) {
856 std::string error;
857 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000858 std::string sdp_type = "local ";
859 sdp_type.append(action);
860 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 EXPECT_NE(std::string::npos, error.find(expected_error));
862 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000863 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
864 SessionDescriptionInterface* desc) {
865 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
866 expected_error, desc);
867 }
868 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
869 SessionDescriptionInterface* desc) {
870 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
871 expected_error, desc);
872 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
874 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
875 }
876 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700877 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 SetRemoteDescriptionWithoutError(desc);
879 EXPECT_EQ(expected_state, session_->state());
880 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000881 void SetRemoteDescriptionExpectError(const std::string& action,
882 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 SessionDescriptionInterface* desc) {
884 std::string error;
885 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000886 std::string sdp_type = "remote ";
887 sdp_type.append(action);
888 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 EXPECT_NE(std::string::npos, error.find(expected_error));
890 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000891 void SetRemoteDescriptionOfferExpectError(
892 const std::string& expected_error, SessionDescriptionInterface* desc) {
893 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
894 expected_error, desc);
895 }
896 void SetRemoteDescriptionPranswerExpectError(
897 const std::string& expected_error, SessionDescriptionInterface* desc) {
898 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
899 expected_error, desc);
900 }
901 void SetRemoteDescriptionAnswerExpectError(
902 const std::string& expected_error, SessionDescriptionInterface* desc) {
903 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
904 expected_error, desc);
905 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906
907 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
908 SessionDescriptionInterface** nocrypto_answer) {
909 // Create a SDP without Crypto.
910 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000911 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 options.bundle_enabled = true;
913 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
914 ASSERT_TRUE(*offer != NULL);
915 VerifyCryptoParams((*offer)->description());
916
917 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
918 cricket::SEC_DISABLED);
919 EXPECT_TRUE(*nocrypto_answer != NULL);
920 }
921
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000922 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
923 SessionDescriptionInterface** nodtls_answer) {
924 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000925 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000926 options.bundle_enabled = true;
927
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000928 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000929 CreateRemoteOffer(options, cricket::SEC_ENABLED));
930
931 *nodtls_answer =
932 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
933 EXPECT_TRUE(*nodtls_answer != NULL);
934 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
935 VerifyCryptoParams((*nodtls_answer)->description());
936
937 SetFactoryDtlsSrtp();
938 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
939 ASSERT_TRUE(*offer != NULL);
940 VerifyFingerprintStatus((*offer)->description(), true);
941 VerifyCryptoParams((*offer)->description());
942 }
943
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 JsepSessionDescription* CreateRemoteOfferWithVersion(
945 cricket::MediaSessionOptions options,
946 cricket::SecurePolicy secure_policy,
947 const std::string& session_version,
948 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000949 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 const cricket::SessionDescription* cricket_desc = NULL;
951 if (current_desc) {
952 cricket_desc = current_desc->description();
953 session_id = current_desc->session_id();
954 }
955
956 desc_factory_->set_secure(secure_policy);
957 JsepSessionDescription* offer(
958 new JsepSessionDescription(JsepSessionDescription::kOffer));
959 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
960 session_id, session_version)) {
961 delete offer;
962 offer = NULL;
963 }
964 return offer;
965 }
966 JsepSessionDescription* CreateRemoteOffer(
967 cricket::MediaSessionOptions options) {
968 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
969 kSessionVersion, NULL);
970 }
971 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000972 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
973 return CreateRemoteOfferWithVersion(
974 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 }
976 JsepSessionDescription* CreateRemoteOffer(
977 cricket::MediaSessionOptions options,
978 const SessionDescriptionInterface* current_desc) {
979 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
980 kSessionVersion, current_desc);
981 }
982
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000983 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
984 const char* sctp_stream_name, int new_port,
985 cricket::MediaSessionOptions options) {
986 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000987 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
988 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000989 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
990 }
991
992 // Takes ownership of offer_basis (and deletes it).
993 JsepSessionDescription* ChangeSDPSctpPort(
994 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
995 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
996 // SessionDescription from the mutated string.
997 const char* default_port_str = "5000";
998 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000999 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001000 std::string offer_str;
1001 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001002 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001003 new_port_str, strlen(new_port_str),
1004 &offer_str);
1005 JsepSessionDescription* offer = new JsepSessionDescription(
1006 offer_basis->type());
1007 delete offer_basis;
1008 offer->Initialize(offer_str, NULL);
1009 return offer;
1010 }
1011
deadbeefab9b2d12015-10-14 11:33:11 -07001012 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013 // before this function to decide which streams to create.
1014 JsepSessionDescription* CreateRemoteOffer() {
1015 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001016 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017 return CreateRemoteOffer(options, session_->remote_description());
1018 }
1019
1020 JsepSessionDescription* CreateRemoteAnswer(
1021 const SessionDescriptionInterface* offer,
1022 cricket::MediaSessionOptions options,
1023 cricket::SecurePolicy policy) {
1024 desc_factory_->set_secure(policy);
1025 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001026 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001027 JsepSessionDescription* answer(
1028 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1029 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1030 options, NULL),
1031 session_id, kSessionVersion)) {
1032 delete answer;
1033 answer = NULL;
1034 }
1035 return answer;
1036 }
1037
1038 JsepSessionDescription* CreateRemoteAnswer(
1039 const SessionDescriptionInterface* offer,
1040 cricket::MediaSessionOptions options) {
1041 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1042 }
1043
deadbeefab9b2d12015-10-14 11:33:11 -07001044 // Creates an answer session description.
1045 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001046 // to decide which streams to create.
1047 JsepSessionDescription* CreateRemoteAnswer(
1048 const SessionDescriptionInterface* offer) {
1049 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001050 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001051 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1052 }
1053
1054 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001055 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001056 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001057 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001058
1059 PeerConnectionInterface::RTCOfferAnswerOptions options;
1060 options.use_rtp_mux = bundle;
1061
1062 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1064 // and answer.
1065 SetLocalDescriptionWithoutError(offer);
1066
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001067 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001068 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 std::string sdp;
1070 EXPECT_TRUE(answer->ToString(&sdp));
1071
1072 size_t expected_candidate_num = 2;
1073 if (!rtcp_mux) {
1074 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1075 // for rtp and rtcp.
1076 expected_candidate_num = 4;
1077 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 const std::string kRtcpMux = "a=rtcp-mux";
1079 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001080 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001081 kXRtcpMux.c_str(), kXRtcpMux.length(),
1082 &sdp);
1083 }
1084
1085 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1086 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087
1088 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001089 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001090 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1091 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001092 if (bundle) {
1093 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1094 } else {
1095 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096 }
1097 }
1098 // Tests that we can only send DTMF when the dtmf codec is supported.
1099 void TestCanInsertDtmf(bool can) {
1100 if (can) {
1101 InitWithDtmfCodec();
1102 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001103 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104 }
deadbeefab9b2d12015-10-14 11:33:11 -07001105 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 CreateAndSetRemoteOfferAndLocalAnswer();
1107 EXPECT_FALSE(session_->CanInsertDtmf(""));
1108 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1109 }
1110
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001111 // Helper class to configure loopback network and verify Best
1112 // Connection using right IP protocol for TestLoopbackCall
1113 // method. LoopbackNetworkManager applies firewall rules to block
1114 // all ping traffic once ICE completed, and remove them to observe
1115 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1116 // verifies the best connection is using the right IP protocol after
1117 // initial ICE convergences.
1118
1119 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001120 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001121 LoopbackNetworkConfiguration()
1122 : test_ipv6_network_(false),
1123 test_extra_ipv4_network_(false),
1124 best_connection_after_initial_ice_converged_(1, 0) {}
1125
1126 // Used to track the expected best connection count in each IP protocol.
1127 struct ExpectedBestConnection {
1128 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1129 : ipv4_count_(ipv4_count),
1130 ipv6_count_(ipv6_count) {}
1131
1132 int ipv4_count_;
1133 int ipv6_count_;
1134 };
1135
1136 bool test_ipv6_network_;
1137 bool test_extra_ipv4_network_;
1138 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1139
1140 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001141 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001142 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1143 }
1144
1145 private:
jbauchac8869e2015-07-03 01:36:14 -07001146 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001147 const ExpectedBestConnection& expected) const {
1148 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001149 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1150 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001151 expected.ipv4_count_);
1152 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001153 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1154 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001155 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001156 // This is used in the loopback call so there is only single host to host
1157 // candidate pair.
1158 EXPECT_EQ(metrics_observer->GetEnumCounter(
1159 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1160 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001161 0);
1162 EXPECT_EQ(metrics_observer->GetEnumCounter(
1163 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1164 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001165 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001166 }
1167 };
1168
1169 class LoopbackNetworkManager {
1170 public:
1171 LoopbackNetworkManager(WebRtcSessionTest* session,
1172 const LoopbackNetworkConfiguration& config)
1173 : config_(config) {
1174 session->AddInterface(
1175 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1176 if (config_.test_extra_ipv4_network_) {
1177 session->AddInterface(
1178 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1179 }
1180 if (config_.test_ipv6_network_) {
1181 session->AddInterface(
1182 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1183 }
1184 }
1185
1186 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1187 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1188 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1189 if (config_.test_extra_ipv4_network_) {
1190 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1191 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1192 }
1193 if (config_.test_ipv6_network_) {
1194 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1195 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1196 }
1197 }
1198
1199 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1200
1201 private:
1202 LoopbackNetworkConfiguration config_;
1203 };
1204
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001205 // The method sets up a call from the session to itself, in a loopback
1206 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001207 // disconnection, and then a permanent disconnection.
1208 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001209 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1210 // While running the call, this method also checks if the session goes through
1211 // the correct sequence of ICE states when a connection is established,
1212 // broken, and re-established.
1213 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001214 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1215 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001216 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001217
stefanc1aeaf02015-10-15 07:26:07 -07001218 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001219 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001220 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001221 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001222
1223 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1224 observer_.ice_gathering_state_);
1225 SetLocalDescriptionWithoutError(offer);
1226 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1227 observer_.ice_connection_state_);
1228 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001229 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001230 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1231 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001232 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001233
1234 std::string sdp;
1235 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001236 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1237 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001238 ASSERT_TRUE(desc != NULL);
1239 SetRemoteDescriptionWithoutError(desc);
1240
1241 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001242 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001243
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001244 // The ice connection state is "Connected" too briefly to catch in a test.
1245 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001246 observer_.ice_connection_state_, kIceCandidatesTimeout);
1247 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248
stefanc1aeaf02015-10-15 07:26:07 -07001249 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1250 LoopbackNetworkManager loopback_network_manager(this, config);
1251 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001252 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001253 // Adding firewall rule to block ping requests, which should cause
1254 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001255
1256 loopback_network_manager.ApplyFirewallRules(fss_.get());
1257
1258 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001259 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1260 observer_.ice_connection_state_,
1261 kIceCandidatesTimeout);
1262
jbauchac8869e2015-07-03 01:36:14 -07001263 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001264
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001266 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001267
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001268 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001269 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 observer_.ice_connection_state_,
1271 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001272
1273 // Now we block ping requests and wait until the ICE connection transitions
1274 // to the Failed state. This will take at least 30 seconds because it must
1275 // wait for the Port to timeout.
1276 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001277
1278 loopback_network_manager.ApplyFirewallRules(fss_.get());
1279 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001280 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001281 observer_.ice_connection_state_,
1282 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283 }
1284
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001285 void TestLoopbackCall() {
1286 LoopbackNetworkConfiguration config;
1287 TestLoopbackCall(config);
1288 }
1289
stefanc1aeaf02015-10-15 07:26:07 -07001290 void TestPacketOptions() {
1291 media_controller_.reset(
1292 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1293 LoopbackNetworkConfiguration config;
1294 LoopbackNetworkManager loopback_network_manager(this, config);
1295
1296 SetupLoopbackCall();
1297
1298 uint8_t test_packet[15] = {0};
1299 rtc::PacketOptions options;
1300 options.packet_id = 10;
1301 media_engine_->GetVideoChannel(0)
1302 ->SendRtp(test_packet, sizeof(test_packet), options);
1303
1304 const int kPacketTimeout = 2000;
1305 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1306 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1307 }
1308
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001309 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1310 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001311 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1312 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1313
1314 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1316 codecs.push_back(kCNCodec1);
1317 codecs.push_back(kCNCodec2);
1318 media_engine_->SetAudioCodecs(codecs);
1319 desc_factory_->set_audio_codecs(codecs);
1320 }
1321
1322 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1323 const cricket::ContentDescription* description = content->description;
1324 ASSERT(description != NULL);
1325 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001326 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327 ASSERT(audio_content_desc != NULL);
1328 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1329 if (audio_content_desc->codecs()[i].name == "CN")
1330 return false;
1331 }
1332 return true;
1333 }
1334
deadbeefab9b2d12015-10-14 11:33:11 -07001335 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001336 webrtc::InternalDataChannelInit dci;
deadbeefab9b2d12015-10-14 11:33:11 -07001337 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1338 data_channel_ = DataChannel::Create(
1339 session_.get(), session_->data_channel_type(), "datachannel", dci);
1340 }
1341
1342 void SetLocalDescriptionWithDataChannel() {
1343 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001344 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001345 SetLocalDescriptionWithoutError(offer);
1346 }
1347
wu@webrtc.org91053e72013-08-10 07:18:04 +00001348 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001349 RTCCertificateGenerationMethod cert_gen_method,
1350 CreateSessionDescriptionRequest::Type type) {
1351 InitWithDtls(cert_gen_method);
1352 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1353 }
1354
1355 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1356 CreateSessionDescriptionRequest::Type type) {
1357 InitWithDtlsIdentityGenFail();
1358 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1359 }
1360
1361 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001362 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001363 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001364 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001365 if (type == CreateSessionDescriptionRequest::kAnswer) {
1366 cricket::MediaSessionOptions options;
1367 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001368 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001369 ASSERT_TRUE(offer.get() != NULL);
1370 SetRemoteDescriptionWithoutError(offer.release());
1371 }
1372
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001373 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001374 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001375 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001376 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001377 observers[kNumber];
1378 for (int i = 0; i < kNumber; ++i) {
1379 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1380 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001381 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001382 } else {
deadbeefab9b2d12015-10-14 11:33:11 -07001383 session_->CreateAnswer(observers[i], nullptr, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001384 }
1385 }
1386
1387 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1388 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1389 WebRtcSessionCreateSDPObserverForTest::kFailed;
1390
1391 for (int i = 0; i < kNumber; ++i) {
1392 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1393 if (success) {
1394 EXPECT_TRUE(observers[i]->description() != NULL);
1395 } else {
1396 EXPECT_TRUE(observers[i]->description() == NULL);
1397 }
1398 }
1399 }
1400
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001401 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001402 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001403 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001404 turn_server.credentials = credentials;
1405 turn_server.ports.push_back(
1406 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1407 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001408 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001409 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001410 }
1411
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412 cricket::FakeMediaEngine* media_engine_;
1413 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001414 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001415 cricket::FakeCall fake_call_;
1416 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001417 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001418 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1419 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1420 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1421 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1422 rtc::SocketServerScope ss_scope_;
1423 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001424 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001425 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001426 rtc::FakeNetworkManager network_manager_;
1427 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001428 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001429 rtc::scoped_ptr<FakeConstraints> constraints_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001430 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001431 MockIceObserver observer_;
1432 cricket::FakeVideoMediaChannel* video_channel_;
1433 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001434 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001435 // The following flags affect options created for CreateOffer/CreateAnswer.
1436 bool send_stream_1_ = false;
1437 bool send_stream_2_ = false;
1438 bool send_audio_ = false;
1439 bool send_video_ = false;
1440 rtc::scoped_refptr<DataChannel> data_channel_;
1441 // Last values received from data channel creation signal.
1442 std::string last_data_channel_label_;
1443 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001444 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001445};
1446
Henrik Boström87713d02015-08-25 09:53:21 +02001447TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1448 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001449 // SDES is disabled when DTLS is on.
1450 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451}
1452
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001453TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001454 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001455 // SDES is required if DTLS is off.
1456 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001457}
1458
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1460 TestSessionCandidatesWithBundleRtcpMux(false, false);
1461}
1462
1463// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1464// with rtcp-mux and/or bundle.
1465TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1466 TestSessionCandidatesWithBundleRtcpMux(false, true);
1467}
1468
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1470 TestSessionCandidatesWithBundleRtcpMux(true, true);
1471}
1472
1473TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001474 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1475 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001476 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001477 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001478 InitiateCall();
1479 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1480 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1481 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1482}
1483
minyuec8930ba2016-01-22 06:17:46 -08001484// Crashes on Win only. See webrtc:5411.
1485#if defined(WEBRTC_WIN)
1486#define MAYBE_TestStunError DISABLED_TestStunError
1487#else
1488#define MAYBE_TestStunError TestStunError
1489#endif
1490TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001491 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1492 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001493 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001494 rtc::FP_UDP,
1495 rtc::FD_ANY,
1496 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001497 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001498 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001499 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001500 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1502 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1503 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1504}
1505
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001506// Test session delivers no candidates gathered when constraint set to "none".
1507TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1508 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001509 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001510 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001511 InitiateCall();
1512 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1513 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1514 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1515}
1516
1517// Test session delivers only relay candidates gathered when constaint set to
1518// "relay".
1519TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1520 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1521 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001522 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001523 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001524 InitiateCall();
1525 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1526 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1527 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1528 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1529 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1530 observer_.mline_0_candidates_[i].type());
1531 }
1532 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1533 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1534 observer_.mline_1_candidates_[i].type());
1535 }
1536}
1537
1538// Test session delivers all candidates gathered when constaint set to "all".
1539TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1540 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001541 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001542 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001543 InitiateCall();
1544 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1545 // Host + STUN. By default allocator is disabled to gather relay candidates.
1546 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1547 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1548}
1549
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001550TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001551 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001552 SessionDescriptionInterface* offer = NULL;
1553 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1554 std::string unknown_action;
1555 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1556 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1557}
1558
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559// Test creating offers and receive answers and make sure the
1560// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001561TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001562 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001563 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001564 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565 const std::string session_id_orig = offer->session_id();
1566 const std::string session_version_orig = offer->session_version();
1567 SetLocalDescriptionWithoutError(offer);
1568
deadbeefab9b2d12015-10-14 11:33:11 -07001569 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570 SessionDescriptionInterface* answer =
1571 CreateRemoteAnswer(session_->local_description());
1572 SetRemoteDescriptionWithoutError(answer);
1573
1574 video_channel_ = media_engine_->GetVideoChannel(0);
1575 voice_channel_ = media_engine_->GetVoiceChannel(0);
1576
1577 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1578 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1579
1580 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1581 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1582
1583 ASSERT_EQ(1u, video_channel_->send_streams().size());
1584 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1585 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1586 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1587
1588 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001589 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001590 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591
1592 // Verify the session id is the same and the session version is
1593 // increased.
1594 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001595 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1596 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597
1598 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001599 EXPECT_EQ(0u, video_channel_->send_streams().size());
1600 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601
deadbeefab9b2d12015-10-14 11:33:11 -07001602 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 answer = CreateRemoteAnswer(session_->local_description());
1604 SetRemoteDescriptionWithoutError(answer);
1605
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 // Make sure the receive streams have not changed.
1607 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1608 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1609 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1610 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1611}
1612
1613// Test receiving offers and creating answers and make sure the
1614// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001615TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001616 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001617 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001618 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001619 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001620 SetRemoteDescriptionWithoutError(offer);
1621
deadbeefab9b2d12015-10-14 11:33:11 -07001622 SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001623 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001624 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625 SetLocalDescriptionWithoutError(answer);
1626
1627 const std::string session_id_orig = answer->session_id();
1628 const std::string session_version_orig = answer->session_version();
1629
1630 video_channel_ = media_engine_->GetVideoChannel(0);
1631 voice_channel_ = media_engine_->GetVoiceChannel(0);
1632
1633 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1634 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1635
1636 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1637 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1638
1639 ASSERT_EQ(1u, video_channel_->send_streams().size());
1640 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1641 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1642 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1643
deadbeefab9b2d12015-10-14 11:33:11 -07001644 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001645 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001646 SetRemoteDescriptionWithoutError(offer);
1647
1648 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001649 SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001650 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001651
1652 // Verify the session id is the same and the session version is
1653 // increased.
1654 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001655 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1656 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 SetLocalDescriptionWithoutError(answer);
1658
1659 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1660 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1661 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1662 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1663 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1664 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1665
1666 // Make sure we have no send streams.
1667 EXPECT_EQ(0u, video_channel_->send_streams().size());
1668 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1669}
1670
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001671TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001672 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001673 media_engine_->set_fail_create_channel(true);
1674
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001675 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001676 ASSERT_TRUE(offer != NULL);
1677 // SetRemoteDescription and SetLocalDescription will take the ownership of
1678 // the offer.
1679 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001680 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001681 ASSERT_TRUE(offer != NULL);
1682 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1683}
1684
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001685//
1686// Tests for creating/setting SDP under different SDES/DTLS polices:
1687//
1688// --DTLS off and SDES on
1689// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1690// set local/remote offer/answer with crypto --> success
1691// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1692// failure
1693// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1694// failure
1695// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1696// failure
1697//
1698// --DTLS on and SDES off
1699// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1700// set local/remote offer/answer with DTLS fingerprint --> success
1701// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1702// fingerprint --> failure
1703// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1704// --> failure
1705// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1706// --> failure
1707//
1708// --Encryption disabled: DTLS off and SDES off
1709// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1710// answer without SDES or DTLS --> success
1711// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1712// answer without SDES or DTLS --> success
1713//
1714
1715// Test that we return a failure when applying a remote/local offer that doesn't
1716// have cryptos enabled when DTLS is off.
1717TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001718 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001720 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001721 JsepSessionDescription* offer = CreateRemoteOffer(
1722 options, cricket::SEC_DISABLED);
1723 ASSERT_TRUE(offer != NULL);
1724 VerifyNoCryptoParams(offer->description(), false);
1725 // SetRemoteDescription and SetLocalDescription will take the ownership of
1726 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001727 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1729 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001730 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731}
1732
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001733// Test that we return a failure when applying a local answer that doesn't have
1734// cryptos enabled when DTLS is off.
1735TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001736 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 SessionDescriptionInterface* offer = NULL;
1738 SessionDescriptionInterface* answer = NULL;
1739 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1740 // SetRemoteDescription and SetLocalDescription will take the ownership of
1741 // the offer.
1742 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001743 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744}
1745
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001746// Test we will return fail when apply an remote answer that doesn't have
1747// crypto enabled when DTLS is off.
1748TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001749 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750 SessionDescriptionInterface* offer = NULL;
1751 SessionDescriptionInterface* answer = NULL;
1752 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1753 // SetRemoteDescription and SetLocalDescription will take the ownership of
1754 // the offer.
1755 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001756 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757}
1758
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001759// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1760// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001761TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001762 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001763 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001764 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 SetFactoryDtlsSrtp();
1766 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001767 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001768 JsepSessionDescription* offer =
1769 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770 ASSERT_TRUE(offer != NULL);
1771 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001772 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773
1774 // SetRemoteDescription will take the ownership of the offer.
1775 SetRemoteDescriptionWithoutError(offer);
1776
1777 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001778 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779 ASSERT_TRUE(answer != NULL);
1780 VerifyFingerprintStatus(answer->description(), true);
1781 // Check that we don't have an a=crypto line in the answer.
1782 VerifyNoCryptoParams(answer->description(), true);
1783
1784 // Now set the local description, which should work, even without a=crypto.
1785 SetLocalDescriptionWithoutError(answer);
1786}
1787
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001788// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1789// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001790TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001791 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001792 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001793 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001794 SetFactoryDtlsSrtp();
1795
1796 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001797 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001798 ASSERT_TRUE(offer != NULL);
1799 VerifyFingerprintStatus(offer->description(), true);
1800 // Check that we don't have an a=crypto line in the offer.
1801 VerifyNoCryptoParams(offer->description(), true);
1802
1803 // Now set the local description, which should work, even without a=crypto.
1804 SetLocalDescriptionWithoutError(offer);
1805
1806 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001807 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001808 JsepSessionDescription* answer =
1809 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1810 ASSERT_TRUE(answer != NULL);
1811 VerifyFingerprintStatus(answer->description(), true);
1812 VerifyNoCryptoParams(answer->description(), true);
1813
1814 // SetRemoteDescription will take the ownership of the answer.
1815 SetRemoteDescriptionWithoutError(answer);
1816}
1817
1818// Test that if we support DTLS and the other side didn't offer a fingerprint,
1819// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001820TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001821 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001822 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001824 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001825 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826 JsepSessionDescription* offer = CreateRemoteOffer(
1827 options, cricket::SEC_REQUIRED);
1828 ASSERT_TRUE(offer != NULL);
1829 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001830 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001832 // SetRemoteDescription will take the ownership of the offer.
1833 SetRemoteDescriptionOfferExpectError(
1834 kSdpWithoutDtlsFingerprint, offer);
1835
1836 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1837 // SetLocalDescription will take the ownership of the offer.
1838 SetLocalDescriptionOfferExpectError(
1839 kSdpWithoutDtlsFingerprint, offer);
1840}
1841
1842// Test that we return a failure when applying a local answer that doesn't have
1843// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001844TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001845 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001846 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001847 SessionDescriptionInterface* offer = NULL;
1848 SessionDescriptionInterface* answer = NULL;
1849 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1850
1851 // SetRemoteDescription and SetLocalDescription will take the ownership of
1852 // the offer and answer.
1853 SetRemoteDescriptionWithoutError(offer);
1854 SetLocalDescriptionAnswerExpectError(
1855 kSdpWithoutDtlsFingerprint, answer);
1856}
1857
1858// Test that we return a failure when applying a remote answer that doesn't have
1859// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001860TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001861 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001862 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001863 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001864 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001865 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001866 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1867 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001868 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001869 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001870
1871 // SetRemoteDescription and SetLocalDescription will take the ownership of
1872 // the offer and answer.
1873 SetLocalDescriptionWithoutError(offer);
1874 SetRemoteDescriptionAnswerExpectError(
1875 kSdpWithoutDtlsFingerprint, answer);
1876}
1877
1878// Test that we create a local offer without SDES or DTLS and accept a remote
1879// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001880TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001881 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001882 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001883 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001884
1885 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001886 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001887 ASSERT_TRUE(offer != NULL);
1888 VerifyFingerprintStatus(offer->description(), false);
1889 // Check that we don't have an a=crypto line in the offer.
1890 VerifyNoCryptoParams(offer->description(), false);
1891
1892 // Now set the local description, which should work, even without a=crypto.
1893 SetLocalDescriptionWithoutError(offer);
1894
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* answer =
1898 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1899 ASSERT_TRUE(answer != NULL);
1900 VerifyFingerprintStatus(answer->description(), false);
1901 VerifyNoCryptoParams(answer->description(), false);
1902
1903 // SetRemoteDescription will take the ownership of the answer.
1904 SetRemoteDescriptionWithoutError(answer);
1905}
1906
1907// Test that we create a local answer without SDES or DTLS and accept a remote
1908// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001909TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001910 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001911 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001912
1913 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001914 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001915 JsepSessionDescription* offer =
1916 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1917 ASSERT_TRUE(offer != NULL);
1918 VerifyFingerprintStatus(offer->description(), false);
1919 VerifyNoCryptoParams(offer->description(), false);
1920
1921 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001922 SetRemoteDescriptionWithoutError(offer);
1923
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001924 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001925 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001926 ASSERT_TRUE(answer != NULL);
1927 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001928 // Check that we don't have an a=crypto line in the answer.
1929 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001931 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001932 SetLocalDescriptionWithoutError(answer);
1933}
1934
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001935// Test that we can create and set an answer correctly when different
1936// SSL roles have been negotiated for different transports.
1937// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1938TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1939 SendAudioVideoStream1();
1940 InitWithDtls(GetParam());
1941 SetFactoryDtlsSrtp();
1942
1943 SessionDescriptionInterface* offer = CreateOffer();
1944 SetLocalDescriptionWithoutError(offer);
1945
1946 cricket::MediaSessionOptions options;
1947 options.recv_video = true;
1948
1949 // First, negotiate different SSL roles.
1950 SessionDescriptionInterface* answer =
1951 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1952 TransportInfo* audio_transport_info =
1953 answer->description()->GetTransportInfoByName("audio");
1954 audio_transport_info->description.connection_role =
1955 cricket::CONNECTIONROLE_ACTIVE;
1956 TransportInfo* video_transport_info =
1957 answer->description()->GetTransportInfoByName("video");
1958 video_transport_info->description.connection_role =
1959 cricket::CONNECTIONROLE_PASSIVE;
1960 SetRemoteDescriptionWithoutError(answer);
1961
1962 // Now create an offer in the reverse direction, and ensure the initial
1963 // offerer responds with an answer with correct SSL roles.
1964 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1965 kSessionVersion,
1966 session_->remote_description());
1967 SetRemoteDescriptionWithoutError(offer);
1968
1969 answer = CreateAnswer(nullptr);
1970 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1971 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1972 audio_transport_info->description.connection_role);
1973 video_transport_info = answer->description()->GetTransportInfoByName("video");
1974 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1975 video_transport_info->description.connection_role);
1976 SetLocalDescriptionWithoutError(answer);
1977
1978 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1979 // audio is transferred over to video in the answer that completes the BUNDLE
1980 // negotiation.
1981 options.bundle_enabled = true;
1982 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1983 kSessionVersion,
1984 session_->remote_description());
1985 SetRemoteDescriptionWithoutError(offer);
1986 answer = CreateAnswer(nullptr);
1987 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1988 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1989 audio_transport_info->description.connection_role);
1990 video_transport_info = answer->description()->GetTransportInfoByName("video");
1991 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1992 video_transport_info->description.connection_role);
1993 SetLocalDescriptionWithoutError(answer);
1994}
1995
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001997 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001998 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002000 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 SetLocalDescriptionWithoutError(offer);
2002
2003 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002004 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 SetLocalDescriptionWithoutError(offer2);
2006}
2007
2008TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002009 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002010 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002012 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013 SetRemoteDescriptionWithoutError(offer);
2014
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002015 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016 SetRemoteDescriptionWithoutError(offer2);
2017}
2018
2019TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002020 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002021 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002022 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002024 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002025 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2026 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027}
2028
2029TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002030 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002031 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002032 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002034 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002035 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002036 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037}
2038
2039TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002040 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002041 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002043 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044
2045 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002046 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002048 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049
deadbeefab9b2d12015-10-14 11:33:11 -07002050 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002052 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2054
deadbeefd59daf82015-10-14 15:02:44 -07002055 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056
deadbeefab9b2d12015-10-14 11:33:11 -07002057 SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002058 SessionDescriptionInterface* answer = CreateAnswer(NULL);
deadbeefd59daf82015-10-14 15:02:44 -07002059 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060}
2061
2062TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002063 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002064 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002065 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002066 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067
2068 JsepSessionDescription* pranswer =
2069 CreateRemoteAnswer(session_->local_description());
2070 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2071
2072 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002073 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074
deadbeefab9b2d12015-10-14 11:33:11 -07002075 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002076 JsepSessionDescription* pranswer2 =
2077 CreateRemoteAnswer(session_->local_description());
2078 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2079
2080 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002081 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082
deadbeefab9b2d12015-10-14 11:33:11 -07002083 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084 SessionDescriptionInterface* answer =
2085 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002086 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087}
2088
2089TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002090 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002091 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002092 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2093
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094 SessionDescriptionInterface* answer =
2095 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002096 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2097 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098}
2099
2100TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002101 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002102 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002103 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2104
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105 SessionDescriptionInterface* answer =
2106 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002107 SetRemoteDescriptionAnswerExpectError(
2108 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109}
2110
2111TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002112 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002113 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114
2115 cricket::Candidate candidate;
2116 candidate.set_component(1);
2117 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2118
deadbeefd59daf82015-10-14 15:02:44 -07002119 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2121
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002122 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002124
2125 // Fail since we have not set a remote description.
2126 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127
2128 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2129 session_->local_description());
2130 SetRemoteDescriptionWithoutError(answer);
2131
deadbeefd59daf82015-10-14 15:02:44 -07002132 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2133 candidate.set_component(2);
2134 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2135 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2136
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137 // Verifying the candidates are copied properly from internal vector.
2138 const SessionDescriptionInterface* remote_desc =
2139 session_->remote_description();
2140 ASSERT_TRUE(remote_desc != NULL);
2141 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2142 const IceCandidateCollection* candidates =
2143 remote_desc->candidates(kMediaContentIndex0);
2144 ASSERT_EQ(2u, candidates->count());
2145 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2146 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2147 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2148 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2149
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002150 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2151 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 candidate.set_component(2);
2153 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2154 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002155 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156
2157 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2158 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2159}
2160
2161// Test that a remote candidate is added to the remote session description and
2162// that it is retained if the remote session description is changed.
2163TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002164 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165 cricket::Candidate candidate1;
2166 candidate1.set_component(1);
2167 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2168 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002169 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 CreateAndSetRemoteOfferAndLocalAnswer();
2171
2172 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2173 const SessionDescriptionInterface* remote_desc =
2174 session_->remote_description();
2175 ASSERT_TRUE(remote_desc != NULL);
2176 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2177 const IceCandidateCollection* candidates =
2178 remote_desc->candidates(kMediaContentIndex0);
2179 ASSERT_EQ(1u, candidates->count());
2180 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2181
2182 // Update the RemoteSessionDescription with a new session description and
2183 // a candidate and check that the new remote session description contains both
2184 // candidates.
2185 SessionDescriptionInterface* offer = CreateRemoteOffer();
2186 cricket::Candidate candidate2;
2187 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2188 candidate2);
2189 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2190 SetRemoteDescriptionWithoutError(offer);
2191
2192 remote_desc = session_->remote_description();
2193 ASSERT_TRUE(remote_desc != NULL);
2194 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2195 candidates = remote_desc->candidates(kMediaContentIndex0);
2196 ASSERT_EQ(2u, candidates->count());
2197 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2198 // Username and password have be updated with the TransportInfo of the
2199 // SessionDescription, won't be equal to the original one.
2200 candidate2.set_username(candidates->at(0)->candidate().username());
2201 candidate2.set_password(candidates->at(0)->candidate().password());
2202 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2203 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2204 // No need to verify the username and password.
2205 candidate1.set_username(candidates->at(1)->candidate().username());
2206 candidate1.set_password(candidates->at(1)->candidate().password());
2207 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2208
2209 // Test that the candidate is ignored if we can add the same candidate again.
2210 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2211}
2212
2213// Test that local candidates are added to the local session description and
2214// that they are retained if the local session description is changed.
2215TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002216 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002217 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002218 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219 CreateAndSetRemoteOfferAndLocalAnswer();
2220
2221 const SessionDescriptionInterface* local_desc = session_->local_description();
2222 const IceCandidateCollection* candidates =
2223 local_desc->candidates(kMediaContentIndex0);
2224 ASSERT_TRUE(candidates != NULL);
2225 EXPECT_EQ(0u, candidates->count());
2226
2227 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2228
2229 local_desc = session_->local_description();
2230 candidates = local_desc->candidates(kMediaContentIndex0);
2231 ASSERT_TRUE(candidates != NULL);
2232 EXPECT_LT(0u, candidates->count());
2233 candidates = local_desc->candidates(1);
2234 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002235 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002236
2237 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002238 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 CreateAndSetRemoteOfferAndLocalAnswer();
2240
2241 local_desc = session_->local_description();
2242 candidates = local_desc->candidates(kMediaContentIndex0);
2243 ASSERT_TRUE(candidates != NULL);
2244 EXPECT_LT(0u, candidates->count());
2245 candidates = local_desc->candidates(1);
2246 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002247 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002248}
2249
2250// Test that we can set a remote session description with remote candidates.
2251TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002252 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253
2254 cricket::Candidate candidate1;
2255 candidate1.set_component(1);
2256 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2257 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002258 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002259 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260
2261 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2262 SetRemoteDescriptionWithoutError(offer);
2263
2264 const SessionDescriptionInterface* remote_desc =
2265 session_->remote_description();
2266 ASSERT_TRUE(remote_desc != NULL);
2267 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2268 const IceCandidateCollection* candidates =
2269 remote_desc->candidates(kMediaContentIndex0);
2270 ASSERT_EQ(1u, candidates->count());
2271 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2272
wu@webrtc.org91053e72013-08-10 07:18:04 +00002273 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274 SetLocalDescriptionWithoutError(answer);
2275}
2276
2277// Test that offers and answers contains ice candidates when Ice candidates have
2278// been gathered.
2279TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002280 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002281 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002282 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 // Ice is started but candidates are not provided until SetLocalDescription
2284 // is called.
2285 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2286 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2287 CreateAndSetRemoteOfferAndLocalAnswer();
2288 // Wait until at least one local candidate has been collected.
2289 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2290 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002292 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2293
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2295 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002296
2297 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2298 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002299 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2301 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302 SetLocalDescriptionWithoutError(answer);
2303}
2304
2305// Verifies TransportProxy and media channels are created with content names
2306// present in the SessionDescription.
2307TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002308 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002309 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002310 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311
2312 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002313 // "video". Goal is to modify these content names and verify transport
2314 // channels
2315 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 // present in SDP.
2317 std::string sdp;
2318 EXPECT_TRUE(offer->ToString(&sdp));
2319 const std::string kAudioMid = "a=mid:audio";
2320 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2321 const std::string kVideoMid = "a=mid:video";
2322 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2323
2324 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002325 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 kAudioMidReplaceStr.c_str(),
2327 kAudioMidReplaceStr.length(),
2328 &sdp);
2329 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002330 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331 kVideoMidReplaceStr.c_str(),
2332 kVideoMidReplaceStr.length(),
2333 &sdp);
2334
2335 SessionDescriptionInterface* modified_offer =
2336 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2337
2338 SetRemoteDescriptionWithoutError(modified_offer);
2339
2340 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002341 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342 SetLocalDescriptionWithoutError(answer);
2343
deadbeefcbecd352015-09-23 11:50:27 -07002344 cricket::TransportChannel* voice_transport_channel =
2345 session_->voice_rtp_transport_channel();
2346 EXPECT_TRUE(voice_transport_channel != NULL);
2347 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2348 cricket::TransportChannel* video_transport_channel =
2349 session_->video_rtp_transport_channel();
2350 EXPECT_TRUE(video_transport_channel != NULL);
2351 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2353 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2354}
2355
2356// Test that an offer contains the correct media content descriptions based on
2357// the send streams when no constraints have been set.
2358TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002359 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002360 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2361
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362 ASSERT_TRUE(offer != NULL);
2363 const cricket::ContentInfo* content =
2364 cricket::GetFirstAudioContent(offer->description());
2365 EXPECT_TRUE(content != NULL);
2366 content = cricket::GetFirstVideoContent(offer->description());
2367 EXPECT_TRUE(content == NULL);
2368}
2369
2370// Test that an offer contains the correct media content descriptions based on
2371// the send streams when no constraints have been set.
2372TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002373 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002375 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002376 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2377
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 const cricket::ContentInfo* content =
2379 cricket::GetFirstAudioContent(offer->description());
2380 EXPECT_TRUE(content != NULL);
2381 content = cricket::GetFirstVideoContent(offer->description());
2382 EXPECT_TRUE(content == NULL);
2383
2384 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002385 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002386 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387 content = cricket::GetFirstAudioContent(offer->description());
2388 EXPECT_TRUE(content != NULL);
2389 content = cricket::GetFirstVideoContent(offer->description());
2390 EXPECT_TRUE(content != NULL);
2391}
2392
2393// Test that an offer contains no media content descriptions if
2394// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2395TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002396 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002397 PeerConnectionInterface::RTCOfferAnswerOptions options;
2398 options.offer_to_receive_audio = 0;
2399 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002401 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002402 CreateOffer(options));
2403
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404 ASSERT_TRUE(offer != NULL);
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 only audio media content descriptions if
2413// kOfferToReceiveAudio constraints are set to true.
2414TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002415 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002416 PeerConnectionInterface::RTCOfferAnswerOptions options;
2417 options.offer_to_receive_audio =
2418 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2419
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002420 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002421 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002422
2423 const cricket::ContentInfo* content =
2424 cricket::GetFirstAudioContent(offer->description());
2425 EXPECT_TRUE(content != NULL);
2426 content = cricket::GetFirstVideoContent(offer->description());
2427 EXPECT_TRUE(content == NULL);
2428}
2429
2430// Test that an offer contains audio and video media content descriptions if
2431// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2432TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002433 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002435 PeerConnectionInterface::RTCOfferAnswerOptions options;
2436 options.offer_to_receive_audio =
2437 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2438 options.offer_to_receive_video =
2439 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2440
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002441 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002442 CreateOffer(options));
2443
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444 const cricket::ContentInfo* content =
2445 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002446 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002447
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002448 content = cricket::GetFirstVideoContent(offer->description());
2449 EXPECT_TRUE(content != NULL);
2450
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002451 // Sets constraints to false and verifies that audio/video contents are
2452 // removed.
2453 options.offer_to_receive_audio = 0;
2454 options.offer_to_receive_video = 0;
2455 offer.reset(CreateOffer(options));
2456
2457 content = cricket::GetFirstAudioContent(offer->description());
2458 EXPECT_TRUE(content == NULL);
2459 content = cricket::GetFirstVideoContent(offer->description());
2460 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002461}
2462
2463// Test that an answer can not be created if the last remote description is not
2464// an offer.
2465TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002466 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002467 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002468 SetLocalDescriptionWithoutError(offer);
2469 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2470 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002471 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002472}
2473
2474// Test that an answer contains the correct media content descriptions when no
2475// constraints have been set.
2476TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002477 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002479 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002481 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002482 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002483 const cricket::ContentInfo* content =
2484 cricket::GetFirstAudioContent(answer->description());
2485 ASSERT_TRUE(content != NULL);
2486 EXPECT_FALSE(content->rejected);
2487
2488 content = cricket::GetFirstVideoContent(answer->description());
2489 ASSERT_TRUE(content != NULL);
2490 EXPECT_FALSE(content->rejected);
2491}
2492
2493// Test that an answer contains the correct media content descriptions when no
2494// constraints have been set and the offer only contain audio.
2495TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002496 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497 // Create a remote offer with audio only.
2498 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002499
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002500 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002501 CreateRemoteOffer(options));
2502 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2503 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2504
2505 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002506 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002507 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002508 const cricket::ContentInfo* content =
2509 cricket::GetFirstAudioContent(answer->description());
2510 ASSERT_TRUE(content != NULL);
2511 EXPECT_FALSE(content->rejected);
2512
2513 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2514}
2515
2516// Test that an answer contains the correct media content descriptions when no
2517// constraints have been set.
2518TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002519 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002521 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002522 SetRemoteDescriptionWithoutError(offer.release());
2523 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002524 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002525 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002526 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002527 const cricket::ContentInfo* content =
2528 cricket::GetFirstAudioContent(answer->description());
2529 ASSERT_TRUE(content != NULL);
2530 EXPECT_FALSE(content->rejected);
2531
2532 content = cricket::GetFirstVideoContent(answer->description());
2533 ASSERT_TRUE(content != NULL);
2534 EXPECT_FALSE(content->rejected);
2535}
2536
2537// Test that an answer contains the correct media content descriptions when
2538// constraints have been set but no stream is sent.
2539TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002540 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002541 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002542 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002543 SetRemoteDescriptionWithoutError(offer.release());
2544
2545 webrtc::FakeConstraints constraints_no_receive;
2546 constraints_no_receive.SetMandatoryReceiveAudio(false);
2547 constraints_no_receive.SetMandatoryReceiveVideo(false);
2548
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002549 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002550 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551 const cricket::ContentInfo* content =
2552 cricket::GetFirstAudioContent(answer->description());
2553 ASSERT_TRUE(content != NULL);
2554 EXPECT_TRUE(content->rejected);
2555
2556 content = cricket::GetFirstVideoContent(answer->description());
2557 ASSERT_TRUE(content != NULL);
2558 EXPECT_TRUE(content->rejected);
2559}
2560
2561// Test that an answer contains the correct media content descriptions when
2562// constraints have been set and streams are sent.
2563TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002564 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002565 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002566 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002567 SetRemoteDescriptionWithoutError(offer.release());
2568
2569 webrtc::FakeConstraints constraints_no_receive;
2570 constraints_no_receive.SetMandatoryReceiveAudio(false);
2571 constraints_no_receive.SetMandatoryReceiveVideo(false);
2572
2573 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002574 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002575 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002576 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002577
2578 // TODO(perkj): Should the direction be set to SEND_ONLY?
2579 const cricket::ContentInfo* content =
2580 cricket::GetFirstAudioContent(answer->description());
2581 ASSERT_TRUE(content != NULL);
2582 EXPECT_FALSE(content->rejected);
2583
2584 // TODO(perkj): Should the direction be set to SEND_ONLY?
2585 content = cricket::GetFirstVideoContent(answer->description());
2586 ASSERT_TRUE(content != NULL);
2587 EXPECT_FALSE(content->rejected);
2588}
2589
2590TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2591 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002592 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002593 PeerConnectionInterface::RTCOfferAnswerOptions options;
2594 options.offer_to_receive_audio =
2595 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2596 options.voice_activity_detection = false;
2597
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002598 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002599 CreateOffer(options));
2600
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601 const cricket::ContentInfo* content =
2602 cricket::GetFirstAudioContent(offer->description());
2603 EXPECT_TRUE(content != NULL);
2604 EXPECT_TRUE(VerifyNoCNCodecs(content));
2605}
2606
2607TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2608 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002609 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002610 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002611 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002612 SetRemoteDescriptionWithoutError(offer.release());
2613
2614 webrtc::FakeConstraints constraints;
2615 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002616 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002617 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002618 const cricket::ContentInfo* content =
2619 cricket::GetFirstAudioContent(answer->description());
2620 ASSERT_TRUE(content != NULL);
2621 EXPECT_TRUE(VerifyNoCNCodecs(content));
2622}
2623
2624// This test verifies the call setup when remote answer with audio only and
2625// later updates with video.
2626TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002627 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002628 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2629 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2630
deadbeefab9b2d12015-10-14 11:33:11 -07002631 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002632 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002633
2634 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002635 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2636
2637 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2638 // and answer;
2639 SetLocalDescriptionWithoutError(offer);
2640 SetRemoteDescriptionWithoutError(answer);
2641
2642 video_channel_ = media_engine_->GetVideoChannel(0);
2643 voice_channel_ = media_engine_->GetVoiceChannel(0);
2644
2645 ASSERT_TRUE(video_channel_ == NULL);
2646
2647 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2648 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2649 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2650
2651 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002652 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002653 CreateAndSetRemoteOfferAndLocalAnswer();
2654
2655 video_channel_ = media_engine_->GetVideoChannel(0);
2656 voice_channel_ = media_engine_->GetVoiceChannel(0);
2657
2658 ASSERT_TRUE(video_channel_ != NULL);
2659 ASSERT_TRUE(voice_channel_ != NULL);
2660
2661 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2662 ASSERT_EQ(1u, video_channel_->send_streams().size());
2663 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2664 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2665 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2666 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2667 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2668 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2669
2670 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002671 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002672 CreateAndSetRemoteOfferAndLocalAnswer();
2673
2674 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2675 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2676 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2677 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2678 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2679}
2680
2681// This test verifies the call setup when remote answer with video only and
2682// later updates with audio.
2683TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002684 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002685 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2686 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002687 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002688 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002689
2690 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002691 options.recv_audio = false;
2692 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002693 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2694 offer, options, cricket::SEC_ENABLED);
2695
2696 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2697 // and answer.
2698 SetLocalDescriptionWithoutError(offer);
2699 SetRemoteDescriptionWithoutError(answer);
2700
2701 video_channel_ = media_engine_->GetVideoChannel(0);
2702 voice_channel_ = media_engine_->GetVoiceChannel(0);
2703
2704 ASSERT_TRUE(voice_channel_ == NULL);
2705 ASSERT_TRUE(video_channel_ != NULL);
2706
2707 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2708 ASSERT_EQ(1u, video_channel_->send_streams().size());
2709 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2710
2711 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002712 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002713 CreateAndSetRemoteOfferAndLocalAnswer();
2714
2715 voice_channel_ = media_engine_->GetVoiceChannel(0);
2716 ASSERT_TRUE(voice_channel_ != NULL);
2717
2718 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2719 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2720 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2721 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2722
2723 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002724 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725 CreateAndSetRemoteOfferAndLocalAnswer();
2726
2727 video_channel_ = media_engine_->GetVideoChannel(0);
2728 voice_channel_ = media_engine_->GetVoiceChannel(0);
2729
2730 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2731 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2732 ASSERT_EQ(1u, video_channel_->send_streams().size());
2733 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2734}
2735
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002736TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002737 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002738 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002739 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002740 VerifyCryptoParams(offer->description());
2741 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002742 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002743 VerifyCryptoParams(answer->description());
2744}
2745
2746TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002747 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002748 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002749 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002750 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002751 VerifyNoCryptoParams(offer->description(), false);
2752}
2753
2754TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002755 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002756 VerifyAnswerFromNonCryptoOffer();
2757}
2758
2759TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002760 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002761 VerifyAnswerFromCryptoOffer();
2762}
2763
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002764// This test verifies that setLocalDescription fails if
2765// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2766TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002767 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002768 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002769 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2770
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002771 std::string sdp;
2772 RemoveIceUfragPwdLines(offer.get(), &sdp);
2773 SessionDescriptionInterface* modified_offer =
2774 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002775 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002776}
2777
2778// This test verifies that setRemoteDescription fails if
2779// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2780TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002781 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002782 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002783 std::string sdp;
2784 RemoveIceUfragPwdLines(offer.get(), &sdp);
2785 SessionDescriptionInterface* modified_offer =
2786 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002787 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002788}
2789
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002790// This test verifies that setLocalDescription fails if local offer has
2791// too short ice ufrag and pwd strings.
2792TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002793 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002794 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002795 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002796 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2797 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002798 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002799 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002800 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002801
2802 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002803 offer.reset(CreateOffer());
2804 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2805 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002806}
2807
2808// This test verifies that setRemoteDescription fails if remote offer has
2809// too short ice ufrag and pwd strings.
2810TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002811 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002812 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002813 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2814 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002815 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002816 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002817 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002818
deadbeef0ed85b22016-02-23 17:24:52 -08002819 offer.reset(CreateRemoteOffer());
2820 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2821 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002822}
2823
Honghai Zhang04e91462015-12-11 14:26:22 -08002824// Test that if the remote offer indicates the peer requested ICE restart (via
2825// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2826TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002827 Init();
honghaiz503726c2015-07-31 12:37:38 -07002828
2829 // Create the first offer.
deadbeef0ed85b22016-02-23 17:24:52 -08002830 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2831 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002832 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2833 0, "", "", "relay", 0, "");
2834 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2835 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002836 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2837 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002838 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2839
2840 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002841 offer.reset(CreateRemoteOffer());
2842 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002843 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2844 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2845 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002846 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2847 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002848 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2849
2850 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002851 offer.reset(CreateRemoteOffer());
2852 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002853 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2854 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2855 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002856 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2857 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002858 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2859
2860 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002861 offer.reset(CreateRemoteOffer());
2862 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2863 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002864 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2865}
2866
Honghai Zhang04e91462015-12-11 14:26:22 -08002867// Test that if the remote answer indicates the peer requested ICE restart (via
2868// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2869TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2870 Init();
2871 SessionDescriptionInterface* offer = CreateOffer();
2872 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002873
2874 // Create the first answer.
deadbeef0ed85b22016-02-23 17:24:52 -08002875 scoped_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
2876 answer->set_type(JsepSessionDescription::kPrAnswer);
2877 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002878 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2879 0, "", "", "relay", 0, "");
2880 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2881 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002882 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2883 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002884 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2885
2886 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002887 answer.reset(CreateRemoteAnswer(offer));
2888 answer->set_type(JsepSessionDescription::kPrAnswer);
2889 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002890 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2891 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2892 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002893 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2894 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002895 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2896
2897 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002898 answer.reset(CreateRemoteAnswer(offer));
2899 answer->set_type(JsepSessionDescription::kPrAnswer);
2900 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002901 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2902 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2903 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002904 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2905 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002906 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2907
2908 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002909 answer.reset(CreateRemoteAnswer(offer));
2910 answer->set_type(JsepSessionDescription::kPrAnswer);
2911 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2912 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002913 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2914}
2915
Donald Curtisd4f769d2015-05-28 09:48:21 -07002916// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002917// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002918TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2919 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2920
2921 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002922 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002923
2924 PeerConnectionInterface::RTCOfferAnswerOptions options;
2925 options.use_rtp_mux = true;
2926
2927 SessionDescriptionInterface* offer = CreateRemoteOffer();
2928 SetRemoteDescriptionWithoutError(offer);
2929
2930 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2931 SetLocalDescriptionWithoutError(answer);
2932
deadbeefcbecd352015-09-23 11:50:27 -07002933 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2934 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002935
deadbeefcbecd352015-09-23 11:50:27 -07002936 cricket::BaseChannel* voice_channel = session_->voice_channel();
2937 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002938
2939 // Checks if one of the transport channels contains a connection using a given
2940 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002941 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002942 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002943 session_->GetChannelTransportStats(voice_channel, &stats);
2944 for (auto& kv : stats.transport_stats) {
2945 for (auto& chan_stat : kv.second.channel_stats) {
2946 for (auto& conn_info : chan_stat.connection_infos) {
2947 if (conn_info.remote_candidate.address().port() == port) {
2948 return true;
2949 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002950 }
2951 }
2952 }
2953 return false;
2954 };
2955
2956 EXPECT_FALSE(connection_with_remote_port(5000));
2957 EXPECT_FALSE(connection_with_remote_port(5001));
2958 EXPECT_FALSE(connection_with_remote_port(6000));
2959
2960 // The way the *_WAIT checks work is they only wait if the condition fails,
2961 // which does not help in the case where state is not changing. This is
2962 // problematic in this test since we want to verify that adding a video
2963 // candidate does _not_ change state. So we interleave candidates and assume
2964 // that messages are executed in the order they were posted.
2965
2966 // First audio candidate.
2967 cricket::Candidate candidate0;
2968 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2969 candidate0.set_component(1);
2970 candidate0.set_protocol("udp");
2971 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2972 candidate0);
2973 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2974
2975 // Video candidate.
2976 cricket::Candidate candidate1;
2977 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2978 candidate1.set_component(1);
2979 candidate1.set_protocol("udp");
2980 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2981 candidate1);
2982 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2983
2984 // Second audio candidate.
2985 cricket::Candidate candidate2;
2986 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2987 candidate2.set_component(1);
2988 candidate2.set_protocol("udp");
2989 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2990 candidate2);
2991 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2992
2993 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2994 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2995
2996 // No need here for a _WAIT check since we are checking that state hasn't
2997 // changed: if this is false we would be doing waits for nothing and if this
2998 // is true then there will be no messages processed anyways.
2999 EXPECT_FALSE(connection_with_remote_port(6000));
3000}
3001
deadbeefcbecd352015-09-23 11:50:27 -07003002// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003003TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3004 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003005 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003006
3007 PeerConnectionInterface::RTCOfferAnswerOptions options;
3008 options.use_rtp_mux = true;
3009
3010 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003011 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003012
deadbeefcbecd352015-09-23 11:50:27 -07003013 EXPECT_NE(session_->voice_rtp_transport_channel(),
3014 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003015
deadbeefab9b2d12015-10-14 11:33:11 -07003016 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003017 SessionDescriptionInterface* answer =
3018 CreateRemoteAnswer(session_->local_description());
3019 SetRemoteDescriptionWithoutError(answer);
3020
deadbeefcbecd352015-09-23 11:50:27 -07003021 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3022 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003023}
3024
deadbeefcbecd352015-09-23 11:50:27 -07003025// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003026TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3027 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003028 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003029
Donald Curtis0e209b02015-03-24 09:29:54 -07003030 PeerConnectionInterface::RTCOfferAnswerOptions options;
3031 options.use_rtp_mux = true;
3032
3033 SessionDescriptionInterface* offer = CreateOffer(options);
3034 SetLocalDescriptionWithoutError(offer);
3035
deadbeefcbecd352015-09-23 11:50:27 -07003036 EXPECT_NE(session_->voice_rtp_transport_channel(),
3037 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003038
deadbeefab9b2d12015-10-14 11:33:11 -07003039 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003040
3041 // Remove BUNDLE from the answer.
3042 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3043 CreateRemoteAnswer(session_->local_description()));
3044 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3045 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3046 JsepSessionDescription* modified_answer =
3047 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3048 modified_answer->Initialize(answer_copy, "1", "1");
3049 SetRemoteDescriptionWithoutError(modified_answer); //
3050
deadbeefcbecd352015-09-23 11:50:27 -07003051 EXPECT_NE(session_->voice_rtp_transport_channel(),
3052 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003053}
3054
3055// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3056TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3057 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003058 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003059
3060 PeerConnectionInterface::RTCOfferAnswerOptions options;
3061 options.use_rtp_mux = true;
3062
3063 SessionDescriptionInterface* offer = CreateOffer(options);
3064 SetLocalDescriptionWithoutError(offer);
3065
deadbeefcbecd352015-09-23 11:50:27 -07003066 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3067 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003068
deadbeefab9b2d12015-10-14 11:33:11 -07003069 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003070 SessionDescriptionInterface* answer =
3071 CreateRemoteAnswer(session_->local_description());
3072 SetRemoteDescriptionWithoutError(answer);
3073
deadbeefcbecd352015-09-23 11:50:27 -07003074 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3075 session_->video_rtp_transport_channel());
3076}
3077
3078// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3079// audio content in the answer.
3080TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3081 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003082 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003083
3084 PeerConnectionInterface::RTCOfferAnswerOptions options;
3085 options.use_rtp_mux = true;
3086
3087 SessionDescriptionInterface* offer = CreateOffer(options);
3088 SetLocalDescriptionWithoutError(offer);
3089
3090 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3091 session_->video_rtp_transport_channel());
3092
deadbeefab9b2d12015-10-14 11:33:11 -07003093 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003094 cricket::MediaSessionOptions recv_options;
3095 recv_options.recv_audio = false;
3096 recv_options.recv_video = true;
3097 SessionDescriptionInterface* answer =
3098 CreateRemoteAnswer(session_->local_description(), recv_options);
3099 SetRemoteDescriptionWithoutError(answer);
3100
deadbeefd59daf82015-10-14 15:02:44 -07003101 EXPECT_TRUE(nullptr == session_->voice_channel());
3102 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003103
deadbeefd59daf82015-10-14 15:02:44 -07003104 session_->Close();
3105 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3106 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3107 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3108 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003109}
3110
3111// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3112TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3113 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003114 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003115
Donald Curtis0e209b02015-03-24 09:29:54 -07003116 PeerConnectionInterface::RTCOfferAnswerOptions options;
3117 options.use_rtp_mux = true;
3118
3119 SessionDescriptionInterface* offer = CreateOffer(options);
3120 SetLocalDescriptionWithoutError(offer);
3121
deadbeefcbecd352015-09-23 11:50:27 -07003122 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3123 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003124
deadbeefab9b2d12015-10-14 11:33:11 -07003125 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003126
3127 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003128 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003129 CreateRemoteAnswer(session_->local_description()));
3130 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3131 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3132 JsepSessionDescription* modified_answer =
3133 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3134 modified_answer->Initialize(answer_copy, "1", "1");
3135 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003136
deadbeefcbecd352015-09-23 11:50:27 -07003137 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3138 session_->video_rtp_transport_channel());
3139}
3140
3141// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3142TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3143 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003144 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003145
3146 SessionDescriptionInterface* offer = CreateRemoteOffer();
3147 SetRemoteDescriptionWithoutError(offer);
3148
3149 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3150 session_->video_rtp_transport_channel());
3151
deadbeefab9b2d12015-10-14 11:33:11 -07003152 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003153 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
3154 SetLocalDescriptionWithoutError(answer);
3155
3156 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3157 session_->video_rtp_transport_channel());
3158}
3159
3160// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3161TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3162 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003163 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003164
3165 // Remove BUNDLE from the offer.
3166 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3167 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3168 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3169 JsepSessionDescription* modified_offer =
3170 new JsepSessionDescription(JsepSessionDescription::kOffer);
3171 modified_offer->Initialize(offer_copy, "1", "1");
3172
3173 // Expect an error when applying the remote description
3174 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3175 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003176}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003177
Peter Thatcher4eddf182015-04-30 10:55:59 -07003178// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003179TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3180 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003181 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003182
Donald Curtis0e209b02015-03-24 09:29:54 -07003183 PeerConnectionInterface::RTCOfferAnswerOptions options;
3184 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003185
Donald Curtis0e209b02015-03-24 09:29:54 -07003186 SessionDescriptionInterface* offer = CreateOffer(options);
3187 SetLocalDescriptionWithoutError(offer);
3188
deadbeefcbecd352015-09-23 11:50:27 -07003189 EXPECT_NE(session_->voice_rtp_transport_channel(),
3190 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003191
deadbeefab9b2d12015-10-14 11:33:11 -07003192 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003193 SessionDescriptionInterface* answer =
3194 CreateRemoteAnswer(session_->local_description());
3195 SetRemoteDescriptionWithoutError(answer);
3196
3197 // This should lead to an audio-only call but isn't implemented
3198 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003199 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3200 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003201}
3202
deadbeefcbecd352015-09-23 11:50:27 -07003203// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003204TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3205 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003206 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003207 PeerConnectionInterface::RTCOfferAnswerOptions options;
3208 options.use_rtp_mux = true;
3209
3210 SessionDescriptionInterface* offer = CreateOffer(options);
3211 SetLocalDescriptionWithoutError(offer);
3212
deadbeefcbecd352015-09-23 11:50:27 -07003213 EXPECT_NE(session_->voice_rtp_transport_channel(),
3214 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003215
deadbeefab9b2d12015-10-14 11:33:11 -07003216 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003217
3218 // Remove BUNDLE from the answer.
3219 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3220 CreateRemoteAnswer(session_->local_description()));
3221 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3222 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3223 JsepSessionDescription* modified_answer =
3224 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3225 modified_answer->Initialize(answer_copy, "1", "1");
3226 SetRemoteDescriptionWithoutError(modified_answer); //
3227
deadbeefcbecd352015-09-23 11:50:27 -07003228 EXPECT_NE(session_->voice_rtp_transport_channel(),
3229 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003230}
3231
Peter Thatcher4eddf182015-04-30 10:55:59 -07003232// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3233TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3234 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003235 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003236
3237 PeerConnectionInterface::RTCOfferAnswerOptions options;
3238 options.use_rtp_mux = true;
3239
3240 SessionDescriptionInterface* offer = CreateOffer(options);
3241 SetRemoteDescriptionWithoutError(offer);
3242
deadbeefcbecd352015-09-23 11:50:27 -07003243 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3244 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003245}
3246
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003247TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3248 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003249 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003250
3251 PeerConnectionInterface::RTCOfferAnswerOptions options;
3252 SessionDescriptionInterface* offer = CreateOffer(options);
3253 SetLocalDescriptionWithoutError(offer);
3254
deadbeefcbecd352015-09-23 11:50:27 -07003255 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3256 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003257
deadbeefab9b2d12015-10-14 11:33:11 -07003258 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003259 SessionDescriptionInterface* answer =
3260 CreateRemoteAnswer(session_->local_description());
3261 SetRemoteDescriptionWithoutError(answer);
3262
deadbeefcbecd352015-09-23 11:50:27 -07003263 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3264 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003265}
3266
3267TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3268 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003269 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003270
3271 PeerConnectionInterface::RTCOfferAnswerOptions options;
3272 SessionDescriptionInterface* offer = CreateOffer(options);
3273 SetLocalDescriptionWithoutError(offer);
3274
deadbeefcbecd352015-09-23 11:50:27 -07003275 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3276 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003277
deadbeefab9b2d12015-10-14 11:33:11 -07003278 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003279 SessionDescriptionInterface* answer =
3280 CreateRemoteAnswer(session_->local_description());
3281 SetRemoteDescriptionWithoutError(answer);
3282
deadbeefcbecd352015-09-23 11:50:27 -07003283 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3284 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003285}
3286
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003287// This test verifies that SetLocalDescription and SetRemoteDescription fails
3288// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3289TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003290 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003291 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003292
3293 PeerConnectionInterface::RTCOfferAnswerOptions options;
3294 options.use_rtp_mux = true;
3295
3296 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003297 std::string offer_str;
3298 offer->ToString(&offer_str);
3299 // Disable rtcp-mux
3300 const std::string rtcp_mux = "rtcp-mux";
3301 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003302 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003303 xrtcp_mux.c_str(), xrtcp_mux.length(),
3304 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003305 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003306 new JsepSessionDescription(JsepSessionDescription::kOffer);
3307 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003308 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003309 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003310 new JsepSessionDescription(JsepSessionDescription::kOffer);
3311 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003312 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003313 // Trying unmodified SDP.
3314 SetLocalDescriptionWithoutError(offer);
3315}
3316
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003317TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003318 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003319 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003320 CreateAndSetRemoteOfferAndLocalAnswer();
3321 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3322 ASSERT_TRUE(channel != NULL);
3323 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003324 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003325 double volume;
3326 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3327 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003328 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003329 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3330 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003331 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003332 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3333 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003334}
3335
3336TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003337 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003338 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003339 CreateAndSetRemoteOfferAndLocalAnswer();
3340 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3341 ASSERT_TRUE(channel != NULL);
3342 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003343 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003344 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3345
3346 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003347 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003348
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003349 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003350 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003351 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003352 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003353 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003354
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003355 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003356 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003357 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003358 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003359 EXPECT_TRUE(renderer->sink() == NULL);
3360}
3361
3362TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003363 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003364 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003365 CreateAndSetRemoteOfferAndLocalAnswer();
3366 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3367 ASSERT_TRUE(channel != NULL);
3368 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003369 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003370
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003371 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003372 cricket::AudioOptions options;
3373 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3374 EXPECT_TRUE(renderer->sink() != NULL);
3375
3376 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3377 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3378 // SetSink(NULL) callback afterwards.
3379 renderer.reset();
3380
3381 // This will trigger SetSink(NULL) if no OnClose() callback.
3382 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003383}
3384
3385TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003386 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003387 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003388 CreateAndSetRemoteOfferAndLocalAnswer();
3389 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3390 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003391 ASSERT_LT(0u, channel->sinks().size());
3392 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003393 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003394 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003395 cricket::FakeVideoRenderer renderer;
3396 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003397 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003398 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003399 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003400}
3401
3402TEST_F(WebRtcSessionTest, SetVideoSend) {
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);
3408 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003409 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003410 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3411 cricket::VideoOptions* options = NULL;
3412 session_->SetVideoSend(send_ssrc, false, options);
3413 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3414 session_->SetVideoSend(send_ssrc, true, options);
3415 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3416}
3417
3418TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3419 TestCanInsertDtmf(false);
3420}
3421
3422TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3423 TestCanInsertDtmf(true);
3424}
3425
3426TEST_F(WebRtcSessionTest, InsertDtmf) {
3427 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003428 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003429 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003430 CreateAndSetRemoteOfferAndLocalAnswer();
3431 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3432 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3433
3434 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003435 const int expected_duration = 90;
3436 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3437 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3438 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3439
3440 // Verify
3441 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003442 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003443 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003444 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003445 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003446 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003447 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003448 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003449}
3450
deadbeefd59daf82015-10-14 15:02:44 -07003451// This test verifies the |initial_offerer| flag when session initiates the
3452// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003453TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003454 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003455 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003456 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003457 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3458 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003459 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003460 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003461 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003462}
3463
deadbeefd59daf82015-10-14 15:02:44 -07003464// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003465TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003466 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003467 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003468 SessionDescriptionInterface* offer = CreateRemoteOffer();
3469 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003470 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003471
deadbeefd59daf82015-10-14 15:02:44 -07003472 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003473 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003474 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003475}
3476
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003477// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3478TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003479 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003480 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003481 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003482 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003483 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003484 CreateRemoteAnswer(session_->local_description()));
3485
3486 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3487 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003488 JsepSessionDescription* modified_answer =
3489 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490
3491 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3492 answer->session_id(),
3493 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003494 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495
wu@webrtc.org4e393072014-04-07 17:04:35 +00003496 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003497 std::string sdp;
3498 EXPECT_TRUE(answer->ToString(&sdp));
3499 const std::string kAudioMid = "a=mid:audio";
3500 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003501 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003502 kAudioMidReplaceStr.c_str(),
3503 kAudioMidReplaceStr.length(),
3504 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003505 SessionDescriptionInterface* modified_answer1 =
3506 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003507 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003508
wu@webrtc.org4e393072014-04-07 17:04:35 +00003509 // Different media types.
3510 EXPECT_TRUE(answer->ToString(&sdp));
3511 const std::string kAudioMline = "m=audio";
3512 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003513 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003514 kAudioMlineReplaceStr.c_str(),
3515 kAudioMlineReplaceStr.length(),
3516 &sdp);
3517 SessionDescriptionInterface* modified_answer2 =
3518 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3519 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3520
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003521 SetRemoteDescriptionWithoutError(answer.release());
3522}
3523
3524// Verifying remote offer and local answer have matching m-lines as per
3525// RFC 3264.
3526TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003527 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003528 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003529 SessionDescriptionInterface* offer = CreateRemoteOffer();
3530 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003531 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003532
3533 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3534 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003535 JsepSessionDescription* modified_answer =
3536 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003537
3538 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3539 answer->session_id(),
3540 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003541 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003542 SetLocalDescriptionWithoutError(answer);
3543}
3544
3545// This test verifies that WebRtcSession does not start candidate allocation
3546// before SetLocalDescription is called.
3547TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003548 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003549 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003550 SessionDescriptionInterface* offer = CreateRemoteOffer();
3551 cricket::Candidate candidate;
3552 candidate.set_component(1);
3553 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3554 candidate);
3555 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3556 cricket::Candidate candidate1;
3557 candidate1.set_component(1);
3558 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3559 candidate1);
3560 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3561 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003562 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3563 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003564
3565 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003566 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003567 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3568 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3569
wu@webrtc.org91053e72013-08-10 07:18:04 +00003570 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003571 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003572 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3573}
3574
3575// This test verifies that crypto parameter is updated in local session
3576// description as per security policy set in MediaSessionDescriptionFactory.
3577TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003578 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003579 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003580 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003581
3582 // Making sure SetLocalDescription correctly sets crypto value in
3583 // SessionDescription object after de-serialization of sdp string. The value
3584 // will be set as per MediaSessionDescriptionFactory.
3585 std::string offer_str;
3586 offer->ToString(&offer_str);
3587 SessionDescriptionInterface* jsep_offer_str =
3588 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3589 SetLocalDescriptionWithoutError(jsep_offer_str);
3590 EXPECT_TRUE(session_->voice_channel()->secure_required());
3591 EXPECT_TRUE(session_->video_channel()->secure_required());
3592}
3593
3594// This test verifies the crypto parameter when security is disabled.
3595TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003596 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003597 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003598 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003599 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003600
3601 // Making sure SetLocalDescription correctly sets crypto value in
3602 // SessionDescription object after de-serialization of sdp string. The value
3603 // will be set as per MediaSessionDescriptionFactory.
3604 std::string offer_str;
3605 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003606 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003607 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3608 SetLocalDescriptionWithoutError(jsep_offer_str);
3609 EXPECT_FALSE(session_->voice_channel()->secure_required());
3610 EXPECT_FALSE(session_->video_channel()->secure_required());
3611}
3612
3613// This test verifies that an answer contains new ufrag and password if an offer
3614// with new ufrag and password is received.
3615TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003616 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003617 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003618 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003619 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003620 CreateRemoteOffer(options));
3621 SetRemoteDescriptionWithoutError(offer.release());
3622
deadbeefab9b2d12015-10-14 11:33:11 -07003623 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003624 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003625 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003626 SetLocalDescriptionWithoutError(answer.release());
3627
3628 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003629 for (const cricket::ContentInfo& content :
3630 session_->local_description()->description()->contents()) {
3631 options.transport_options[content.name].ice_restart = true;
3632 }
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003633 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003634 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003635 SetRemoteDescriptionWithoutError(updated_offer1.release());
3636
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003637 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003638 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003639
deadbeef0ed85b22016-02-23 17:24:52 -08003640 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3641 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003642
deadbeef0ed85b22016-02-23 17:24:52 -08003643 // Even a second answer (created before the description is set) should have
3644 // a new ufrag/password.
3645 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
3646 CreateAnswer(NULL));
3647
3648 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3649 session_->local_description()->description()));
3650
3651 SetLocalDescriptionWithoutError(updated_answer2.release());
3652}
3653
3654// This test verifies that an answer contains new ufrag and password if an offer
3655// that changes either the ufrag or password (but not both) is received.
3656// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3657// a=ice-pwd attributes compared to the previous SDP from the peer, it
3658// indicates that ICE is restarting for this media stream."
3659TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3660 Init();
3661 cricket::MediaSessionOptions options;
3662 options.recv_audio = true;
3663 options.recv_video = true;
3664 // Create an offer with audio and video.
3665 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3666 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3667 SetRemoteDescriptionWithoutError(offer.release());
3668
3669 SendAudioVideoStream1();
3670 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(nullptr));
3671 SetLocalDescriptionWithoutError(answer.release());
3672
3673 // Receive an offer with a new ufrag but stale password.
3674 rtc::scoped_ptr<JsepSessionDescription> ufrag_changed_offer(
3675 CreateRemoteOffer(options, session_->remote_description()));
3676 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3677 "original_password12345");
3678 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3679
3680 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
3681 CreateAnswer(nullptr));
3682 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3683 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003684 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003685
3686 // Receive an offer with a new password but stale ufrag.
3687 rtc::scoped_ptr<JsepSessionDescription> password_changed_offer(
3688 CreateRemoteOffer(options, session_->remote_description()));
3689 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3690 "modified_password12345");
3691 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3692
3693 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
3694 CreateAnswer(nullptr));
3695 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3696 session_->local_description()->description()));
3697 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003698}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003699
wu@webrtc.org91053e72013-08-10 07:18:04 +00003700// This test verifies that an answer contains old ufrag and password if an offer
3701// with old ufrag and password is received.
3702TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003703 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003704 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003705 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003706 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003707 CreateRemoteOffer(options));
3708 SetRemoteDescriptionWithoutError(offer.release());
3709
deadbeefab9b2d12015-10-14 11:33:11 -07003710 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003711 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003712 CreateAnswer(NULL));
3713 SetLocalDescriptionWithoutError(answer.release());
3714
3715 // Receive an offer without changed ufrag or password.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003716 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003717 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003718 SetRemoteDescriptionWithoutError(updated_offer2.release());
3719
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003720 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003721 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003722
deadbeef0ed85b22016-02-23 17:24:52 -08003723 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3724 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003725
3726 SetLocalDescriptionWithoutError(updated_answer2.release());
3727}
3728
deadbeef0ed85b22016-02-23 17:24:52 -08003729// This test verifies that if an offer does an ICE restart on some, but not all
3730// media sections, the answer will change the ufrag/password in the correct
3731// media sections.
3732TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3733 Init();
3734 cricket::MediaSessionOptions options;
3735 options.recv_video = true;
3736 options.recv_audio = true;
3737 options.bundle_enabled = false;
3738 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3739
3740 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3741 "aaaaaaaaaaaaaaaaaaaaaa");
3742 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3743 "bbbbbbbbbbbbbbbbbbbbbb");
3744 SetRemoteDescriptionWithoutError(offer.release());
3745
3746 SendAudioVideoStream1();
3747 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(nullptr));
3748 SetLocalDescriptionWithoutError(answer.release());
3749
3750 // Receive an offer with new ufrag and password, but only for the video media
3751 // section.
3752 rtc::scoped_ptr<JsepSessionDescription> updated_offer(
3753 CreateRemoteOffer(options, session_->remote_description()));
3754 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3755 "cccccccccccccccccccccc");
3756 SetRemoteDescriptionWithoutError(updated_offer.release());
3757
3758 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer(
3759 CreateAnswer(nullptr));
3760
3761 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3762 session_->local_description()->description(),
3763 cricket::MEDIA_TYPE_AUDIO));
3764
3765 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3766 session_->local_description()->description(),
3767 cricket::MEDIA_TYPE_VIDEO));
3768
3769 SetLocalDescriptionWithoutError(updated_answer.release());
3770}
3771
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003772TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003773 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003774 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003775 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003776 const std::string session_id_orig = offer->session_id();
3777 const std::string session_version_orig = offer->session_version();
3778 SetLocalDescriptionWithoutError(offer);
3779
3780 video_channel_ = media_engine_->GetVideoChannel(0);
3781 video_channel_->set_fail_set_send_codecs(true);
3782
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003783 SessionDescriptionInterface* answer =
3784 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003785 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003786
3787 // Test that after a content error, setting any description will
3788 // result in an error.
3789 video_channel_->set_fail_set_send_codecs(false);
3790 answer = CreateRemoteAnswer(session_->local_description());
3791 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3792 offer = CreateRemoteOffer();
3793 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003794}
3795
3796// Runs the loopback call test with BUNDLE and STUN disabled.
3797TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3798 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003799 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003800 cricket::PORTALLOCATOR_DISABLE_STUN |
3801 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003802 TestLoopbackCall();
3803}
3804
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003805TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003806 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003807 cricket::PORTALLOCATOR_DISABLE_STUN |
3808 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3809 cricket::PORTALLOCATOR_DISABLE_RELAY);
3810
3811 // best connection is IPv6 since it has higher network preference.
3812 LoopbackNetworkConfiguration config;
3813 config.test_ipv6_network_ = true;
3814 config.best_connection_after_initial_ice_converged_ =
3815 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3816
3817 TestLoopbackCall(config);
3818}
3819
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003820// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003821TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003822 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3823 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003824 TestLoopbackCall();
3825}
3826
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003827TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3828 constraints_.reset(new FakeConstraints());
3829 constraints_->AddOptional(
3830 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003831 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003832
3833 SetLocalDescriptionWithDataChannel();
3834 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3835}
3836
Henrik Boström87713d02015-08-25 09:53:21 +02003837TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003838 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003839
3840 constraints_.reset(new FakeConstraints());
3841 constraints_->AddOptional(
3842 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003843 options_.disable_sctp_data_channels = false;
3844
Henrik Boström87713d02015-08-25 09:53:21 +02003845 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003846
3847 SetLocalDescriptionWithDataChannel();
3848 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3849}
3850
Henrik Boström87713d02015-08-25 09:53:21 +02003851TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003852 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003853
Henrik Boström87713d02015-08-25 09:53:21 +02003854 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003855
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003856 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003857 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003858 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3859}
3860
Henrik Boström87713d02015-08-25 09:53:21 +02003861TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003862 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003863 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003864 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003865
3866 // Create remote offer with SCTP.
3867 cricket::MediaSessionOptions options;
3868 options.data_channel_type = cricket::DCT_SCTP;
3869 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003870 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003871 SetRemoteDescriptionWithoutError(offer);
3872
3873 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003874 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003875 EXPECT_TRUE(answer != NULL);
3876 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3877 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003878}
3879
Henrik Boström87713d02015-08-25 09:53:21 +02003880TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003881 constraints_.reset(new FakeConstraints());
3882 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003883 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003884 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003885
3886 SetLocalDescriptionWithDataChannel();
3887 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3888}
3889
Henrik Boström87713d02015-08-25 09:53:21 +02003890TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003891 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003892
Henrik Boström87713d02015-08-25 09:53:21 +02003893 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003894
3895 SetLocalDescriptionWithDataChannel();
3896 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3897}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003898
Henrik Boström87713d02015-08-25 09:53:21 +02003899TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003900 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003901 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003902 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003903
3904 SetLocalDescriptionWithDataChannel();
3905 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3906}
3907
Henrik Boström87713d02015-08-25 09:53:21 +02003908TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003909 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003910 const int new_send_port = 9998;
3911 const int new_recv_port = 7775;
3912
Henrik Boström87713d02015-08-25 09:53:21 +02003913 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003914 SetFactoryDtlsSrtp();
3915
3916 // By default, don't actually add the codecs to desc_factory_; they don't
3917 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3918 // let the session description get parsed. That'll get the proper codecs
3919 // into the stream.
3920 cricket::MediaSessionOptions options;
3921 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3922 "stream1", new_send_port, options);
3923
3924 // SetRemoteDescription will take the ownership of the offer.
3925 SetRemoteDescriptionWithoutError(offer);
3926
3927 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3928 new_recv_port, CreateAnswer(NULL));
3929 ASSERT_TRUE(answer != NULL);
3930
3931 // Now set the local description, which'll take ownership of the answer.
3932 SetLocalDescriptionWithoutError(answer);
3933
3934 // TEST PLAN: Set the port number to something new, set it in the SDP,
3935 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003936 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003937 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003938
3939 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3940 int portnum = -1;
3941 ASSERT_TRUE(ch != NULL);
3942 ASSERT_EQ(1UL, ch->send_codecs().size());
3943 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003944 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003945 ch->send_codecs()[0].name.c_str()));
3946 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3947 &portnum));
3948 EXPECT_EQ(new_send_port, portnum);
3949
3950 ASSERT_EQ(1UL, ch->recv_codecs().size());
3951 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003952 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003953 ch->recv_codecs()[0].name.c_str()));
3954 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3955 &portnum));
3956 EXPECT_EQ(new_recv_port, portnum);
3957}
3958
deadbeefab9b2d12015-10-14 11:33:11 -07003959// Verifies that when a session's DataChannel receives an OPEN message,
3960// WebRtcSession signals the DataChannel creation request with the expected
3961// config.
3962TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3963 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3964
3965 InitWithDtls(GetParam());
3966
3967 SetLocalDescriptionWithDataChannel();
3968 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3969
3970 webrtc::DataChannelInit config;
3971 config.id = 1;
3972 rtc::Buffer payload;
3973 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3974 cricket::ReceiveDataParams params;
3975 params.ssrc = config.id;
3976 params.type = cricket::DMT_CONTROL;
3977
3978 cricket::DataChannel* data_channel = session_->data_channel();
3979 data_channel->SignalDataReceived(data_channel, params, payload);
3980
3981 EXPECT_EQ("a", last_data_channel_label_);
3982 EXPECT_EQ(config.id, last_data_channel_config_.id);
3983 EXPECT_FALSE(last_data_channel_config_.negotiated);
3984 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3985 last_data_channel_config_.open_handshake_role);
3986}
3987
3988TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003989 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3990 FakeDtlsIdentityStore::GenerateCertificate();
3991
3992 PeerConnectionInterface::RTCConfiguration configuration;
3993 configuration.certificates.push_back(certificate);
3994 Init(nullptr, configuration);
3995 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3996
3997 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3998}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003999
Henrik Boström87713d02015-08-25 09:53:21 +02004000// Verifies that CreateOffer succeeds when CreateOffer is called before async
4001// identity generation is finished (even if a certificate is provided this is
4002// an async op).
4003TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4004 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4005 InitWithDtls(GetParam());
4006
Henrik Boströmd8281982015-08-27 10:12:24 +02004007 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004008 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004009 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
4010
wu@webrtc.org91053e72013-08-10 07:18:04 +00004011 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004012 VerifyNoCryptoParams(offer->description(), true);
4013 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004014}
4015
4016// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004017// identity generation is finished (even if a certificate is provided this is
4018// an async op).
4019TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004020 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004021 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004022 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004023
4024 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004025 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00004026 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004027 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004028 ASSERT_TRUE(offer.get() != NULL);
4029 SetRemoteDescriptionWithoutError(offer.release());
4030
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004031 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004032 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004033 VerifyNoCryptoParams(answer->description(), true);
4034 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004035}
4036
4037// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004038// identity generation is finished (even if a certificate is provided this is
4039// an async op).
4040TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004041 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004042 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004043
Henrik Boströmd8281982015-08-27 10:12:24 +02004044 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004045
4046 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004047 EXPECT_TRUE(offer != NULL);
4048}
4049
4050// Verifies that CreateOffer fails when CreateOffer is called after async
4051// identity generation fails.
4052TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004053 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004054 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004055
Henrik Boströmd8281982015-08-27 10:12:24 +02004056 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004057
4058 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004059 EXPECT_TRUE(offer == NULL);
4060}
4061
4062// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4063// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004064TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004065 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004066 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004067 VerifyMultipleAsyncCreateDescription(GetParam(),
4068 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004069}
4070
4071// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4072// before async identity generation fails.
4073TEST_F(WebRtcSessionTest,
4074 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004075 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004076 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4077 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004078}
4079
4080// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4081// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004082TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004083 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004084 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004085 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004086 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004087}
4088
4089// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4090// before async identity generation fails.
4091TEST_F(WebRtcSessionTest,
4092 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004093 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004094 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4095 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004096}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004097
4098// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4099// offer has no SDES crypto but only DTLS fingerprint.
4100TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4101 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004102 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004103 // Create a remote offer with secured transport disabled.
4104 cricket::MediaSessionOptions options;
4105 JsepSessionDescription* offer(CreateRemoteOffer(
4106 options, cricket::SEC_DISABLED));
4107 // Adds a DTLS fingerprint to the remote offer.
4108 cricket::SessionDescription* sdp = offer->description();
4109 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4110 ASSERT_TRUE(audio != NULL);
4111 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4112 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004113 rtc::SSLFingerprint::CreateFromRfc4572(
4114 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004115 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004116 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004117}
4118
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004119TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
4120 constraints_.reset(new FakeConstraints());
4121 constraints_->AddOptional(
4122 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
4123 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004124 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004125 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004126 SessionDescriptionInterface* offer = CreateOffer();
4127
4128 SetLocalDescriptionWithoutError(offer);
4129
4130 voice_channel_ = media_engine_->GetVoiceChannel(0);
4131
4132 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004133 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004134 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004135}
4136
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004137// Tests that we can renegotiate new media content with ICE candidates in the
4138// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004139TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004140 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004141 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004142 SetFactoryDtlsSrtp();
4143
deadbeefab9b2d12015-10-14 11:33:11 -07004144 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004145 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004146 SetLocalDescriptionWithoutError(offer);
4147
4148 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4149 SetRemoteDescriptionWithoutError(answer);
4150
4151 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004152 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004153 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4154
4155 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004156 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004157 candidate1.set_component(1);
4158 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4159 candidate1);
4160 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4161 SetRemoteDescriptionWithoutError(offer);
4162
4163 answer = CreateAnswer(NULL);
4164 SetLocalDescriptionWithoutError(answer);
4165}
4166
4167// Tests that we can renegotiate new media content with ICE candidates separated
4168// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004169TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004170 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004171 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004172 SetFactoryDtlsSrtp();
4173
deadbeefab9b2d12015-10-14 11:33:11 -07004174 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004175 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004176 SetLocalDescriptionWithoutError(offer);
4177
4178 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4179 SetRemoteDescriptionWithoutError(answer);
4180
4181 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004182 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004183 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4184 SetRemoteDescriptionWithoutError(offer);
4185
4186 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004187 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004188 candidate1.set_component(1);
4189 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4190 candidate1);
4191 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4192
4193 answer = CreateAnswer(NULL);
4194 SetLocalDescriptionWithoutError(answer);
4195}
honghaiz7f777492016-02-02 21:54:01 -08004196
4197// Flaky on Win and Mac only. See webrtc:4943
4198#if defined(WEBRTC_WIN) || defined(WEBRTC_MAC)
4199#define MAYBE_TestRtxRemovedByCreateAnswer DISABLED_TestRtxRemovedByCreateAnswer
4200#else
4201#define MAYBE_TestRtxRemovedByCreateAnswer TestRtxRemovedByCreateAnswer
4202#endif
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004203// Tests that RTX codec is removed from the answer when it isn't supported
4204// by local side.
honghaiz7f777492016-02-02 21:54:01 -08004205TEST_F(WebRtcSessionTest, MAYBE_TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004206 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004207 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004208 std::string offer_sdp(kSdpWithRtx);
4209
4210 SessionDescriptionInterface* offer =
4211 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4212 EXPECT_TRUE(offer->ToString(&offer_sdp));
4213
4214 // Offer SDP contains the RTX codec.
4215 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4216 SetRemoteDescriptionWithoutError(offer);
4217
4218 SessionDescriptionInterface* answer = CreateAnswer(NULL);
4219 std::string answer_sdp;
4220 answer->ToString(&answer_sdp);
4221 // Answer SDP removes the unsupported RTX codec.
4222 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4223 SetLocalDescriptionWithoutError(answer);
4224}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004225
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004226// This verifies that the voice channel after bundle has both options from video
4227// and voice channels.
4228TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4229 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004230 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004231
4232 PeerConnectionInterface::RTCOfferAnswerOptions options;
4233 options.use_rtp_mux = true;
4234
4235 SessionDescriptionInterface* offer = CreateOffer(options);
4236 SetLocalDescriptionWithoutError(offer);
4237
4238 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4239 rtc::Socket::Option::OPT_SNDBUF, 4000);
4240
4241 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4242 rtc::Socket::Option::OPT_RCVBUF, 8000);
4243
4244 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004245 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004246 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4247 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004248 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004249 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4250
deadbeefcbecd352015-09-23 11:50:27 -07004251 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004252 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4253 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004254 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004255 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4256
deadbeefcbecd352015-09-23 11:50:27 -07004257 EXPECT_NE(session_->voice_rtp_transport_channel(),
4258 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004259
deadbeefab9b2d12015-10-14 11:33:11 -07004260 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004261 SessionDescriptionInterface* answer =
4262 CreateRemoteAnswer(session_->local_description());
4263 SetRemoteDescriptionWithoutError(answer);
4264
deadbeefcbecd352015-09-23 11:50:27 -07004265 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004266 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4267 EXPECT_EQ(4000, option_val);
4268
deadbeefcbecd352015-09-23 11:50:27 -07004269 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004270 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4271 EXPECT_EQ(8000, option_val);
4272}
4273
tommi0f620f42015-07-09 03:25:02 -07004274// Test creating a session, request multiple offers, destroy the session
4275// and make sure we got success/failure callbacks for all of the requests.
4276// Background: crbug.com/507307
4277TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4278 Init();
4279
4280 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4281 PeerConnectionInterface::RTCOfferAnswerOptions options;
4282 options.offer_to_receive_audio =
4283 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004284 cricket::MediaSessionOptions session_options;
4285 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004286
4287 for (auto& o : observers) {
4288 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004289 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004290 }
4291
4292 session_.reset();
4293
tommi0f620f42015-07-09 03:25:02 -07004294 for (auto& o : observers) {
4295 // We expect to have received a notification now even if the session was
4296 // terminated. The offer creation may or may not have succeeded, but we
4297 // must have received a notification which, so the only invalid state
4298 // is kInit.
4299 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4300 }
4301}
4302
stefanc1aeaf02015-10-15 07:26:07 -07004303TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4304 TestPacketOptions();
4305}
4306
deadbeef057ecf02016-01-20 14:30:43 -08004307// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4308// is destroyed.
4309TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4310 Init();
4311 session_.reset();
4312 EXPECT_TRUE(session_destroyed_);
4313}
4314
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004315// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4316// currently fails because upon disconnection and reconnection OnIceComplete is
4317// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004318
deadbeefcbecd352015-09-23 11:50:27 -07004319INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4320 WebRtcSessionTest,
4321 testing::Values(ALREADY_GENERATED,
4322 DTLS_IDENTITY_STORE));