blob: 2c9a99b5e08a247cea0eaf567f30a9e65b464899 [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"
Henrik Kjellander15583c12016-02-10 10:53:12 +010021#include "webrtc/api/test/fakedtlsidentitystore.h"
22#include "webrtc/api/videotrack.h"
23#include "webrtc/api/webrtcsession.h"
24#include "webrtc/api/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000025#include "webrtc/base/fakenetwork.h"
26#include "webrtc/base/firewallsocketserver.h"
27#include "webrtc/base/gunit.h"
28#include "webrtc/base/logging.h"
29#include "webrtc/base/network.h"
30#include "webrtc/base/physicalsocketserver.h"
31#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020032#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000033#include "webrtc/base/sslstreamadapter.h"
34#include "webrtc/base/stringutils.h"
35#include "webrtc/base/thread.h"
36#include "webrtc/base/virtualsocketserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080037#include "webrtc/media/base/fakemediaengine.h"
38#include "webrtc/media/base/fakevideorenderer.h"
39#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010040#include "webrtc/media/engine/fakewebrtccall.h"
kjellandera96e2d72016-02-04 23:52:28 -080041#include "webrtc/p2p/base/stunserver.h"
42#include "webrtc/p2p/base/teststunserver.h"
43#include "webrtc/p2p/base/testturnserver.h"
44#include "webrtc/p2p/base/transportchannel.h"
45#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010046#include "webrtc/pc/channelmanager.h"
47#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048
49#define MAYBE_SKIP_TEST(feature) \
50 if (!(feature())) { \
51 LOG(LS_INFO) << "Feature disabled... skipping"; \
52 return; \
53 }
54
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000057using rtc::SocketAddress;
58using rtc::scoped_ptr;
59using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000061using webrtc::CreateSessionDescriptionObserver;
62using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070063using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020064using webrtc::DtlsIdentityStoreInterface;
jbauchac8869e2015-07-03 01:36:14 -070065using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070067using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068using webrtc::JsepIceCandidate;
69using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000070using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071using webrtc::PeerConnectionInterface;
72using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070073using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000075using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000076using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000077using webrtc::kCreateChannelFailed;
78using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000080using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000081using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000082using webrtc::kSdpWithoutDtlsFingerprint;
83using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000085using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000086using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000088typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
89
wu@webrtc.org364f2042013-11-20 21:49:41 +000090static const int kClientAddrPort = 0;
91static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000092static const char kClientIPv6AddrHost1[] =
93 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000094static const char kClientAddrHost2[] = "22.22.22.22";
95static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000096static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
97static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000098static const char kTurnUsername[] = "test";
99static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
101static const char kSessionVersion[] = "1";
102
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103// Media index of candidates belonging to the first media content.
104static const int kMediaContentIndex0 = 0;
105static const char kMediaContentName0[] = "audio";
106
107// Media index of candidates belonging to the second media content.
108static const int kMediaContentIndex1 = 1;
109static const char kMediaContentName1[] = "video";
110
111static const int kIceCandidatesTimeout = 10000;
112
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000113static const char kFakeDtlsFingerprint[] =
114 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
115 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
116
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000117static const char kTooLongIceUfragPwd[] =
118 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
119 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
120 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
121 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
122
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000123static const char kSdpWithRtx[] =
124 "v=0\r\n"
125 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
126 "s=-\r\n"
127 "t=0 0\r\n"
128 "a=msid-semantic: WMS stream1\r\n"
129 "m=video 9 RTP/SAVPF 0 96\r\n"
130 "c=IN IP4 0.0.0.0\r\n"
131 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
132 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
133 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
134 "a=mid:video\r\n"
135 "a=sendrecv\r\n"
136 "a=rtcp-mux\r\n"
137 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
138 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
139 "a=rtpmap:0 fake_video_codec/90000\r\n"
140 "a=rtpmap:96 rtx/90000\r\n"
141 "a=fmtp:96 apt=0\r\n";
142
deadbeefab9b2d12015-10-14 11:33:11 -0700143static const char kStream1[] = "stream1";
144static const char kVideoTrack1[] = "video1";
145static const char kAudioTrack1[] = "audio1";
146
147static const char kStream2[] = "stream2";
148static const char kVideoTrack2[] = "video2";
149static const char kAudioTrack2[] = "audio2";
150
Henrik Boström87713d02015-08-25 09:53:21 +0200151enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
152
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153class MockIceObserver : public webrtc::IceObserver {
154 public:
155 MockIceObserver()
156 : oncandidatesready_(false),
157 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
158 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
159 }
160
perkjdfb769d2016-02-09 03:09:43 -0800161 void OnIceConnectionChange(
162 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 ice_connection_state_ = new_state;
164 }
perkjdfb769d2016-02-09 03:09:43 -0800165 void OnIceGatheringChange(
166 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 // We can never transition back to "new".
168 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
169 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800170 oncandidatesready_ =
171 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 }
173
174 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800175 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000176 switch (candidate->sdp_mline_index()) {
177 case kMediaContentIndex0:
178 mline_0_candidates_.push_back(candidate->candidate());
179 break;
180 case kMediaContentIndex1:
181 mline_1_candidates_.push_back(candidate->candidate());
182 break;
183 default:
184 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000186
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 // The ICE gathering state should always be Gathering when a candidate is
188 // received (or possibly Completed in the case of the final candidate).
189 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
190 }
191
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 bool oncandidatesready_;
193 std::vector<cricket::Candidate> mline_0_candidates_;
194 std::vector<cricket::Candidate> mline_1_candidates_;
195 PeerConnectionInterface::IceConnectionState ice_connection_state_;
196 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
197};
198
199class WebRtcSessionForTest : public webrtc::WebRtcSession {
200 public:
stefanc1aeaf02015-10-15 07:26:07 -0700201 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000202 rtc::Thread* signaling_thread,
203 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700205 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700206 : WebRtcSession(media_controller,
207 signaling_thread,
208 worker_thread,
209 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 RegisterIceObserver(ice_observer);
211 }
212 virtual ~WebRtcSessionForTest() {}
213
deadbeefcbecd352015-09-23 11:50:27 -0700214 // Note that these methods are only safe to use if the signaling thread
215 // is the same as the worker thread
216 cricket::TransportChannel* voice_rtp_transport_channel() {
217 return rtp_transport_channel(voice_channel());
218 }
219
220 cricket::TransportChannel* voice_rtcp_transport_channel() {
221 return rtcp_transport_channel(voice_channel());
222 }
223
224 cricket::TransportChannel* video_rtp_transport_channel() {
225 return rtp_transport_channel(video_channel());
226 }
227
228 cricket::TransportChannel* video_rtcp_transport_channel() {
229 return rtcp_transport_channel(video_channel());
230 }
231
232 cricket::TransportChannel* data_rtp_transport_channel() {
233 return rtp_transport_channel(data_channel());
234 }
235
236 cricket::TransportChannel* data_rtcp_transport_channel() {
237 return rtcp_transport_channel(data_channel());
238 }
239
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 using webrtc::WebRtcSession::SetAudioPlayout;
241 using webrtc::WebRtcSession::SetAudioSend;
242 using webrtc::WebRtcSession::SetCaptureDevice;
243 using webrtc::WebRtcSession::SetVideoPlayout;
244 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700245
246 private:
247 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
248 if (!ch) {
249 return nullptr;
250 }
251 return ch->transport_channel();
252 }
253
254 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
255 if (!ch) {
256 return nullptr;
257 }
258 return ch->rtcp_transport_channel();
259 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260};
261
wu@webrtc.org91053e72013-08-10 07:18:04 +0000262class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000263 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000265 enum State {
266 kInit,
267 kFailed,
268 kSucceeded,
269 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000270 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000271
272 // CreateSessionDescriptionObserver implementation.
273 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000274 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000275 state_ = kSucceeded;
276 }
277 virtual void OnFailure(const std::string& error) {
278 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279 }
280
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000281 SessionDescriptionInterface* description() { return description_.get(); }
282
283 SessionDescriptionInterface* ReleaseDescription() {
284 return description_.release();
285 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286
wu@webrtc.org91053e72013-08-10 07:18:04 +0000287 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288
wu@webrtc.org91053e72013-08-10 07:18:04 +0000289 protected:
290 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000291
292 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000293 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000294 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295};
296
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800297class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000298 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800299 FakeAudioSource() : sink_(NULL) {}
300 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000301 if (sink_)
302 sink_->OnClose();
303 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000304
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000305 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000306
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800307 const cricket::AudioSource::Sink* sink() const { return sink_; }
308
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000309 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800310 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000311};
312
Henrik Boström87713d02015-08-25 09:53:21 +0200313class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700314 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
315 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 protected:
317 // TODO Investigate why ChannelManager crashes, if it's created
318 // after stun_server.
319 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700320 : media_engine_(new cricket::FakeMediaEngine()),
321 data_engine_(new cricket::FakeDataEngine()),
322 channel_manager_(
323 new cricket::ChannelManager(media_engine_,
324 data_engine_,
stefanc1aeaf02015-10-15 07:26:07 -0700325 rtc::Thread::Current())),
326 fake_call_(webrtc::Call::Config()),
327 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800328 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
329 rtc::Thread::Current(),
stefanc1aeaf02015-10-15 07:26:07 -0700330 channel_manager_.get())),
331 tdesc_factory_(new cricket::TransportDescriptionFactory()),
332 desc_factory_(
333 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
334 tdesc_factory_.get())),
335 pss_(new rtc::PhysicalSocketServer),
336 vss_(new rtc::VirtualSocketServer(pss_.get())),
337 fss_(new rtc::FirewallSocketServer(vss_.get())),
338 ss_scope_(fss_.get()),
339 stun_socket_addr_(
340 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
341 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
342 stun_socket_addr_)),
343 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
344 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000345 cricket::ServerAddresses stun_servers;
346 stun_servers.insert(stun_socket_addr_);
347 allocator_.reset(new cricket::BasicPortAllocator(
348 &network_manager_,
349 stun_servers,
350 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000351 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700352 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 EXPECT_TRUE(channel_manager_->Init());
354 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000355 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 }
357
358 void AddInterface(const SocketAddress& addr) {
359 network_manager_.AddInterface(addr);
360 }
361
Henrik Boström87713d02015-08-25 09:53:21 +0200362 // If |dtls_identity_store| != null or |rtc_configuration| contains
363 // |certificates| then DTLS will be enabled unless explicitly disabled by
364 // |rtc_configuration| options. When DTLS is enabled a certificate will be
365 // used if provided, otherwise one will be generated using the
366 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000367 void Init(
htaa2a49d92016-03-04 02:51:39 -0800368 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 ASSERT_TRUE(session_.get() == NULL);
370 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700371 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700372 allocator_.get(), &observer_));
373 session_->SignalDataChannelOpenMessage.connect(
374 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800375 session_->GetOnDestroyedSignal()->connect(
376 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377
378 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
379 observer_.ice_connection_state_);
380 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
381 observer_.ice_gathering_state_);
382
htaa2a49d92016-03-04 02:51:39 -0800383 EXPECT_TRUE(session_->Initialize(options_, std::move(dtls_identity_store),
384 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700385 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386 }
387
deadbeefab9b2d12015-10-14 11:33:11 -0700388 void OnDataChannelOpenMessage(const std::string& label,
389 const InternalDataChannelInit& config) {
390 last_data_channel_label_ = label;
391 last_data_channel_config_ = config;
392 }
393
deadbeef057ecf02016-01-20 14:30:43 -0800394 void OnSessionDestroyed() { session_destroyed_ = true; }
395
htaa2a49d92016-03-04 02:51:39 -0800396 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000397
398 void InitWithIceTransport(
399 PeerConnectionInterface::IceTransportsType ice_transport_type) {
htaa2a49d92016-03-04 02:51:39 -0800400 configuration_.type = ice_transport_type;
401 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000402 }
403
404 void InitWithBundlePolicy(
405 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800406 configuration_.bundle_policy = bundle_policy;
407 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700408 }
409
410 void InitWithRtcpMuxPolicy(
411 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
412 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800413 configuration_.rtcp_mux_policy = rtcp_mux_policy;
414 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000415 }
416
Henrik Boström87713d02015-08-25 09:53:21 +0200417 // Successfully init with DTLS; with a certificate generated and supplied or
418 // with a store that generates it for us.
419 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
420 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
Henrik Boström87713d02015-08-25 09:53:21 +0200421 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800422 configuration_.certificates.push_back(
Henrik Boström87713d02015-08-25 09:53:21 +0200423 FakeDtlsIdentityStore::GenerateCertificate());
424 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
425 dtls_identity_store.reset(new FakeDtlsIdentityStore());
426 dtls_identity_store->set_should_fail(false);
427 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700428 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200429 }
htaa2a49d92016-03-04 02:51:39 -0800430 Init(std::move(dtls_identity_store));
Henrik Boström87713d02015-08-25 09:53:21 +0200431 }
432
433 // Init with DTLS with a store that will fail to generate a certificate.
434 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200435 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
436 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200437 dtls_identity_store->set_should_fail(true);
htaa2a49d92016-03-04 02:51:39 -0800438 Init(std::move(dtls_identity_store));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000439 }
440
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441 void InitWithDtmfCodec() {
442 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000443 const cricket::AudioCodec kTelephoneEventCodec(
444 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445 std::vector<cricket::AudioCodec> codecs;
446 codecs.push_back(kTelephoneEventCodec);
447 media_engine_->SetAudioCodecs(codecs);
448 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000449 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450 }
451
deadbeefab9b2d12015-10-14 11:33:11 -0700452 void SendAudioVideoStream1() {
453 send_stream_1_ = true;
454 send_stream_2_ = false;
455 send_audio_ = true;
456 send_video_ = true;
457 }
458
459 void SendAudioVideoStream2() {
460 send_stream_1_ = false;
461 send_stream_2_ = true;
462 send_audio_ = true;
463 send_video_ = true;
464 }
465
466 void SendAudioVideoStream1And2() {
467 send_stream_1_ = true;
468 send_stream_2_ = true;
469 send_audio_ = true;
470 send_video_ = true;
471 }
472
473 void SendNothing() {
474 send_stream_1_ = false;
475 send_stream_2_ = false;
476 send_audio_ = false;
477 send_video_ = false;
478 }
479
480 void SendAudioOnlyStream2() {
481 send_stream_1_ = false;
482 send_stream_2_ = true;
483 send_audio_ = true;
484 send_video_ = false;
485 }
486
487 void SendVideoOnlyStream2() {
488 send_stream_1_ = false;
489 send_stream_2_ = true;
490 send_audio_ = false;
491 send_video_ = true;
492 }
493
494 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
495 if (send_stream_1_ && send_audio_) {
496 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
497 kStream1);
498 }
499 if (send_stream_1_ && send_video_) {
500 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
501 kStream1);
502 }
503 if (send_stream_2_ && send_audio_) {
504 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
505 kStream2);
506 }
507 if (send_stream_2_ && send_video_) {
508 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
509 kStream2);
510 }
511 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
512 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
513 data_channel_->label(),
514 data_channel_->label());
515 }
516 }
517
518 void GetOptionsForOffer(
519 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
520 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800521 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700522
deadbeefc80741f2015-10-22 13:14:45 -0700523 AddStreamsToOptions(session_options);
524 if (rtc_options.offer_to_receive_audio ==
525 RTCOfferAnswerOptions::kUndefined) {
526 session_options->recv_audio =
527 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
528 }
529 if (rtc_options.offer_to_receive_video ==
530 RTCOfferAnswerOptions::kUndefined) {
531 session_options->recv_video =
532 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
533 }
534 session_options->bundle_enabled =
535 session_options->bundle_enabled &&
536 (session_options->has_audio() || session_options->has_video() ||
537 session_options->has_data());
538
deadbeefab9b2d12015-10-14 11:33:11 -0700539 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
540 session_options->data_channel_type = cricket::DCT_SCTP;
541 }
542 }
543
htaa2a49d92016-03-04 02:51:39 -0800544 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
545 // ParseConstraintsForAnswer is used to set some defaults.
546 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700547
deadbeefc80741f2015-10-22 13:14:45 -0700548 AddStreamsToOptions(session_options);
549 session_options->bundle_enabled =
550 session_options->bundle_enabled &&
551 (session_options->has_audio() || session_options->has_video() ||
552 session_options->has_data());
553
deadbeefab9b2d12015-10-14 11:33:11 -0700554 if (session_->data_channel_type() == cricket::DCT_SCTP) {
555 session_options->data_channel_type = cricket::DCT_SCTP;
556 }
557 }
558
559 // Creates a local offer and applies it. Starts ICE.
560 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 // to decide which streams to create.
562 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000563 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564 SetLocalDescriptionWithoutError(offer);
565 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
566 observer_.ice_gathering_state_,
567 kIceCandidatesTimeout);
568 }
569
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000570 SessionDescriptionInterface* CreateOffer() {
571 PeerConnectionInterface::RTCOfferAnswerOptions options;
572 options.offer_to_receive_audio =
573 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
574
575 return CreateOffer(options);
576 }
577
wu@webrtc.org91053e72013-08-10 07:18:04 +0000578 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800579 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000580 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000581 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700582 cricket::MediaSessionOptions session_options;
583 GetOptionsForOffer(options, &session_options);
584 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000585 EXPECT_TRUE_WAIT(
586 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000587 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000588 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000589 }
590
591 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800592 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000593 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000594 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800595 cricket::MediaSessionOptions session_options = options;
596 GetOptionsForAnswer(&session_options);
597 // Overwrite recv_audio and recv_video with passed-in values.
598 session_options.recv_video = options.recv_video;
599 session_options.recv_audio = options.recv_audio;
600 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000601 EXPECT_TRUE_WAIT(
602 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000603 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000604 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000605 }
606
htaa2a49d92016-03-04 02:51:39 -0800607 SessionDescriptionInterface* CreateAnswer() {
608 cricket::MediaSessionOptions options;
609 options.recv_video = true;
610 options.recv_audio = true;
611 return CreateAnswer(options);
612 }
613
wu@webrtc.org364f2042013-11-20 21:49:41 +0000614 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000615 return (session_->voice_channel() != NULL &&
616 session_->video_channel() != NULL);
617 }
618
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000619 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
620 ASSERT_TRUE(session_.get() != NULL);
621 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
622 ASSERT_TRUE(content != NULL);
623 const cricket::AudioContentDescription* audio_content =
624 static_cast<const cricket::AudioContentDescription*>(
625 content->description);
626 ASSERT_TRUE(audio_content != NULL);
627 ASSERT_EQ(1U, audio_content->cryptos().size());
628 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
629 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
630 audio_content->cryptos()[0].cipher_suite);
631 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
632 audio_content->protocol());
633
634 content = cricket::GetFirstVideoContent(sdp);
635 ASSERT_TRUE(content != NULL);
636 const cricket::VideoContentDescription* video_content =
637 static_cast<const cricket::VideoContentDescription*>(
638 content->description);
639 ASSERT_TRUE(video_content != NULL);
640 ASSERT_EQ(1U, video_content->cryptos().size());
641 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
642 video_content->cryptos()[0].cipher_suite);
643 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
644 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
645 video_content->protocol());
646 }
647
648 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
649 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
650 ASSERT_TRUE(content != NULL);
651 const cricket::AudioContentDescription* audio_content =
652 static_cast<const cricket::AudioContentDescription*>(
653 content->description);
654 ASSERT_TRUE(audio_content != NULL);
655 ASSERT_EQ(0U, audio_content->cryptos().size());
656
657 content = cricket::GetFirstVideoContent(sdp);
658 ASSERT_TRUE(content != NULL);
659 const cricket::VideoContentDescription* video_content =
660 static_cast<const cricket::VideoContentDescription*>(
661 content->description);
662 ASSERT_TRUE(video_content != NULL);
663 ASSERT_EQ(0U, video_content->cryptos().size());
664
665 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700666 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000667 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700668 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000669 video_content->protocol());
670 } else {
671 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
672 audio_content->protocol());
673 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
674 video_content->protocol());
675 }
676 }
677
678 // Set the internal fake description factories to do DTLS-SRTP.
679 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000680 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000682 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200683 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800684 tdesc_factory_->set_certificate(
685 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
686 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
688 }
689
690 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
691 bool expected) {
692 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
693 ASSERT_TRUE(audio != NULL);
694 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000695 const TransportInfo* video = sdp->GetTransportInfoByName("video");
696 ASSERT_TRUE(video != NULL);
697 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698 }
699
700 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000701 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000703 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000704 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000706 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000708 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
709 offer);
htaa2a49d92016-03-04 02:51:39 -0800710 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711 // Answer should be NULL as no crypto params in offer.
712 ASSERT_TRUE(answer == NULL);
713 }
714
715 void VerifyAnswerFromCryptoOffer() {
716 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000717 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 options.bundle_enabled = true;
719 scoped_ptr<JsepSessionDescription> offer(
720 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
721 ASSERT_TRUE(offer.get() != NULL);
722 VerifyCryptoParams(offer->description());
723 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -0800724 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 ASSERT_TRUE(answer.get() != NULL);
726 VerifyCryptoParams(answer->description());
727 }
728
deadbeef0ed85b22016-02-23 17:24:52 -0800729 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
730 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000731 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800732 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733 }
734
735 const cricket::ContentInfos& contents = desc1->contents();
736 cricket::ContentInfos::const_iterator it = contents.begin();
737
738 for (; it != contents.end(); ++it) {
739 const cricket::TransportDescription* transport_desc1 =
740 desc1->GetTransportDescriptionByName(it->name);
741 const cricket::TransportDescription* transport_desc2 =
742 desc2->GetTransportDescriptionByName(it->name);
743 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800744 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 }
746 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
747 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800748 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 }
750 }
deadbeef0ed85b22016-02-23 17:24:52 -0800751 return true;
752 }
753
754 // Compares ufrag/password only for the specified |media_type|.
755 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
756 const cricket::SessionDescription* desc2,
757 cricket::MediaType media_type) {
758 if (desc1->contents().size() != desc2->contents().size()) {
759 return false;
760 }
761
762 const cricket::ContentInfo* cinfo =
763 cricket::GetFirstMediaContent(desc1->contents(), media_type);
764 const cricket::TransportDescription* transport_desc1 =
765 desc1->GetTransportDescriptionByName(cinfo->name);
766 const cricket::TransportDescription* transport_desc2 =
767 desc2->GetTransportDescriptionByName(cinfo->name);
768 if (!transport_desc1 || !transport_desc2) {
769 return false;
770 }
771 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
772 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
773 return false;
774 }
775 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000776 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000777
778 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
779 std::string *sdp) {
780 const cricket::SessionDescription* desc = current_desc->description();
781 EXPECT_TRUE(current_desc->ToString(sdp));
782
783 const cricket::ContentInfos& contents = desc->contents();
784 cricket::ContentInfos::const_iterator it = contents.begin();
785 // Replace ufrag and pwd lines with empty strings.
786 for (; it != contents.end(); ++it) {
787 const cricket::TransportDescription* transport_desc =
788 desc->GetTransportDescriptionByName(it->name);
789 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
790 + "\r\n";
791 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
792 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000793 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000794 "", 0,
795 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000796 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000797 "", 0,
798 sdp);
799 }
800 }
801
deadbeef0ed85b22016-02-23 17:24:52 -0800802 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
803 const std::string& ufrag,
804 const std::string& pwd) {
805 cricket::SessionDescription* desc = current_desc->description();
806 for (TransportInfo& transport_info : desc->transport_infos()) {
807 cricket::TransportDescription& transport_desc =
808 transport_info.description;
809 transport_desc.ice_ufrag = ufrag;
810 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000811 }
812 }
813
deadbeef0ed85b22016-02-23 17:24:52 -0800814 // Sets ufrag/pwd for specified |media_type|.
815 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
816 cricket::MediaType media_type,
817 const std::string& ufrag,
818 const std::string& pwd) {
819 cricket::SessionDescription* desc = current_desc->description();
820 const cricket::ContentInfo* cinfo =
821 cricket::GetFirstMediaContent(desc->contents(), media_type);
822 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
823 cricket::TransportDescription* transport_desc =
824 &transport_info->description;
825 transport_desc->ice_ufrag = ufrag;
826 transport_desc->ice_pwd = pwd;
827 }
828
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829 // Creates a remote offer and and applies it as a remote description,
830 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700831 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 // to decide which local and remote streams to create.
833 void CreateAndSetRemoteOfferAndLocalAnswer() {
834 SessionDescriptionInterface* offer = CreateRemoteOffer();
835 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800836 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 SetLocalDescriptionWithoutError(answer);
838 }
839 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
840 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700841 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 }
843 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700844 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 SetLocalDescriptionWithoutError(desc);
846 EXPECT_EQ(expected_state, session_->state());
847 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000848 void SetLocalDescriptionExpectError(const std::string& action,
849 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 SessionDescriptionInterface* desc) {
851 std::string error;
852 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000853 std::string sdp_type = "local ";
854 sdp_type.append(action);
855 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 EXPECT_NE(std::string::npos, error.find(expected_error));
857 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000858 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
859 SessionDescriptionInterface* desc) {
860 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
861 expected_error, desc);
862 }
863 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
864 SessionDescriptionInterface* desc) {
865 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
866 expected_error, desc);
867 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
869 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
870 }
871 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700872 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 SetRemoteDescriptionWithoutError(desc);
874 EXPECT_EQ(expected_state, session_->state());
875 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000876 void SetRemoteDescriptionExpectError(const std::string& action,
877 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 SessionDescriptionInterface* desc) {
879 std::string error;
880 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000881 std::string sdp_type = "remote ";
882 sdp_type.append(action);
883 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 EXPECT_NE(std::string::npos, error.find(expected_error));
885 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000886 void SetRemoteDescriptionOfferExpectError(
887 const std::string& expected_error, SessionDescriptionInterface* desc) {
888 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
889 expected_error, desc);
890 }
891 void SetRemoteDescriptionPranswerExpectError(
892 const std::string& expected_error, SessionDescriptionInterface* desc) {
893 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
894 expected_error, desc);
895 }
896 void SetRemoteDescriptionAnswerExpectError(
897 const std::string& expected_error, SessionDescriptionInterface* desc) {
898 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
899 expected_error, desc);
900 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901
902 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
903 SessionDescriptionInterface** nocrypto_answer) {
904 // Create a SDP without Crypto.
905 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000906 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 options.bundle_enabled = true;
908 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
909 ASSERT_TRUE(*offer != NULL);
910 VerifyCryptoParams((*offer)->description());
911
912 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
913 cricket::SEC_DISABLED);
914 EXPECT_TRUE(*nocrypto_answer != NULL);
915 }
916
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000917 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
918 SessionDescriptionInterface** nodtls_answer) {
919 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000920 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000921 options.bundle_enabled = true;
922
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000923 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000924 CreateRemoteOffer(options, cricket::SEC_ENABLED));
925
926 *nodtls_answer =
927 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
928 EXPECT_TRUE(*nodtls_answer != NULL);
929 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
930 VerifyCryptoParams((*nodtls_answer)->description());
931
932 SetFactoryDtlsSrtp();
933 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
934 ASSERT_TRUE(*offer != NULL);
935 VerifyFingerprintStatus((*offer)->description(), true);
936 VerifyCryptoParams((*offer)->description());
937 }
938
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939 JsepSessionDescription* CreateRemoteOfferWithVersion(
940 cricket::MediaSessionOptions options,
941 cricket::SecurePolicy secure_policy,
942 const std::string& session_version,
943 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000944 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 const cricket::SessionDescription* cricket_desc = NULL;
946 if (current_desc) {
947 cricket_desc = current_desc->description();
948 session_id = current_desc->session_id();
949 }
950
951 desc_factory_->set_secure(secure_policy);
952 JsepSessionDescription* offer(
953 new JsepSessionDescription(JsepSessionDescription::kOffer));
954 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
955 session_id, session_version)) {
956 delete offer;
957 offer = NULL;
958 }
959 return offer;
960 }
961 JsepSessionDescription* CreateRemoteOffer(
962 cricket::MediaSessionOptions options) {
963 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
964 kSessionVersion, NULL);
965 }
966 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000967 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
968 return CreateRemoteOfferWithVersion(
969 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 }
971 JsepSessionDescription* CreateRemoteOffer(
972 cricket::MediaSessionOptions options,
973 const SessionDescriptionInterface* current_desc) {
974 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
975 kSessionVersion, current_desc);
976 }
977
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000978 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
979 const char* sctp_stream_name, int new_port,
980 cricket::MediaSessionOptions options) {
981 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000982 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
983 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000984 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
985 }
986
987 // Takes ownership of offer_basis (and deletes it).
988 JsepSessionDescription* ChangeSDPSctpPort(
989 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
990 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
991 // SessionDescription from the mutated string.
992 const char* default_port_str = "5000";
993 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000994 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000995 std::string offer_str;
996 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000997 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000998 new_port_str, strlen(new_port_str),
999 &offer_str);
1000 JsepSessionDescription* offer = new JsepSessionDescription(
1001 offer_basis->type());
1002 delete offer_basis;
1003 offer->Initialize(offer_str, NULL);
1004 return offer;
1005 }
1006
deadbeefab9b2d12015-10-14 11:33:11 -07001007 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 // before this function to decide which streams to create.
1009 JsepSessionDescription* CreateRemoteOffer() {
1010 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001011 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001012 return CreateRemoteOffer(options, session_->remote_description());
1013 }
1014
1015 JsepSessionDescription* CreateRemoteAnswer(
1016 const SessionDescriptionInterface* offer,
1017 cricket::MediaSessionOptions options,
1018 cricket::SecurePolicy policy) {
1019 desc_factory_->set_secure(policy);
1020 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001021 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 JsepSessionDescription* answer(
1023 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1024 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1025 options, NULL),
1026 session_id, kSessionVersion)) {
1027 delete answer;
1028 answer = NULL;
1029 }
1030 return answer;
1031 }
1032
1033 JsepSessionDescription* CreateRemoteAnswer(
1034 const SessionDescriptionInterface* offer,
1035 cricket::MediaSessionOptions options) {
1036 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1037 }
1038
deadbeefab9b2d12015-10-14 11:33:11 -07001039 // Creates an answer session description.
1040 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041 // to decide which streams to create.
1042 JsepSessionDescription* CreateRemoteAnswer(
1043 const SessionDescriptionInterface* offer) {
1044 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001045 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001046 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1047 }
1048
1049 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001050 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001051 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001052 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001053
1054 PeerConnectionInterface::RTCOfferAnswerOptions options;
1055 options.use_rtp_mux = bundle;
1056
1057 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1059 // and answer.
1060 SetLocalDescriptionWithoutError(offer);
1061
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001062 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001063 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 std::string sdp;
1065 EXPECT_TRUE(answer->ToString(&sdp));
1066
1067 size_t expected_candidate_num = 2;
1068 if (!rtcp_mux) {
1069 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1070 // for rtp and rtcp.
1071 expected_candidate_num = 4;
1072 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073 const std::string kRtcpMux = "a=rtcp-mux";
1074 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001075 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 kXRtcpMux.c_str(), kXRtcpMux.length(),
1077 &sdp);
1078 }
1079
1080 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1081 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082
1083 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001084 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1086 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001087 if (bundle) {
1088 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1089 } else {
1090 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001091 }
1092 }
1093 // Tests that we can only send DTMF when the dtmf codec is supported.
1094 void TestCanInsertDtmf(bool can) {
1095 if (can) {
1096 InitWithDtmfCodec();
1097 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001098 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001099 }
deadbeefab9b2d12015-10-14 11:33:11 -07001100 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 CreateAndSetRemoteOfferAndLocalAnswer();
1102 EXPECT_FALSE(session_->CanInsertDtmf(""));
1103 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1104 }
1105
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001106 // Helper class to configure loopback network and verify Best
1107 // Connection using right IP protocol for TestLoopbackCall
1108 // method. LoopbackNetworkManager applies firewall rules to block
1109 // all ping traffic once ICE completed, and remove them to observe
1110 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1111 // verifies the best connection is using the right IP protocol after
1112 // initial ICE convergences.
1113
1114 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001115 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001116 LoopbackNetworkConfiguration()
1117 : test_ipv6_network_(false),
1118 test_extra_ipv4_network_(false),
1119 best_connection_after_initial_ice_converged_(1, 0) {}
1120
1121 // Used to track the expected best connection count in each IP protocol.
1122 struct ExpectedBestConnection {
1123 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1124 : ipv4_count_(ipv4_count),
1125 ipv6_count_(ipv6_count) {}
1126
1127 int ipv4_count_;
1128 int ipv6_count_;
1129 };
1130
1131 bool test_ipv6_network_;
1132 bool test_extra_ipv4_network_;
1133 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1134
1135 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001136 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001137 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1138 }
1139
1140 private:
jbauchac8869e2015-07-03 01:36:14 -07001141 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001142 const ExpectedBestConnection& expected) const {
1143 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001144 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1145 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001146 expected.ipv4_count_);
1147 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001148 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1149 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001150 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001151 // This is used in the loopback call so there is only single host to host
1152 // candidate pair.
1153 EXPECT_EQ(metrics_observer->GetEnumCounter(
1154 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1155 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001156 0);
1157 EXPECT_EQ(metrics_observer->GetEnumCounter(
1158 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1159 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001160 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001161 }
1162 };
1163
1164 class LoopbackNetworkManager {
1165 public:
1166 LoopbackNetworkManager(WebRtcSessionTest* session,
1167 const LoopbackNetworkConfiguration& config)
1168 : config_(config) {
1169 session->AddInterface(
1170 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1171 if (config_.test_extra_ipv4_network_) {
1172 session->AddInterface(
1173 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1174 }
1175 if (config_.test_ipv6_network_) {
1176 session->AddInterface(
1177 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1178 }
1179 }
1180
1181 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1182 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1183 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1184 if (config_.test_extra_ipv4_network_) {
1185 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1186 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1187 }
1188 if (config_.test_ipv6_network_) {
1189 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1190 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1191 }
1192 }
1193
1194 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1195
1196 private:
1197 LoopbackNetworkConfiguration config_;
1198 };
1199
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001200 // The method sets up a call from the session to itself, in a loopback
1201 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001202 // disconnection, and then a permanent disconnection.
1203 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001204 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1205 // While running the call, this method also checks if the session goes through
1206 // the correct sequence of ICE states when a connection is established,
1207 // broken, and re-established.
1208 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001209 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1210 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001211 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001212
stefanc1aeaf02015-10-15 07:26:07 -07001213 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001214 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001215 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001216 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001217
1218 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1219 observer_.ice_gathering_state_);
1220 SetLocalDescriptionWithoutError(offer);
1221 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1222 observer_.ice_connection_state_);
1223 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001224 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001225 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1226 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001227 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001228
1229 std::string sdp;
1230 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001231 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1232 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001233 ASSERT_TRUE(desc != NULL);
1234 SetRemoteDescriptionWithoutError(desc);
1235
1236 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001237 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001238
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001239 // The ice connection state is "Connected" too briefly to catch in a test.
1240 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001241 observer_.ice_connection_state_, kIceCandidatesTimeout);
1242 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001243
stefanc1aeaf02015-10-15 07:26:07 -07001244 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1245 LoopbackNetworkManager loopback_network_manager(this, config);
1246 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001247 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248 // Adding firewall rule to block ping requests, which should cause
1249 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001250
1251 loopback_network_manager.ApplyFirewallRules(fss_.get());
1252
1253 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001254 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1255 observer_.ice_connection_state_,
1256 kIceCandidatesTimeout);
1257
jbauchac8869e2015-07-03 01:36:14 -07001258 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001259
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001260 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001261 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001262
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001263 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001264 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265 observer_.ice_connection_state_,
1266 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001267
1268 // Now we block ping requests and wait until the ICE connection transitions
1269 // to the Failed state. This will take at least 30 seconds because it must
1270 // wait for the Port to timeout.
1271 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001272
1273 loopback_network_manager.ApplyFirewallRules(fss_.get());
1274 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001275 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001276 observer_.ice_connection_state_,
1277 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278 }
1279
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001280 void TestLoopbackCall() {
1281 LoopbackNetworkConfiguration config;
1282 TestLoopbackCall(config);
1283 }
1284
stefanc1aeaf02015-10-15 07:26:07 -07001285 void TestPacketOptions() {
1286 media_controller_.reset(
1287 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1288 LoopbackNetworkConfiguration config;
1289 LoopbackNetworkManager loopback_network_manager(this, config);
1290
1291 SetupLoopbackCall();
1292
1293 uint8_t test_packet[15] = {0};
1294 rtc::PacketOptions options;
1295 options.packet_id = 10;
1296 media_engine_->GetVideoChannel(0)
1297 ->SendRtp(test_packet, sizeof(test_packet), options);
1298
1299 const int kPacketTimeout = 2000;
1300 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1301 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1302 }
1303
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1305 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001306 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1307 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1308
1309 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1311 codecs.push_back(kCNCodec1);
1312 codecs.push_back(kCNCodec2);
1313 media_engine_->SetAudioCodecs(codecs);
1314 desc_factory_->set_audio_codecs(codecs);
1315 }
1316
1317 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1318 const cricket::ContentDescription* description = content->description;
1319 ASSERT(description != NULL);
1320 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001321 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322 ASSERT(audio_content_desc != NULL);
1323 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1324 if (audio_content_desc->codecs()[i].name == "CN")
1325 return false;
1326 }
1327 return true;
1328 }
1329
deadbeefab9b2d12015-10-14 11:33:11 -07001330 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001331 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001332 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001333 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1334 data_channel_ = DataChannel::Create(
1335 session_.get(), session_->data_channel_type(), "datachannel", dci);
1336 }
1337
1338 void SetLocalDescriptionWithDataChannel() {
1339 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001340 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001341 SetLocalDescriptionWithoutError(offer);
1342 }
1343
wu@webrtc.org91053e72013-08-10 07:18:04 +00001344 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001345 RTCCertificateGenerationMethod cert_gen_method,
1346 CreateSessionDescriptionRequest::Type type) {
1347 InitWithDtls(cert_gen_method);
1348 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1349 }
1350
1351 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1352 CreateSessionDescriptionRequest::Type type) {
1353 InitWithDtlsIdentityGenFail();
1354 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1355 }
1356
1357 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001358 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001359 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001360 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001361 if (type == CreateSessionDescriptionRequest::kAnswer) {
1362 cricket::MediaSessionOptions options;
1363 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001364 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001365 ASSERT_TRUE(offer.get() != NULL);
1366 SetRemoteDescriptionWithoutError(offer.release());
1367 }
1368
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001369 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001370 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001371 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001372 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001373 observers[kNumber];
1374 for (int i = 0; i < kNumber; ++i) {
1375 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1376 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001377 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001378 } else {
htaa2a49d92016-03-04 02:51:39 -08001379 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001380 }
1381 }
1382
1383 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1384 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1385 WebRtcSessionCreateSDPObserverForTest::kFailed;
1386
1387 for (int i = 0; i < kNumber; ++i) {
1388 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1389 if (success) {
1390 EXPECT_TRUE(observers[i]->description() != NULL);
1391 } else {
1392 EXPECT_TRUE(observers[i]->description() == NULL);
1393 }
1394 }
1395 }
1396
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001397 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001398 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001399 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001400 turn_server.credentials = credentials;
1401 turn_server.ports.push_back(
1402 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1403 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001404 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001405 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001406 }
1407
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408 cricket::FakeMediaEngine* media_engine_;
1409 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001410 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001411 cricket::FakeCall fake_call_;
1412 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001413 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001414 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1415 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1416 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1417 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1418 rtc::SocketServerScope ss_scope_;
1419 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001420 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001421 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001422 rtc::FakeNetworkManager network_manager_;
1423 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001424 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001425 PeerConnectionInterface::RTCConfiguration configuration_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001426 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 MockIceObserver observer_;
1428 cricket::FakeVideoMediaChannel* video_channel_;
1429 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001430 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001431 // The following flags affect options created for CreateOffer/CreateAnswer.
1432 bool send_stream_1_ = false;
1433 bool send_stream_2_ = false;
1434 bool send_audio_ = false;
1435 bool send_video_ = false;
1436 rtc::scoped_refptr<DataChannel> data_channel_;
1437 // Last values received from data channel creation signal.
1438 std::string last_data_channel_label_;
1439 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001440 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441};
1442
Henrik Boström87713d02015-08-25 09:53:21 +02001443TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1444 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001445 // SDES is disabled when DTLS is on.
1446 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447}
1448
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001449TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001450 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001451 // SDES is required if DTLS is off.
1452 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001453}
1454
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1456 TestSessionCandidatesWithBundleRtcpMux(false, false);
1457}
1458
1459// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1460// with rtcp-mux and/or bundle.
1461TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1462 TestSessionCandidatesWithBundleRtcpMux(false, true);
1463}
1464
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1466 TestSessionCandidatesWithBundleRtcpMux(true, true);
1467}
1468
1469TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001470 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1471 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001472 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001473 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474 InitiateCall();
1475 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1476 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1477 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1478}
1479
minyuec8930ba2016-01-22 06:17:46 -08001480// Crashes on Win only. See webrtc:5411.
1481#if defined(WEBRTC_WIN)
1482#define MAYBE_TestStunError DISABLED_TestStunError
1483#else
1484#define MAYBE_TestStunError TestStunError
1485#endif
1486TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001487 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1488 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001489 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001490 rtc::FP_UDP,
1491 rtc::FD_ANY,
1492 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001493 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001494 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001496 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001497 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1498 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1499 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1500}
1501
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001502// Test session delivers no candidates gathered when constraint set to "none".
1503TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1504 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001505 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001506 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001507 InitiateCall();
1508 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1509 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1510 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1511}
1512
1513// Test session delivers only relay candidates gathered when constaint set to
1514// "relay".
1515TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1516 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1517 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001518 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001519 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001520 InitiateCall();
1521 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1522 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1523 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1524 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1525 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1526 observer_.mline_0_candidates_[i].type());
1527 }
1528 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1529 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1530 observer_.mline_1_candidates_[i].type());
1531 }
1532}
1533
1534// Test session delivers all candidates gathered when constaint set to "all".
1535TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1536 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001537 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001538 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001539 InitiateCall();
1540 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1541 // Host + STUN. By default allocator is disabled to gather relay candidates.
1542 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1543 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1544}
1545
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001546TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001547 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001548 SessionDescriptionInterface* offer = NULL;
1549 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1550 std::string unknown_action;
1551 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1552 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1553}
1554
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555// Test creating offers and receive answers and make sure the
1556// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001557TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001558 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001559 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001560 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561 const std::string session_id_orig = offer->session_id();
1562 const std::string session_version_orig = offer->session_version();
1563 SetLocalDescriptionWithoutError(offer);
1564
deadbeefab9b2d12015-10-14 11:33:11 -07001565 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566 SessionDescriptionInterface* answer =
1567 CreateRemoteAnswer(session_->local_description());
1568 SetRemoteDescriptionWithoutError(answer);
1569
1570 video_channel_ = media_engine_->GetVideoChannel(0);
1571 voice_channel_ = media_engine_->GetVoiceChannel(0);
1572
1573 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1574 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1575
1576 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1577 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1578
1579 ASSERT_EQ(1u, video_channel_->send_streams().size());
1580 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1581 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1582 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1583
1584 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001585 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001586 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587
1588 // Verify the session id is the same and the session version is
1589 // increased.
1590 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001591 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1592 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593
1594 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001595 EXPECT_EQ(0u, video_channel_->send_streams().size());
1596 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597
deadbeefab9b2d12015-10-14 11:33:11 -07001598 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 answer = CreateRemoteAnswer(session_->local_description());
1600 SetRemoteDescriptionWithoutError(answer);
1601
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602 // Make sure the receive streams have not changed.
1603 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1604 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1605 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1606 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1607}
1608
1609// Test receiving offers and creating answers and make sure the
1610// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001611TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001612 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001613 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001614 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001615 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616 SetRemoteDescriptionWithoutError(offer);
1617
deadbeefab9b2d12015-10-14 11:33:11 -07001618 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001619 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001620 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621 SetLocalDescriptionWithoutError(answer);
1622
1623 const std::string session_id_orig = answer->session_id();
1624 const std::string session_version_orig = answer->session_version();
1625
1626 video_channel_ = media_engine_->GetVideoChannel(0);
1627 voice_channel_ = media_engine_->GetVoiceChannel(0);
1628
htaa2a49d92016-03-04 02:51:39 -08001629 ASSERT_TRUE(video_channel_);
1630 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1632 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1633
1634 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1635 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1636
1637 ASSERT_EQ(1u, video_channel_->send_streams().size());
1638 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1639 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1640 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1641
deadbeefab9b2d12015-10-14 11:33:11 -07001642 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001643 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001644 SetRemoteDescriptionWithoutError(offer);
1645
1646 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001647 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001648 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649
1650 // Verify the session id is the same and the session version is
1651 // increased.
1652 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001653 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1654 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 SetLocalDescriptionWithoutError(answer);
1656
1657 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1658 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1659 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1660 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1661 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1662 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1663
1664 // Make sure we have no send streams.
1665 EXPECT_EQ(0u, video_channel_->send_streams().size());
1666 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1667}
1668
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001669TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001670 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001671 media_engine_->set_fail_create_channel(true);
1672
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001673 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001674 ASSERT_TRUE(offer != NULL);
1675 // SetRemoteDescription and SetLocalDescription will take the ownership of
1676 // the offer.
1677 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001678 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001679 ASSERT_TRUE(offer != NULL);
1680 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1681}
1682
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001683//
1684// Tests for creating/setting SDP under different SDES/DTLS polices:
1685//
1686// --DTLS off and SDES on
1687// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1688// set local/remote offer/answer with crypto --> success
1689// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1690// failure
1691// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1692// failure
1693// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1694// failure
1695//
1696// --DTLS on and SDES off
1697// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1698// set local/remote offer/answer with DTLS fingerprint --> success
1699// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1700// fingerprint --> failure
1701// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1702// --> failure
1703// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1704// --> failure
1705//
1706// --Encryption disabled: DTLS off and SDES off
1707// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1708// answer without SDES or DTLS --> success
1709// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1710// answer without SDES or DTLS --> success
1711//
1712
1713// Test that we return a failure when applying a remote/local offer that doesn't
1714// have cryptos enabled when DTLS is off.
1715TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001716 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001718 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719 JsepSessionDescription* offer = CreateRemoteOffer(
1720 options, cricket::SEC_DISABLED);
1721 ASSERT_TRUE(offer != NULL);
1722 VerifyNoCryptoParams(offer->description(), false);
1723 // SetRemoteDescription and SetLocalDescription will take the ownership of
1724 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001725 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1727 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001728 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729}
1730
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001731// Test that we return a failure when applying a local answer that doesn't have
1732// cryptos enabled when DTLS is off.
1733TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001734 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735 SessionDescriptionInterface* offer = NULL;
1736 SessionDescriptionInterface* answer = NULL;
1737 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1738 // SetRemoteDescription and SetLocalDescription will take the ownership of
1739 // the offer.
1740 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001741 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742}
1743
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001744// Test we will return fail when apply an remote answer that doesn't have
1745// crypto enabled when DTLS is off.
1746TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001747 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 SessionDescriptionInterface* offer = NULL;
1749 SessionDescriptionInterface* answer = NULL;
1750 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1751 // SetRemoteDescription and SetLocalDescription will take the ownership of
1752 // the offer.
1753 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001754 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755}
1756
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001757// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1758// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001759TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001760 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001761 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001762 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 SetFactoryDtlsSrtp();
1764 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001765 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001766 JsepSessionDescription* offer =
1767 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 ASSERT_TRUE(offer != NULL);
1769 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001770 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771
1772 // SetRemoteDescription will take the ownership of the offer.
1773 SetRemoteDescriptionWithoutError(offer);
1774
1775 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001776 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777 ASSERT_TRUE(answer != NULL);
1778 VerifyFingerprintStatus(answer->description(), true);
1779 // Check that we don't have an a=crypto line in the answer.
1780 VerifyNoCryptoParams(answer->description(), true);
1781
1782 // Now set the local description, which should work, even without a=crypto.
1783 SetLocalDescriptionWithoutError(answer);
1784}
1785
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001786// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1787// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001788TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001789 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001790 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001791 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001792 SetFactoryDtlsSrtp();
1793
1794 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001795 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001796 ASSERT_TRUE(offer != NULL);
1797 VerifyFingerprintStatus(offer->description(), true);
1798 // Check that we don't have an a=crypto line in the offer.
1799 VerifyNoCryptoParams(offer->description(), true);
1800
1801 // Now set the local description, which should work, even without a=crypto.
1802 SetLocalDescriptionWithoutError(offer);
1803
1804 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001805 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001806 JsepSessionDescription* answer =
1807 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1808 ASSERT_TRUE(answer != NULL);
1809 VerifyFingerprintStatus(answer->description(), true);
1810 VerifyNoCryptoParams(answer->description(), true);
1811
1812 // SetRemoteDescription will take the ownership of the answer.
1813 SetRemoteDescriptionWithoutError(answer);
1814}
1815
1816// Test that if we support DTLS and the other side didn't offer a fingerprint,
1817// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001818TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001819 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001820 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001821 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001822 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001823 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824 JsepSessionDescription* offer = CreateRemoteOffer(
1825 options, cricket::SEC_REQUIRED);
1826 ASSERT_TRUE(offer != NULL);
1827 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001828 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001830 // SetRemoteDescription will take the ownership of the offer.
1831 SetRemoteDescriptionOfferExpectError(
1832 kSdpWithoutDtlsFingerprint, offer);
1833
1834 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1835 // SetLocalDescription will take the ownership of the offer.
1836 SetLocalDescriptionOfferExpectError(
1837 kSdpWithoutDtlsFingerprint, offer);
1838}
1839
1840// Test that we return a failure when applying a local answer that doesn't have
1841// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001842TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001843 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001844 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001845 SessionDescriptionInterface* offer = NULL;
1846 SessionDescriptionInterface* answer = NULL;
1847 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1848
1849 // SetRemoteDescription and SetLocalDescription will take the ownership of
1850 // the offer and answer.
1851 SetRemoteDescriptionWithoutError(offer);
1852 SetLocalDescriptionAnswerExpectError(
1853 kSdpWithoutDtlsFingerprint, answer);
1854}
1855
1856// Test that we return a failure when applying a remote answer that doesn't have
1857// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001858TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001859 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001860 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001861 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001862 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001863 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001864 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1865 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001866 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001867 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001868
1869 // SetRemoteDescription and SetLocalDescription will take the ownership of
1870 // the offer and answer.
1871 SetLocalDescriptionWithoutError(offer);
1872 SetRemoteDescriptionAnswerExpectError(
1873 kSdpWithoutDtlsFingerprint, answer);
1874}
1875
1876// Test that we create a local offer without SDES or DTLS and accept a remote
1877// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001878TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001879 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001880 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001881 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001882
1883 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001884 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001885 ASSERT_TRUE(offer != NULL);
1886 VerifyFingerprintStatus(offer->description(), false);
1887 // Check that we don't have an a=crypto line in the offer.
1888 VerifyNoCryptoParams(offer->description(), false);
1889
1890 // Now set the local description, which should work, even without a=crypto.
1891 SetLocalDescriptionWithoutError(offer);
1892
1893 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001894 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001895 JsepSessionDescription* answer =
1896 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1897 ASSERT_TRUE(answer != NULL);
1898 VerifyFingerprintStatus(answer->description(), false);
1899 VerifyNoCryptoParams(answer->description(), false);
1900
1901 // SetRemoteDescription will take the ownership of the answer.
1902 SetRemoteDescriptionWithoutError(answer);
1903}
1904
1905// Test that we create a local answer without SDES or DTLS and accept a remote
1906// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001907TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001908 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001909 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001910
1911 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001912 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001913 JsepSessionDescription* offer =
1914 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1915 ASSERT_TRUE(offer != NULL);
1916 VerifyFingerprintStatus(offer->description(), false);
1917 VerifyNoCryptoParams(offer->description(), false);
1918
1919 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001920 SetRemoteDescriptionWithoutError(offer);
1921
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001922 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001923 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924 ASSERT_TRUE(answer != NULL);
1925 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001926 // Check that we don't have an a=crypto line in the answer.
1927 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001929 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930 SetLocalDescriptionWithoutError(answer);
1931}
1932
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001933// Test that we can create and set an answer correctly when different
1934// SSL roles have been negotiated for different transports.
1935// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1936TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1937 SendAudioVideoStream1();
1938 InitWithDtls(GetParam());
1939 SetFactoryDtlsSrtp();
1940
1941 SessionDescriptionInterface* offer = CreateOffer();
1942 SetLocalDescriptionWithoutError(offer);
1943
1944 cricket::MediaSessionOptions options;
1945 options.recv_video = true;
1946
1947 // First, negotiate different SSL roles.
1948 SessionDescriptionInterface* answer =
1949 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1950 TransportInfo* audio_transport_info =
1951 answer->description()->GetTransportInfoByName("audio");
1952 audio_transport_info->description.connection_role =
1953 cricket::CONNECTIONROLE_ACTIVE;
1954 TransportInfo* video_transport_info =
1955 answer->description()->GetTransportInfoByName("video");
1956 video_transport_info->description.connection_role =
1957 cricket::CONNECTIONROLE_PASSIVE;
1958 SetRemoteDescriptionWithoutError(answer);
1959
1960 // Now create an offer in the reverse direction, and ensure the initial
1961 // offerer responds with an answer with correct SSL roles.
1962 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1963 kSessionVersion,
1964 session_->remote_description());
1965 SetRemoteDescriptionWithoutError(offer);
1966
htaa2a49d92016-03-04 02:51:39 -08001967 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001968 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1969 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1970 audio_transport_info->description.connection_role);
1971 video_transport_info = answer->description()->GetTransportInfoByName("video");
1972 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1973 video_transport_info->description.connection_role);
1974 SetLocalDescriptionWithoutError(answer);
1975
1976 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1977 // audio is transferred over to video in the answer that completes the BUNDLE
1978 // negotiation.
1979 options.bundle_enabled = true;
1980 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1981 kSessionVersion,
1982 session_->remote_description());
1983 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08001984 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001985 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1986 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1987 audio_transport_info->description.connection_role);
1988 video_transport_info = answer->description()->GetTransportInfoByName("video");
1989 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1990 video_transport_info->description.connection_role);
1991 SetLocalDescriptionWithoutError(answer);
1992}
1993
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001995 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001996 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001998 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 SetLocalDescriptionWithoutError(offer);
2000
2001 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002002 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003 SetLocalDescriptionWithoutError(offer2);
2004}
2005
2006TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002007 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002008 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002010 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011 SetRemoteDescriptionWithoutError(offer);
2012
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002013 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014 SetRemoteDescriptionWithoutError(offer2);
2015}
2016
2017TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002018 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002019 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002020 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002021 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002022 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002023 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2024 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025}
2026
2027TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002028 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002029 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002030 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002032 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002033 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002034 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035}
2036
2037TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002038 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002039 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002041 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042
htaa2a49d92016-03-04 02:51:39 -08002043 JsepSessionDescription* pranswer =
2044 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002046 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047
deadbeefab9b2d12015-10-14 11:33:11 -07002048 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002049 JsepSessionDescription* pranswer2 =
2050 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2052
deadbeefd59daf82015-10-14 15:02:44 -07002053 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002054
deadbeefab9b2d12015-10-14 11:33:11 -07002055 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002056 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002057 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058}
2059
2060TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002061 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002062 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002063 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002064 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065
2066 JsepSessionDescription* pranswer =
2067 CreateRemoteAnswer(session_->local_description());
2068 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2069
2070 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002071 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072
deadbeefab9b2d12015-10-14 11:33:11 -07002073 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074 JsepSessionDescription* pranswer2 =
2075 CreateRemoteAnswer(session_->local_description());
2076 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2077
2078 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002079 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080
deadbeefab9b2d12015-10-14 11:33:11 -07002081 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082 SessionDescriptionInterface* answer =
2083 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002084 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085}
2086
2087TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002088 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002089 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002090 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2091
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092 SessionDescriptionInterface* answer =
2093 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002094 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2095 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096}
2097
2098TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002099 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002100 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002101 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2102
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 SessionDescriptionInterface* answer =
2104 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002105 SetRemoteDescriptionAnswerExpectError(
2106 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107}
2108
2109TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002110 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002111 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112
2113 cricket::Candidate candidate;
2114 candidate.set_component(1);
2115 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2116
deadbeefd59daf82015-10-14 15:02:44 -07002117 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2119
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002120 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002122
2123 // Fail since we have not set a remote description.
2124 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125
2126 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2127 session_->local_description());
2128 SetRemoteDescriptionWithoutError(answer);
2129
deadbeefd59daf82015-10-14 15:02:44 -07002130 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2131 candidate.set_component(2);
2132 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2133 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2134
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 // Verifying the candidates are copied properly from internal vector.
2136 const SessionDescriptionInterface* remote_desc =
2137 session_->remote_description();
2138 ASSERT_TRUE(remote_desc != NULL);
2139 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2140 const IceCandidateCollection* candidates =
2141 remote_desc->candidates(kMediaContentIndex0);
2142 ASSERT_EQ(2u, candidates->count());
2143 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2144 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2145 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2146 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2147
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002148 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2149 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150 candidate.set_component(2);
2151 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2152 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002153 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154
2155 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2156 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2157}
2158
2159// Test that a remote candidate is added to the remote session description and
2160// that it is retained if the remote session description is changed.
2161TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002162 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 cricket::Candidate candidate1;
2164 candidate1.set_component(1);
2165 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2166 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002167 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168 CreateAndSetRemoteOfferAndLocalAnswer();
2169
2170 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2171 const SessionDescriptionInterface* remote_desc =
2172 session_->remote_description();
2173 ASSERT_TRUE(remote_desc != NULL);
2174 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2175 const IceCandidateCollection* candidates =
2176 remote_desc->candidates(kMediaContentIndex0);
2177 ASSERT_EQ(1u, candidates->count());
2178 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2179
2180 // Update the RemoteSessionDescription with a new session description and
2181 // a candidate and check that the new remote session description contains both
2182 // candidates.
2183 SessionDescriptionInterface* offer = CreateRemoteOffer();
2184 cricket::Candidate candidate2;
2185 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2186 candidate2);
2187 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2188 SetRemoteDescriptionWithoutError(offer);
2189
2190 remote_desc = session_->remote_description();
2191 ASSERT_TRUE(remote_desc != NULL);
2192 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2193 candidates = remote_desc->candidates(kMediaContentIndex0);
2194 ASSERT_EQ(2u, candidates->count());
2195 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2196 // Username and password have be updated with the TransportInfo of the
2197 // SessionDescription, won't be equal to the original one.
2198 candidate2.set_username(candidates->at(0)->candidate().username());
2199 candidate2.set_password(candidates->at(0)->candidate().password());
2200 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2201 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2202 // No need to verify the username and password.
2203 candidate1.set_username(candidates->at(1)->candidate().username());
2204 candidate1.set_password(candidates->at(1)->candidate().password());
2205 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2206
2207 // Test that the candidate is ignored if we can add the same candidate again.
2208 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2209}
2210
2211// Test that local candidates are added to the local session description and
2212// that they are retained if the local session description is changed.
2213TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002214 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002215 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002216 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217 CreateAndSetRemoteOfferAndLocalAnswer();
2218
2219 const SessionDescriptionInterface* local_desc = session_->local_description();
2220 const IceCandidateCollection* candidates =
2221 local_desc->candidates(kMediaContentIndex0);
2222 ASSERT_TRUE(candidates != NULL);
2223 EXPECT_EQ(0u, candidates->count());
2224
2225 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2226
2227 local_desc = session_->local_description();
2228 candidates = local_desc->candidates(kMediaContentIndex0);
2229 ASSERT_TRUE(candidates != NULL);
2230 EXPECT_LT(0u, candidates->count());
2231 candidates = local_desc->candidates(1);
2232 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002233 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002234
2235 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002236 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237 CreateAndSetRemoteOfferAndLocalAnswer();
2238
2239 local_desc = session_->local_description();
2240 candidates = local_desc->candidates(kMediaContentIndex0);
2241 ASSERT_TRUE(candidates != NULL);
2242 EXPECT_LT(0u, candidates->count());
2243 candidates = local_desc->candidates(1);
2244 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002245 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246}
2247
2248// Test that we can set a remote session description with remote candidates.
2249TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002250 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251
2252 cricket::Candidate candidate1;
2253 candidate1.set_component(1);
2254 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2255 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002256 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002257 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002258
2259 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2260 SetRemoteDescriptionWithoutError(offer);
2261
2262 const SessionDescriptionInterface* remote_desc =
2263 session_->remote_description();
2264 ASSERT_TRUE(remote_desc != NULL);
2265 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2266 const IceCandidateCollection* candidates =
2267 remote_desc->candidates(kMediaContentIndex0);
2268 ASSERT_EQ(1u, candidates->count());
2269 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2270
htaa2a49d92016-03-04 02:51:39 -08002271 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272 SetLocalDescriptionWithoutError(answer);
2273}
2274
2275// Test that offers and answers contains ice candidates when Ice candidates have
2276// been gathered.
2277TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002278 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002279 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002280 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281 // Ice is started but candidates are not provided until SetLocalDescription
2282 // is called.
2283 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2284 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2285 CreateAndSetRemoteOfferAndLocalAnswer();
2286 // Wait until at least one local candidate has been collected.
2287 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2288 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002290 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2291
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2293 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294
2295 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2296 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002297 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2299 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300 SetLocalDescriptionWithoutError(answer);
2301}
2302
2303// Verifies TransportProxy and media channels are created with content names
2304// present in the SessionDescription.
2305TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002306 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002307 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002308 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002309
2310 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002311 // "video". Goal is to modify these content names and verify transport
2312 // channels
2313 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314 // present in SDP.
2315 std::string sdp;
2316 EXPECT_TRUE(offer->ToString(&sdp));
2317 const std::string kAudioMid = "a=mid:audio";
2318 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2319 const std::string kVideoMid = "a=mid:video";
2320 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2321
2322 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002323 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 kAudioMidReplaceStr.c_str(),
2325 kAudioMidReplaceStr.length(),
2326 &sdp);
2327 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002328 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329 kVideoMidReplaceStr.c_str(),
2330 kVideoMidReplaceStr.length(),
2331 &sdp);
2332
2333 SessionDescriptionInterface* modified_offer =
2334 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2335
2336 SetRemoteDescriptionWithoutError(modified_offer);
2337
htaa2a49d92016-03-04 02:51:39 -08002338 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339 SetLocalDescriptionWithoutError(answer);
2340
deadbeefcbecd352015-09-23 11:50:27 -07002341 cricket::TransportChannel* voice_transport_channel =
2342 session_->voice_rtp_transport_channel();
2343 EXPECT_TRUE(voice_transport_channel != NULL);
2344 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2345 cricket::TransportChannel* video_transport_channel =
2346 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002347 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002348 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2350 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2351}
2352
2353// Test that an offer contains the correct media content descriptions based on
2354// the send streams when no constraints have been set.
2355TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002356 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002357 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2358
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 ASSERT_TRUE(offer != NULL);
2360 const cricket::ContentInfo* content =
2361 cricket::GetFirstAudioContent(offer->description());
2362 EXPECT_TRUE(content != NULL);
2363 content = cricket::GetFirstVideoContent(offer->description());
2364 EXPECT_TRUE(content == NULL);
2365}
2366
2367// Test that an offer contains the correct media content descriptions based on
2368// the send streams when no constraints have been set.
2369TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002370 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002372 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002373 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2374
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375 const cricket::ContentInfo* content =
2376 cricket::GetFirstAudioContent(offer->description());
2377 EXPECT_TRUE(content != NULL);
2378 content = cricket::GetFirstVideoContent(offer->description());
2379 EXPECT_TRUE(content == NULL);
2380
2381 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002382 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002383 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384 content = cricket::GetFirstAudioContent(offer->description());
2385 EXPECT_TRUE(content != NULL);
2386 content = cricket::GetFirstVideoContent(offer->description());
2387 EXPECT_TRUE(content != NULL);
2388}
2389
2390// Test that an offer contains no media content descriptions if
2391// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2392TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002393 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002394 PeerConnectionInterface::RTCOfferAnswerOptions options;
2395 options.offer_to_receive_audio = 0;
2396 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002398 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002399 CreateOffer(options));
2400
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401 ASSERT_TRUE(offer != NULL);
2402 const cricket::ContentInfo* content =
2403 cricket::GetFirstAudioContent(offer->description());
2404 EXPECT_TRUE(content == NULL);
2405 content = cricket::GetFirstVideoContent(offer->description());
2406 EXPECT_TRUE(content == NULL);
2407}
2408
2409// Test that an offer contains only audio media content descriptions if
2410// kOfferToReceiveAudio constraints are set to true.
2411TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002412 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002413 PeerConnectionInterface::RTCOfferAnswerOptions options;
2414 options.offer_to_receive_audio =
2415 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2416
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002417 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002418 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419
2420 const cricket::ContentInfo* content =
2421 cricket::GetFirstAudioContent(offer->description());
2422 EXPECT_TRUE(content != NULL);
2423 content = cricket::GetFirstVideoContent(offer->description());
2424 EXPECT_TRUE(content == NULL);
2425}
2426
2427// Test that an offer contains audio and video media content descriptions if
2428// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2429TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002430 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002432 PeerConnectionInterface::RTCOfferAnswerOptions options;
2433 options.offer_to_receive_audio =
2434 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2435 options.offer_to_receive_video =
2436 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2437
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002438 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002439 CreateOffer(options));
2440
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441 const cricket::ContentInfo* content =
2442 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002443 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002444
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445 content = cricket::GetFirstVideoContent(offer->description());
2446 EXPECT_TRUE(content != NULL);
2447
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002448 // Sets constraints to false and verifies that audio/video contents are
2449 // removed.
2450 options.offer_to_receive_audio = 0;
2451 options.offer_to_receive_video = 0;
2452 offer.reset(CreateOffer(options));
2453
2454 content = cricket::GetFirstAudioContent(offer->description());
2455 EXPECT_TRUE(content == NULL);
2456 content = cricket::GetFirstVideoContent(offer->description());
2457 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002458}
2459
2460// Test that an answer can not be created if the last remote description is not
2461// an offer.
2462TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002463 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002464 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465 SetLocalDescriptionWithoutError(offer);
2466 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2467 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002468 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469}
2470
2471// Test that an answer contains the correct media content descriptions when no
2472// constraints have been set.
2473TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002474 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002476 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -08002478 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002479 const cricket::ContentInfo* content =
2480 cricket::GetFirstAudioContent(answer->description());
2481 ASSERT_TRUE(content != NULL);
2482 EXPECT_FALSE(content->rejected);
2483
2484 content = cricket::GetFirstVideoContent(answer->description());
2485 ASSERT_TRUE(content != NULL);
2486 EXPECT_FALSE(content->rejected);
2487}
2488
2489// Test that an answer contains the correct media content descriptions when no
2490// constraints have been set and the offer only contain audio.
2491TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002492 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002493 // Create a remote offer with audio only.
2494 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002495
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002496 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497 CreateRemoteOffer(options));
2498 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2499 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2500
2501 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -08002502 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002503 const cricket::ContentInfo* content =
2504 cricket::GetFirstAudioContent(answer->description());
2505 ASSERT_TRUE(content != NULL);
2506 EXPECT_FALSE(content->rejected);
2507
2508 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2509}
2510
2511// Test that an answer contains the correct media content descriptions when no
2512// constraints have been set.
2513TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002514 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002516 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002517 SetRemoteDescriptionWithoutError(offer.release());
2518 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002519 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002520 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002521 const cricket::ContentInfo* content =
2522 cricket::GetFirstAudioContent(answer->description());
2523 ASSERT_TRUE(content != NULL);
2524 EXPECT_FALSE(content->rejected);
2525
2526 content = cricket::GetFirstVideoContent(answer->description());
2527 ASSERT_TRUE(content != NULL);
2528 EXPECT_FALSE(content->rejected);
2529}
2530
2531// Test that an answer contains the correct media content descriptions when
2532// constraints have been set but no stream is sent.
2533TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002534 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002535 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002536 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002537 SetRemoteDescriptionWithoutError(offer.release());
2538
htaa2a49d92016-03-04 02:51:39 -08002539 cricket::MediaSessionOptions session_options;
2540 session_options.recv_audio = false;
2541 session_options.recv_video = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002542 rtc::scoped_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002543 CreateAnswer(session_options));
2544
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002545 const cricket::ContentInfo* content =
2546 cricket::GetFirstAudioContent(answer->description());
2547 ASSERT_TRUE(content != NULL);
2548 EXPECT_TRUE(content->rejected);
2549
2550 content = cricket::GetFirstVideoContent(answer->description());
2551 ASSERT_TRUE(content != NULL);
2552 EXPECT_TRUE(content->rejected);
2553}
2554
2555// Test that an answer contains the correct media content descriptions when
2556// constraints have been set and streams are sent.
2557TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002558 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002560 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002561 SetRemoteDescriptionWithoutError(offer.release());
2562
htaa2a49d92016-03-04 02:51:39 -08002563 cricket::MediaSessionOptions options;
2564 options.recv_audio = false;
2565 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566
2567 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002568 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002569 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002570
2571 // TODO(perkj): Should the direction be set to SEND_ONLY?
2572 const cricket::ContentInfo* content =
2573 cricket::GetFirstAudioContent(answer->description());
2574 ASSERT_TRUE(content != NULL);
2575 EXPECT_FALSE(content->rejected);
2576
2577 // TODO(perkj): Should the direction be set to SEND_ONLY?
2578 content = cricket::GetFirstVideoContent(answer->description());
2579 ASSERT_TRUE(content != NULL);
2580 EXPECT_FALSE(content->rejected);
2581}
2582
2583TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2584 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002585 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002586 PeerConnectionInterface::RTCOfferAnswerOptions options;
2587 options.offer_to_receive_audio =
2588 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2589 options.voice_activity_detection = false;
2590
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002591 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002592 CreateOffer(options));
2593
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002594 const cricket::ContentInfo* content =
2595 cricket::GetFirstAudioContent(offer->description());
2596 EXPECT_TRUE(content != NULL);
2597 EXPECT_TRUE(VerifyNoCNCodecs(content));
2598}
2599
2600TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2601 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002602 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002603 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002604 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002605 SetRemoteDescriptionWithoutError(offer.release());
2606
htaa2a49d92016-03-04 02:51:39 -08002607 cricket::MediaSessionOptions options;
2608 options.vad_enabled = false;
2609 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002610 const cricket::ContentInfo* content =
2611 cricket::GetFirstAudioContent(answer->description());
2612 ASSERT_TRUE(content != NULL);
2613 EXPECT_TRUE(VerifyNoCNCodecs(content));
2614}
2615
2616// This test verifies the call setup when remote answer with audio only and
2617// later updates with video.
2618TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002619 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002620 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2621 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2622
deadbeefab9b2d12015-10-14 11:33:11 -07002623 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002624 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002625
2626 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002627 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2628
2629 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2630 // and answer;
2631 SetLocalDescriptionWithoutError(offer);
2632 SetRemoteDescriptionWithoutError(answer);
2633
2634 video_channel_ = media_engine_->GetVideoChannel(0);
2635 voice_channel_ = media_engine_->GetVoiceChannel(0);
2636
2637 ASSERT_TRUE(video_channel_ == NULL);
2638
2639 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2640 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2641 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2642
2643 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002644 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002645 CreateAndSetRemoteOfferAndLocalAnswer();
2646
2647 video_channel_ = media_engine_->GetVideoChannel(0);
2648 voice_channel_ = media_engine_->GetVoiceChannel(0);
2649
2650 ASSERT_TRUE(video_channel_ != NULL);
2651 ASSERT_TRUE(voice_channel_ != NULL);
2652
2653 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2654 ASSERT_EQ(1u, video_channel_->send_streams().size());
2655 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2656 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2657 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2658 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2659 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2660 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2661
2662 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002663 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002664 CreateAndSetRemoteOfferAndLocalAnswer();
2665
2666 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2667 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2668 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2669 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2670 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2671}
2672
2673// This test verifies the call setup when remote answer with video only and
2674// later updates with audio.
2675TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002676 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002677 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2678 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002679 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002680 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002681
2682 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002683 options.recv_audio = false;
2684 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002685 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2686 offer, options, cricket::SEC_ENABLED);
2687
2688 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2689 // and answer.
2690 SetLocalDescriptionWithoutError(offer);
2691 SetRemoteDescriptionWithoutError(answer);
2692
2693 video_channel_ = media_engine_->GetVideoChannel(0);
2694 voice_channel_ = media_engine_->GetVoiceChannel(0);
2695
2696 ASSERT_TRUE(voice_channel_ == NULL);
2697 ASSERT_TRUE(video_channel_ != NULL);
2698
2699 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2700 ASSERT_EQ(1u, video_channel_->send_streams().size());
2701 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2702
2703 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002704 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002705 CreateAndSetRemoteOfferAndLocalAnswer();
2706
2707 voice_channel_ = media_engine_->GetVoiceChannel(0);
2708 ASSERT_TRUE(voice_channel_ != NULL);
2709
2710 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2711 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2712 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2713 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2714
2715 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002716 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002717 CreateAndSetRemoteOfferAndLocalAnswer();
2718
2719 video_channel_ = media_engine_->GetVideoChannel(0);
2720 voice_channel_ = media_engine_->GetVoiceChannel(0);
2721
2722 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2723 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2724 ASSERT_EQ(1u, video_channel_->send_streams().size());
2725 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2726}
2727
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002729 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002730 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002731 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002732 VerifyCryptoParams(offer->description());
2733 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -08002734 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002735 VerifyCryptoParams(answer->description());
2736}
2737
2738TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002739 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002740 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002741 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002742 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002743 VerifyNoCryptoParams(offer->description(), false);
2744}
2745
2746TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002747 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002748 VerifyAnswerFromNonCryptoOffer();
2749}
2750
2751TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002752 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002753 VerifyAnswerFromCryptoOffer();
2754}
2755
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002756// This test verifies that setLocalDescription fails if
2757// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2758TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002759 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002760 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002761 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2762
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002763 std::string sdp;
2764 RemoveIceUfragPwdLines(offer.get(), &sdp);
2765 SessionDescriptionInterface* modified_offer =
2766 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002767 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002768}
2769
2770// This test verifies that setRemoteDescription fails if
2771// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2772TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002773 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002774 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002775 std::string sdp;
2776 RemoveIceUfragPwdLines(offer.get(), &sdp);
2777 SessionDescriptionInterface* modified_offer =
2778 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002779 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002780}
2781
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002782// This test verifies that setLocalDescription fails if local offer has
2783// too short ice ufrag and pwd strings.
2784TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002785 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002786 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002787 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002788 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2789 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002790 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002791 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002792 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002793
2794 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002795 offer.reset(CreateOffer());
2796 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2797 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002798}
2799
2800// This test verifies that setRemoteDescription fails if remote offer has
2801// too short ice ufrag and pwd strings.
2802TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002803 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002804 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002805 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2806 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002807 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002808 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002809 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002810
deadbeef0ed85b22016-02-23 17:24:52 -08002811 offer.reset(CreateRemoteOffer());
2812 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2813 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002814}
2815
Honghai Zhang04e91462015-12-11 14:26:22 -08002816// Test that if the remote offer indicates the peer requested ICE restart (via
2817// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2818TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002819 Init();
honghaiz503726c2015-07-31 12:37:38 -07002820
2821 // Create the first offer.
deadbeef0ed85b22016-02-23 17:24:52 -08002822 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2823 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002824 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2825 0, "", "", "relay", 0, "");
2826 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2827 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002828 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2829 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002830 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2831
2832 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002833 offer.reset(CreateRemoteOffer());
2834 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002835 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2836 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2837 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002838 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2839 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002840 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2841
2842 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002843 offer.reset(CreateRemoteOffer());
2844 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002845 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2846 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2847 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002848 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2849 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002850 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2851
2852 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002853 offer.reset(CreateRemoteOffer());
2854 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2855 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002856 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2857}
2858
Honghai Zhang04e91462015-12-11 14:26:22 -08002859// Test that if the remote answer indicates the peer requested ICE restart (via
2860// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2861TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2862 Init();
2863 SessionDescriptionInterface* offer = CreateOffer();
2864 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002865
2866 // Create the first answer.
deadbeef0ed85b22016-02-23 17:24:52 -08002867 scoped_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
2868 answer->set_type(JsepSessionDescription::kPrAnswer);
2869 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002870 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2871 0, "", "", "relay", 0, "");
2872 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2873 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002874 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2875 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002876 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2877
2878 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002879 answer.reset(CreateRemoteAnswer(offer));
2880 answer->set_type(JsepSessionDescription::kPrAnswer);
2881 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002882 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2883 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2884 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002885 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2886 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002887 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2888
2889 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002890 answer.reset(CreateRemoteAnswer(offer));
2891 answer->set_type(JsepSessionDescription::kPrAnswer);
2892 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002893 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2894 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2895 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002896 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2897 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002898 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2899
2900 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002901 answer.reset(CreateRemoteAnswer(offer));
2902 answer->set_type(JsepSessionDescription::kPrAnswer);
2903 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2904 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002905 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2906}
2907
Donald Curtisd4f769d2015-05-28 09:48:21 -07002908// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002909// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002910TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2911 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2912
2913 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002914 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002915
2916 PeerConnectionInterface::RTCOfferAnswerOptions options;
2917 options.use_rtp_mux = true;
2918
2919 SessionDescriptionInterface* offer = CreateRemoteOffer();
2920 SetRemoteDescriptionWithoutError(offer);
2921
htaa2a49d92016-03-04 02:51:39 -08002922 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002923 SetLocalDescriptionWithoutError(answer);
2924
deadbeefcbecd352015-09-23 11:50:27 -07002925 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2926 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002927
deadbeefcbecd352015-09-23 11:50:27 -07002928 cricket::BaseChannel* voice_channel = session_->voice_channel();
2929 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002930
2931 // Checks if one of the transport channels contains a connection using a given
2932 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002933 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002934 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002935 session_->GetChannelTransportStats(voice_channel, &stats);
2936 for (auto& kv : stats.transport_stats) {
2937 for (auto& chan_stat : kv.second.channel_stats) {
2938 for (auto& conn_info : chan_stat.connection_infos) {
2939 if (conn_info.remote_candidate.address().port() == port) {
2940 return true;
2941 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002942 }
2943 }
2944 }
2945 return false;
2946 };
2947
2948 EXPECT_FALSE(connection_with_remote_port(5000));
2949 EXPECT_FALSE(connection_with_remote_port(5001));
2950 EXPECT_FALSE(connection_with_remote_port(6000));
2951
2952 // The way the *_WAIT checks work is they only wait if the condition fails,
2953 // which does not help in the case where state is not changing. This is
2954 // problematic in this test since we want to verify that adding a video
2955 // candidate does _not_ change state. So we interleave candidates and assume
2956 // that messages are executed in the order they were posted.
2957
2958 // First audio candidate.
2959 cricket::Candidate candidate0;
2960 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2961 candidate0.set_component(1);
2962 candidate0.set_protocol("udp");
2963 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2964 candidate0);
2965 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2966
2967 // Video candidate.
2968 cricket::Candidate candidate1;
2969 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2970 candidate1.set_component(1);
2971 candidate1.set_protocol("udp");
2972 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2973 candidate1);
2974 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2975
2976 // Second audio candidate.
2977 cricket::Candidate candidate2;
2978 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2979 candidate2.set_component(1);
2980 candidate2.set_protocol("udp");
2981 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2982 candidate2);
2983 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2984
2985 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2986 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2987
2988 // No need here for a _WAIT check since we are checking that state hasn't
2989 // changed: if this is false we would be doing waits for nothing and if this
2990 // is true then there will be no messages processed anyways.
2991 EXPECT_FALSE(connection_with_remote_port(6000));
2992}
2993
deadbeefcbecd352015-09-23 11:50:27 -07002994// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002995TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2996 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002997 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002998
2999 PeerConnectionInterface::RTCOfferAnswerOptions options;
3000 options.use_rtp_mux = true;
3001
3002 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003003 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003004
deadbeefcbecd352015-09-23 11:50:27 -07003005 EXPECT_NE(session_->voice_rtp_transport_channel(),
3006 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003007
deadbeefab9b2d12015-10-14 11:33:11 -07003008 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003009 SessionDescriptionInterface* answer =
3010 CreateRemoteAnswer(session_->local_description());
3011 SetRemoteDescriptionWithoutError(answer);
3012
deadbeefcbecd352015-09-23 11:50:27 -07003013 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3014 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003015}
3016
deadbeefcbecd352015-09-23 11:50:27 -07003017// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003018TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3019 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003020 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003021
Donald Curtis0e209b02015-03-24 09:29:54 -07003022 PeerConnectionInterface::RTCOfferAnswerOptions options;
3023 options.use_rtp_mux = true;
3024
3025 SessionDescriptionInterface* offer = CreateOffer(options);
3026 SetLocalDescriptionWithoutError(offer);
3027
deadbeefcbecd352015-09-23 11:50:27 -07003028 EXPECT_NE(session_->voice_rtp_transport_channel(),
3029 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003030
deadbeefab9b2d12015-10-14 11:33:11 -07003031 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003032
3033 // Remove BUNDLE from the answer.
3034 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3035 CreateRemoteAnswer(session_->local_description()));
3036 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3037 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3038 JsepSessionDescription* modified_answer =
3039 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3040 modified_answer->Initialize(answer_copy, "1", "1");
3041 SetRemoteDescriptionWithoutError(modified_answer); //
3042
deadbeefcbecd352015-09-23 11:50:27 -07003043 EXPECT_NE(session_->voice_rtp_transport_channel(),
3044 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003045}
3046
3047// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3048TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3049 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003050 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003051
3052 PeerConnectionInterface::RTCOfferAnswerOptions options;
3053 options.use_rtp_mux = true;
3054
3055 SessionDescriptionInterface* offer = CreateOffer(options);
3056 SetLocalDescriptionWithoutError(offer);
3057
deadbeefcbecd352015-09-23 11:50:27 -07003058 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3059 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003060
deadbeefab9b2d12015-10-14 11:33:11 -07003061 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003062 SessionDescriptionInterface* answer =
3063 CreateRemoteAnswer(session_->local_description());
3064 SetRemoteDescriptionWithoutError(answer);
3065
deadbeefcbecd352015-09-23 11:50:27 -07003066 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3067 session_->video_rtp_transport_channel());
3068}
3069
3070// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3071// audio content in the answer.
3072TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3073 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003074 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003075
3076 PeerConnectionInterface::RTCOfferAnswerOptions options;
3077 options.use_rtp_mux = true;
3078
3079 SessionDescriptionInterface* offer = CreateOffer(options);
3080 SetLocalDescriptionWithoutError(offer);
3081
3082 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3083 session_->video_rtp_transport_channel());
3084
deadbeefab9b2d12015-10-14 11:33:11 -07003085 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003086 cricket::MediaSessionOptions recv_options;
3087 recv_options.recv_audio = false;
3088 recv_options.recv_video = true;
3089 SessionDescriptionInterface* answer =
3090 CreateRemoteAnswer(session_->local_description(), recv_options);
3091 SetRemoteDescriptionWithoutError(answer);
3092
deadbeefd59daf82015-10-14 15:02:44 -07003093 EXPECT_TRUE(nullptr == session_->voice_channel());
3094 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003095
deadbeefd59daf82015-10-14 15:02:44 -07003096 session_->Close();
3097 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3098 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3099 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3100 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003101}
3102
3103// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3104TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3105 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003106 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003107
Donald Curtis0e209b02015-03-24 09:29:54 -07003108 PeerConnectionInterface::RTCOfferAnswerOptions options;
3109 options.use_rtp_mux = true;
3110
3111 SessionDescriptionInterface* offer = CreateOffer(options);
3112 SetLocalDescriptionWithoutError(offer);
3113
deadbeefcbecd352015-09-23 11:50:27 -07003114 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3115 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003116
deadbeefab9b2d12015-10-14 11:33:11 -07003117 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003118
3119 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003120 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003121 CreateRemoteAnswer(session_->local_description()));
3122 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3123 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3124 JsepSessionDescription* modified_answer =
3125 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3126 modified_answer->Initialize(answer_copy, "1", "1");
3127 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003128
deadbeefcbecd352015-09-23 11:50:27 -07003129 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3130 session_->video_rtp_transport_channel());
3131}
3132
3133// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3134TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3135 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003136 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003137
3138 SessionDescriptionInterface* offer = CreateRemoteOffer();
3139 SetRemoteDescriptionWithoutError(offer);
3140
3141 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3142 session_->video_rtp_transport_channel());
3143
deadbeefab9b2d12015-10-14 11:33:11 -07003144 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003145 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003146 SetLocalDescriptionWithoutError(answer);
3147
3148 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3149 session_->video_rtp_transport_channel());
3150}
3151
3152// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3153TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3154 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003155 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003156
3157 // Remove BUNDLE from the offer.
3158 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3159 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3160 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3161 JsepSessionDescription* modified_offer =
3162 new JsepSessionDescription(JsepSessionDescription::kOffer);
3163 modified_offer->Initialize(offer_copy, "1", "1");
3164
3165 // Expect an error when applying the remote description
3166 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3167 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003168}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003169
Peter Thatcher4eddf182015-04-30 10:55:59 -07003170// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003171TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3172 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003173 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003174
Donald Curtis0e209b02015-03-24 09:29:54 -07003175 PeerConnectionInterface::RTCOfferAnswerOptions options;
3176 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003177
Donald Curtis0e209b02015-03-24 09:29:54 -07003178 SessionDescriptionInterface* offer = CreateOffer(options);
3179 SetLocalDescriptionWithoutError(offer);
3180
deadbeefcbecd352015-09-23 11:50:27 -07003181 EXPECT_NE(session_->voice_rtp_transport_channel(),
3182 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003183
deadbeefab9b2d12015-10-14 11:33:11 -07003184 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003185 SessionDescriptionInterface* answer =
3186 CreateRemoteAnswer(session_->local_description());
3187 SetRemoteDescriptionWithoutError(answer);
3188
3189 // This should lead to an audio-only call but isn't implemented
3190 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003191 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3192 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003193}
3194
deadbeefcbecd352015-09-23 11:50:27 -07003195// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003196TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3197 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003198 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003199 PeerConnectionInterface::RTCOfferAnswerOptions options;
3200 options.use_rtp_mux = true;
3201
3202 SessionDescriptionInterface* offer = CreateOffer(options);
3203 SetLocalDescriptionWithoutError(offer);
3204
deadbeefcbecd352015-09-23 11:50:27 -07003205 EXPECT_NE(session_->voice_rtp_transport_channel(),
3206 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003207
deadbeefab9b2d12015-10-14 11:33:11 -07003208 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003209
3210 // Remove BUNDLE from the answer.
3211 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3212 CreateRemoteAnswer(session_->local_description()));
3213 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3214 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3215 JsepSessionDescription* modified_answer =
3216 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3217 modified_answer->Initialize(answer_copy, "1", "1");
3218 SetRemoteDescriptionWithoutError(modified_answer); //
3219
deadbeefcbecd352015-09-23 11:50:27 -07003220 EXPECT_NE(session_->voice_rtp_transport_channel(),
3221 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003222}
3223
Peter Thatcher4eddf182015-04-30 10:55:59 -07003224// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3225TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3226 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003227 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003228
3229 PeerConnectionInterface::RTCOfferAnswerOptions options;
3230 options.use_rtp_mux = true;
3231
3232 SessionDescriptionInterface* offer = CreateOffer(options);
3233 SetRemoteDescriptionWithoutError(offer);
3234
deadbeefcbecd352015-09-23 11:50:27 -07003235 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3236 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003237}
3238
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003239TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3240 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003241 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003242
3243 PeerConnectionInterface::RTCOfferAnswerOptions options;
3244 SessionDescriptionInterface* offer = CreateOffer(options);
3245 SetLocalDescriptionWithoutError(offer);
3246
deadbeefcbecd352015-09-23 11:50:27 -07003247 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3248 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003249
deadbeefab9b2d12015-10-14 11:33:11 -07003250 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003251 SessionDescriptionInterface* answer =
3252 CreateRemoteAnswer(session_->local_description());
3253 SetRemoteDescriptionWithoutError(answer);
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}
3258
3259TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3260 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003261 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003262
3263 PeerConnectionInterface::RTCOfferAnswerOptions options;
3264 SessionDescriptionInterface* offer = CreateOffer(options);
3265 SetLocalDescriptionWithoutError(offer);
3266
deadbeefcbecd352015-09-23 11:50:27 -07003267 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3268 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003269
deadbeefab9b2d12015-10-14 11:33:11 -07003270 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003271 SessionDescriptionInterface* answer =
3272 CreateRemoteAnswer(session_->local_description());
3273 SetRemoteDescriptionWithoutError(answer);
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}
3278
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003279// This test verifies that SetLocalDescription and SetRemoteDescription fails
3280// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3281TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003282 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003283 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003284
3285 PeerConnectionInterface::RTCOfferAnswerOptions options;
3286 options.use_rtp_mux = true;
3287
3288 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003289 std::string offer_str;
3290 offer->ToString(&offer_str);
3291 // Disable rtcp-mux
3292 const std::string rtcp_mux = "rtcp-mux";
3293 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003294 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003295 xrtcp_mux.c_str(), xrtcp_mux.length(),
3296 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003297 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003298 new JsepSessionDescription(JsepSessionDescription::kOffer);
3299 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003300 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003301 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003302 new JsepSessionDescription(JsepSessionDescription::kOffer);
3303 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003304 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003305 // Trying unmodified SDP.
3306 SetLocalDescriptionWithoutError(offer);
3307}
3308
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003309TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003310 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003311 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003312 CreateAndSetRemoteOfferAndLocalAnswer();
3313 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3314 ASSERT_TRUE(channel != NULL);
3315 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003316 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003317 double volume;
3318 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3319 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003320 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003321 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3322 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003323 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003324 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3325 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003326}
3327
3328TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003329 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003330 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003331 CreateAndSetRemoteOfferAndLocalAnswer();
3332 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3333 ASSERT_TRUE(channel != NULL);
3334 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003335 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3337
3338 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003339 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003340
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003341 rtc::scoped_ptr<FakeAudioSource> source(new FakeAudioSource());
3342 session_->SetAudioSend(send_ssrc, false, options, source.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003343 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003344 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003345 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003346
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003347 // This will trigger SetSink(nullptr) to the |source|.
3348 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003349 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003350 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003351 EXPECT_TRUE(source->sink() == nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003352}
3353
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003354TEST_F(WebRtcSessionTest, AudioSourceForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003355 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003356 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003357 CreateAndSetRemoteOfferAndLocalAnswer();
3358 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3359 ASSERT_TRUE(channel != NULL);
3360 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003361 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003362
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003363 rtc::scoped_ptr<FakeAudioSource> source(new FakeAudioSource());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003364 cricket::AudioOptions options;
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003365 session_->SetAudioSend(send_ssrc, true, options, source.get());
3366 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003367
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003368 // Delete the |source| and it will trigger OnClose() to the sink, and this
3369 // will invalidate the |source_| pointer in the sink and prevent getting a
3370 // SetSink(nullptr) callback afterwards.
3371 source.reset();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003372
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003373 // This will trigger SetSink(nullptr) if no OnClose() callback.
3374 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003375}
3376
3377TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003378 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003379 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003380 CreateAndSetRemoteOfferAndLocalAnswer();
3381 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3382 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003383 ASSERT_LT(0u, channel->sinks().size());
3384 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003385 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003386 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003387 cricket::FakeVideoRenderer renderer;
3388 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003389 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003390 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003391 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003392}
3393
3394TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003395 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003396 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003397 CreateAndSetRemoteOfferAndLocalAnswer();
3398 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3399 ASSERT_TRUE(channel != NULL);
3400 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003401 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003402 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3403 cricket::VideoOptions* options = NULL;
3404 session_->SetVideoSend(send_ssrc, false, options);
3405 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3406 session_->SetVideoSend(send_ssrc, true, options);
3407 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3408}
3409
3410TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3411 TestCanInsertDtmf(false);
3412}
3413
3414TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3415 TestCanInsertDtmf(true);
3416}
3417
3418TEST_F(WebRtcSessionTest, InsertDtmf) {
3419 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003420 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003421 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003422 CreateAndSetRemoteOfferAndLocalAnswer();
3423 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3424 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3425
3426 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003427 const int expected_duration = 90;
3428 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3429 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3430 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3431
3432 // Verify
3433 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003434 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003435 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003436 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003437 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003438 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003439 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003440 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003441}
3442
deadbeefd59daf82015-10-14 15:02:44 -07003443// This test verifies the |initial_offerer| flag when session initiates the
3444// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003445TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003446 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003447 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003448 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003449 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3450 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003451 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003452 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003453 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003454}
3455
deadbeefd59daf82015-10-14 15:02:44 -07003456// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003457TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003458 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003459 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003460 SessionDescriptionInterface* offer = CreateRemoteOffer();
3461 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003462 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003463
deadbeefd59daf82015-10-14 15:02:44 -07003464 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003465 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003466 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003467}
3468
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003469// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3470TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003471 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003472 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003473 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003474 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003475 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476 CreateRemoteAnswer(session_->local_description()));
3477
3478 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3479 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003480 JsepSessionDescription* modified_answer =
3481 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003482
3483 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3484 answer->session_id(),
3485 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003486 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003487
wu@webrtc.org4e393072014-04-07 17:04:35 +00003488 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003489 std::string sdp;
3490 EXPECT_TRUE(answer->ToString(&sdp));
3491 const std::string kAudioMid = "a=mid:audio";
3492 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003493 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003494 kAudioMidReplaceStr.c_str(),
3495 kAudioMidReplaceStr.length(),
3496 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003497 SessionDescriptionInterface* modified_answer1 =
3498 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003499 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003500
wu@webrtc.org4e393072014-04-07 17:04:35 +00003501 // Different media types.
3502 EXPECT_TRUE(answer->ToString(&sdp));
3503 const std::string kAudioMline = "m=audio";
3504 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003505 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003506 kAudioMlineReplaceStr.c_str(),
3507 kAudioMlineReplaceStr.length(),
3508 &sdp);
3509 SessionDescriptionInterface* modified_answer2 =
3510 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3511 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3512
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003513 SetRemoteDescriptionWithoutError(answer.release());
3514}
3515
3516// Verifying remote offer and local answer have matching m-lines as per
3517// RFC 3264.
3518TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003519 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003520 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003521 SessionDescriptionInterface* offer = CreateRemoteOffer();
3522 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003523 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003524
3525 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3526 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003527 JsepSessionDescription* modified_answer =
3528 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003529
3530 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3531 answer->session_id(),
3532 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003533 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003534 SetLocalDescriptionWithoutError(answer);
3535}
3536
3537// This test verifies that WebRtcSession does not start candidate allocation
3538// before SetLocalDescription is called.
3539TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003540 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003541 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003542 SessionDescriptionInterface* offer = CreateRemoteOffer();
3543 cricket::Candidate candidate;
3544 candidate.set_component(1);
3545 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3546 candidate);
3547 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3548 cricket::Candidate candidate1;
3549 candidate1.set_component(1);
3550 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3551 candidate1);
3552 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3553 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003554 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3555 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003556
3557 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003558 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003559 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3560 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3561
htaa2a49d92016-03-04 02:51:39 -08003562 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003563 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003564 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3565}
3566
3567// This test verifies that crypto parameter is updated in local session
3568// description as per security policy set in MediaSessionDescriptionFactory.
3569TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003570 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003571 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003572 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003573
3574 // Making sure SetLocalDescription correctly sets crypto value in
3575 // SessionDescription object after de-serialization of sdp string. The value
3576 // will be set as per MediaSessionDescriptionFactory.
3577 std::string offer_str;
3578 offer->ToString(&offer_str);
3579 SessionDescriptionInterface* jsep_offer_str =
3580 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3581 SetLocalDescriptionWithoutError(jsep_offer_str);
3582 EXPECT_TRUE(session_->voice_channel()->secure_required());
3583 EXPECT_TRUE(session_->video_channel()->secure_required());
3584}
3585
3586// This test verifies the crypto parameter when security is disabled.
3587TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003588 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003589 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003590 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003591 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003592
3593 // Making sure SetLocalDescription correctly sets crypto value in
3594 // SessionDescription object after de-serialization of sdp string. The value
3595 // will be set as per MediaSessionDescriptionFactory.
3596 std::string offer_str;
3597 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003598 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003599 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3600 SetLocalDescriptionWithoutError(jsep_offer_str);
3601 EXPECT_FALSE(session_->voice_channel()->secure_required());
3602 EXPECT_FALSE(session_->video_channel()->secure_required());
3603}
3604
3605// This test verifies that an answer contains new ufrag and password if an offer
3606// with new ufrag and password is received.
3607TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003608 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003609 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003610 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003611 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003612 CreateRemoteOffer(options));
3613 SetRemoteDescriptionWithoutError(offer.release());
3614
deadbeefab9b2d12015-10-14 11:33:11 -07003615 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003616 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003617 SetLocalDescriptionWithoutError(answer.release());
3618
3619 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003620 for (const cricket::ContentInfo& content :
3621 session_->local_description()->description()->contents()) {
3622 options.transport_options[content.name].ice_restart = true;
3623 }
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003624 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003625 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003626 SetRemoteDescriptionWithoutError(updated_offer1.release());
3627
htaa2a49d92016-03-04 02:51:39 -08003628 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003629
deadbeef0ed85b22016-02-23 17:24:52 -08003630 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3631 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003632
deadbeef0ed85b22016-02-23 17:24:52 -08003633 // Even a second answer (created before the description is set) should have
3634 // a new ufrag/password.
htaa2a49d92016-03-04 02:51:39 -08003635 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003636
3637 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3638 session_->local_description()->description()));
3639
3640 SetLocalDescriptionWithoutError(updated_answer2.release());
3641}
3642
3643// This test verifies that an answer contains new ufrag and password if an offer
3644// that changes either the ufrag or password (but not both) is received.
3645// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3646// a=ice-pwd attributes compared to the previous SDP from the peer, it
3647// indicates that ICE is restarting for this media stream."
3648TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3649 Init();
3650 cricket::MediaSessionOptions options;
3651 options.recv_audio = true;
3652 options.recv_video = true;
3653 // Create an offer with audio and video.
3654 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3655 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3656 SetRemoteDescriptionWithoutError(offer.release());
3657
3658 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003659 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003660 SetLocalDescriptionWithoutError(answer.release());
3661
3662 // Receive an offer with a new ufrag but stale password.
3663 rtc::scoped_ptr<JsepSessionDescription> ufrag_changed_offer(
3664 CreateRemoteOffer(options, session_->remote_description()));
3665 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3666 "original_password12345");
3667 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3668
htaa2a49d92016-03-04 02:51:39 -08003669 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003670 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3671 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003672 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003673
3674 // Receive an offer with a new password but stale ufrag.
3675 rtc::scoped_ptr<JsepSessionDescription> password_changed_offer(
3676 CreateRemoteOffer(options, session_->remote_description()));
3677 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3678 "modified_password12345");
3679 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3680
htaa2a49d92016-03-04 02:51:39 -08003681 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003682 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3683 session_->local_description()->description()));
3684 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003685}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003686
wu@webrtc.org91053e72013-08-10 07:18:04 +00003687// This test verifies that an answer contains old ufrag and password if an offer
3688// with old ufrag and password is received.
3689TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003690 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003691 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003692 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003693 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003694 CreateRemoteOffer(options));
3695 SetRemoteDescriptionWithoutError(offer.release());
3696
deadbeefab9b2d12015-10-14 11:33:11 -07003697 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003698 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003699 SetLocalDescriptionWithoutError(answer.release());
3700
3701 // Receive an offer without changed ufrag or password.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003702 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003703 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003704 SetRemoteDescriptionWithoutError(updated_offer2.release());
3705
htaa2a49d92016-03-04 02:51:39 -08003706 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003707
deadbeef0ed85b22016-02-23 17:24:52 -08003708 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3709 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003710
3711 SetLocalDescriptionWithoutError(updated_answer2.release());
3712}
3713
deadbeef0ed85b22016-02-23 17:24:52 -08003714// This test verifies that if an offer does an ICE restart on some, but not all
3715// media sections, the answer will change the ufrag/password in the correct
3716// media sections.
3717TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3718 Init();
3719 cricket::MediaSessionOptions options;
3720 options.recv_video = true;
3721 options.recv_audio = true;
3722 options.bundle_enabled = false;
3723 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3724
3725 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3726 "aaaaaaaaaaaaaaaaaaaaaa");
3727 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3728 "bbbbbbbbbbbbbbbbbbbbbb");
3729 SetRemoteDescriptionWithoutError(offer.release());
3730
3731 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003732 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003733 SetLocalDescriptionWithoutError(answer.release());
3734
3735 // Receive an offer with new ufrag and password, but only for the video media
3736 // section.
3737 rtc::scoped_ptr<JsepSessionDescription> updated_offer(
3738 CreateRemoteOffer(options, session_->remote_description()));
3739 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3740 "cccccccccccccccccccccc");
3741 SetRemoteDescriptionWithoutError(updated_offer.release());
3742
htaa2a49d92016-03-04 02:51:39 -08003743 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003744
3745 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3746 session_->local_description()->description(),
3747 cricket::MEDIA_TYPE_AUDIO));
3748
3749 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3750 session_->local_description()->description(),
3751 cricket::MEDIA_TYPE_VIDEO));
3752
3753 SetLocalDescriptionWithoutError(updated_answer.release());
3754}
3755
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003756TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003757 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003758 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003759 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003760 const std::string session_id_orig = offer->session_id();
3761 const std::string session_version_orig = offer->session_version();
3762 SetLocalDescriptionWithoutError(offer);
3763
3764 video_channel_ = media_engine_->GetVideoChannel(0);
3765 video_channel_->set_fail_set_send_codecs(true);
3766
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003767 SessionDescriptionInterface* answer =
3768 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003769 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003770
3771 // Test that after a content error, setting any description will
3772 // result in an error.
3773 video_channel_->set_fail_set_send_codecs(false);
3774 answer = CreateRemoteAnswer(session_->local_description());
3775 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3776 offer = CreateRemoteOffer();
3777 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003778}
3779
3780// Runs the loopback call test with BUNDLE and STUN disabled.
3781TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3782 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003783 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003784 cricket::PORTALLOCATOR_DISABLE_STUN |
3785 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003786 TestLoopbackCall();
3787}
3788
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003789TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003790 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003791 cricket::PORTALLOCATOR_DISABLE_STUN |
3792 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3793 cricket::PORTALLOCATOR_DISABLE_RELAY);
3794
3795 // best connection is IPv6 since it has higher network preference.
3796 LoopbackNetworkConfiguration config;
3797 config.test_ipv6_network_ = true;
3798 config.best_connection_after_initial_ice_converged_ =
3799 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3800
3801 TestLoopbackCall(config);
3802}
3803
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003804// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003805TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003806 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3807 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003808 TestLoopbackCall();
3809}
3810
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003811TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003812 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003813 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003814 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003815 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003816 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3817}
3818
Henrik Boström87713d02015-08-25 09:53:21 +02003819TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003820 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003821
htaa2a49d92016-03-04 02:51:39 -08003822 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003823 options_.disable_sctp_data_channels = false;
3824
Henrik Boström87713d02015-08-25 09:53:21 +02003825 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003826
3827 SetLocalDescriptionWithDataChannel();
3828 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3829}
3830
Henrik Boström87713d02015-08-25 09:53:21 +02003831TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003832 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003833
Henrik Boström87713d02015-08-25 09:53:21 +02003834 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003835
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003836 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003837 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003838 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3839}
3840
Henrik Boström87713d02015-08-25 09:53:21 +02003841TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003842 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003843 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003844 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003845
3846 // Create remote offer with SCTP.
3847 cricket::MediaSessionOptions options;
3848 options.data_channel_type = cricket::DCT_SCTP;
3849 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003850 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003851 SetRemoteDescriptionWithoutError(offer);
3852
3853 // Verifies the answer contains SCTP.
htaa2a49d92016-03-04 02:51:39 -08003854 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003855 EXPECT_TRUE(answer != NULL);
3856 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3857 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003858}
3859
Henrik Boström87713d02015-08-25 09:53:21 +02003860TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003861 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003862 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003863
3864 SetLocalDescriptionWithDataChannel();
3865 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3866}
3867
Henrik Boström87713d02015-08-25 09:53:21 +02003868TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003869 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003870
Henrik Boström87713d02015-08-25 09:53:21 +02003871 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003872
3873 SetLocalDescriptionWithDataChannel();
3874 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3875}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003876
Henrik Boström87713d02015-08-25 09:53:21 +02003877TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003878 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003879 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003880 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003881
3882 SetLocalDescriptionWithDataChannel();
3883 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3884}
3885
Henrik Boström87713d02015-08-25 09:53:21 +02003886TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003887 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003888 const int new_send_port = 9998;
3889 const int new_recv_port = 7775;
3890
Henrik Boström87713d02015-08-25 09:53:21 +02003891 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003892 SetFactoryDtlsSrtp();
3893
3894 // By default, don't actually add the codecs to desc_factory_; they don't
3895 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3896 // let the session description get parsed. That'll get the proper codecs
3897 // into the stream.
3898 cricket::MediaSessionOptions options;
3899 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3900 "stream1", new_send_port, options);
3901
3902 // SetRemoteDescription will take the ownership of the offer.
3903 SetRemoteDescriptionWithoutError(offer);
3904
htaa2a49d92016-03-04 02:51:39 -08003905 SessionDescriptionInterface* answer =
3906 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003907 ASSERT_TRUE(answer != NULL);
3908
3909 // Now set the local description, which'll take ownership of the answer.
3910 SetLocalDescriptionWithoutError(answer);
3911
3912 // TEST PLAN: Set the port number to something new, set it in the SDP,
3913 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003914 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003915 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003916
3917 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3918 int portnum = -1;
3919 ASSERT_TRUE(ch != NULL);
3920 ASSERT_EQ(1UL, ch->send_codecs().size());
3921 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003922 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003923 ch->send_codecs()[0].name.c_str()));
3924 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3925 &portnum));
3926 EXPECT_EQ(new_send_port, portnum);
3927
3928 ASSERT_EQ(1UL, ch->recv_codecs().size());
3929 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003930 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003931 ch->recv_codecs()[0].name.c_str()));
3932 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3933 &portnum));
3934 EXPECT_EQ(new_recv_port, portnum);
3935}
3936
deadbeefab9b2d12015-10-14 11:33:11 -07003937// Verifies that when a session's DataChannel receives an OPEN message,
3938// WebRtcSession signals the DataChannel creation request with the expected
3939// config.
3940TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3941 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3942
3943 InitWithDtls(GetParam());
3944
3945 SetLocalDescriptionWithDataChannel();
3946 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3947
3948 webrtc::DataChannelInit config;
3949 config.id = 1;
3950 rtc::Buffer payload;
3951 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3952 cricket::ReceiveDataParams params;
3953 params.ssrc = config.id;
3954 params.type = cricket::DMT_CONTROL;
3955
3956 cricket::DataChannel* data_channel = session_->data_channel();
3957 data_channel->SignalDataReceived(data_channel, params, payload);
3958
3959 EXPECT_EQ("a", last_data_channel_label_);
3960 EXPECT_EQ(config.id, last_data_channel_config_.id);
3961 EXPECT_FALSE(last_data_channel_config_.negotiated);
3962 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3963 last_data_channel_config_.open_handshake_role);
3964}
3965
3966TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003967 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3968 FakeDtlsIdentityStore::GenerateCertificate();
3969
htaa2a49d92016-03-04 02:51:39 -08003970 configuration_.certificates.push_back(certificate);
3971 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02003972 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3973
3974 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3975}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003976
Henrik Boström87713d02015-08-25 09:53:21 +02003977// Verifies that CreateOffer succeeds when CreateOffer is called before async
3978// identity generation is finished (even if a certificate is provided this is
3979// an async op).
3980TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3981 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3982 InitWithDtls(GetParam());
3983
Henrik Boströmd8281982015-08-27 10:12:24 +02003984 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003985 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003986 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3987
wu@webrtc.org91053e72013-08-10 07:18:04 +00003988 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003989 VerifyNoCryptoParams(offer->description(), true);
3990 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003991}
3992
3993// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003994// identity generation is finished (even if a certificate is provided this is
3995// an async op).
3996TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003997 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003998 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003999 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004000
4001 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004002 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00004003 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004004 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004005 ASSERT_TRUE(offer.get() != NULL);
4006 SetRemoteDescriptionWithoutError(offer.release());
4007
htaa2a49d92016-03-04 02:51:39 -08004008 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004009 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004010 VerifyNoCryptoParams(answer->description(), true);
4011 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004012}
4013
4014// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004015// identity generation is finished (even if a certificate is provided this is
4016// an async op).
4017TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004018 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004019 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004020
Henrik Boströmd8281982015-08-27 10:12:24 +02004021 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004022
4023 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004024 EXPECT_TRUE(offer != NULL);
4025}
4026
4027// Verifies that CreateOffer fails when CreateOffer is called after async
4028// identity generation fails.
4029TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004030 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004031 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004032
Henrik Boströmd8281982015-08-27 10:12:24 +02004033 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004034
4035 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004036 EXPECT_TRUE(offer == NULL);
4037}
4038
4039// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4040// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004041TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004042 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004043 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004044 VerifyMultipleAsyncCreateDescription(GetParam(),
4045 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004046}
4047
4048// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4049// before async identity generation fails.
4050TEST_F(WebRtcSessionTest,
4051 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004052 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004053 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4054 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004055}
4056
4057// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4058// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004059TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004060 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004061 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004062 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004063 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004064}
4065
4066// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4067// before async identity generation fails.
4068TEST_F(WebRtcSessionTest,
4069 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004070 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004071 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4072 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004073}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004074
4075// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4076// offer has no SDES crypto but only DTLS fingerprint.
4077TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4078 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004079 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004080 // Create a remote offer with secured transport disabled.
4081 cricket::MediaSessionOptions options;
4082 JsepSessionDescription* offer(CreateRemoteOffer(
4083 options, cricket::SEC_DISABLED));
4084 // Adds a DTLS fingerprint to the remote offer.
4085 cricket::SessionDescription* sdp = offer->description();
4086 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4087 ASSERT_TRUE(audio != NULL);
4088 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4089 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004090 rtc::SSLFingerprint::CreateFromRfc4572(
4091 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004092 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004093 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004094}
4095
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004096TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004097 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004098 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004099 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004100 SessionDescriptionInterface* offer = CreateOffer();
4101
4102 SetLocalDescriptionWithoutError(offer);
4103
4104 voice_channel_ = media_engine_->GetVoiceChannel(0);
4105
4106 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004107 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004108 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004109}
4110
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004111// Tests that we can renegotiate new media content with ICE candidates in the
4112// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004113TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004114 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004115 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004116 SetFactoryDtlsSrtp();
4117
deadbeefab9b2d12015-10-14 11:33:11 -07004118 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004119 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004120 SetLocalDescriptionWithoutError(offer);
4121
4122 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4123 SetRemoteDescriptionWithoutError(answer);
4124
4125 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004126 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004127 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4128
4129 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004130 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004131 candidate1.set_component(1);
4132 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4133 candidate1);
4134 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4135 SetRemoteDescriptionWithoutError(offer);
4136
htaa2a49d92016-03-04 02:51:39 -08004137 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004138 SetLocalDescriptionWithoutError(answer);
4139}
4140
4141// Tests that we can renegotiate new media content with ICE candidates separated
4142// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004143TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004144 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004145 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004146 SetFactoryDtlsSrtp();
4147
deadbeefab9b2d12015-10-14 11:33:11 -07004148 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004149 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004150 SetLocalDescriptionWithoutError(offer);
4151
4152 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4153 SetRemoteDescriptionWithoutError(answer);
4154
4155 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004156 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004157 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4158 SetRemoteDescriptionWithoutError(offer);
4159
4160 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004161 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004162 candidate1.set_component(1);
4163 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4164 candidate1);
4165 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4166
htaa2a49d92016-03-04 02:51:39 -08004167 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004168 SetLocalDescriptionWithoutError(answer);
4169}
honghaiz7f777492016-02-02 21:54:01 -08004170
4171// Flaky on Win and Mac only. See webrtc:4943
4172#if defined(WEBRTC_WIN) || defined(WEBRTC_MAC)
4173#define MAYBE_TestRtxRemovedByCreateAnswer DISABLED_TestRtxRemovedByCreateAnswer
4174#else
4175#define MAYBE_TestRtxRemovedByCreateAnswer TestRtxRemovedByCreateAnswer
4176#endif
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004177// Tests that RTX codec is removed from the answer when it isn't supported
4178// by local side.
honghaiz7f777492016-02-02 21:54:01 -08004179TEST_F(WebRtcSessionTest, MAYBE_TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004180 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004181 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004182 std::string offer_sdp(kSdpWithRtx);
4183
4184 SessionDescriptionInterface* offer =
4185 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4186 EXPECT_TRUE(offer->ToString(&offer_sdp));
4187
4188 // Offer SDP contains the RTX codec.
4189 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4190 SetRemoteDescriptionWithoutError(offer);
4191
htaa2a49d92016-03-04 02:51:39 -08004192 SessionDescriptionInterface* answer = CreateAnswer();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004193 std::string answer_sdp;
4194 answer->ToString(&answer_sdp);
4195 // Answer SDP removes the unsupported RTX codec.
4196 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4197 SetLocalDescriptionWithoutError(answer);
4198}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004199
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004200// This verifies that the voice channel after bundle has both options from video
4201// and voice channels.
4202TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4203 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004204 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004205
4206 PeerConnectionInterface::RTCOfferAnswerOptions options;
4207 options.use_rtp_mux = true;
4208
4209 SessionDescriptionInterface* offer = CreateOffer(options);
4210 SetLocalDescriptionWithoutError(offer);
4211
4212 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4213 rtc::Socket::Option::OPT_SNDBUF, 4000);
4214
4215 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4216 rtc::Socket::Option::OPT_RCVBUF, 8000);
4217
4218 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004219 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004220 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4221 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004222 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004223 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4224
deadbeefcbecd352015-09-23 11:50:27 -07004225 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004226 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4227 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004228 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004229 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4230
deadbeefcbecd352015-09-23 11:50:27 -07004231 EXPECT_NE(session_->voice_rtp_transport_channel(),
4232 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004233
deadbeefab9b2d12015-10-14 11:33:11 -07004234 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004235 SessionDescriptionInterface* answer =
4236 CreateRemoteAnswer(session_->local_description());
4237 SetRemoteDescriptionWithoutError(answer);
4238
deadbeefcbecd352015-09-23 11:50:27 -07004239 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004240 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4241 EXPECT_EQ(4000, option_val);
4242
deadbeefcbecd352015-09-23 11:50:27 -07004243 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004244 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4245 EXPECT_EQ(8000, option_val);
4246}
4247
tommi0f620f42015-07-09 03:25:02 -07004248// Test creating a session, request multiple offers, destroy the session
4249// and make sure we got success/failure callbacks for all of the requests.
4250// Background: crbug.com/507307
4251TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4252 Init();
4253
4254 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4255 PeerConnectionInterface::RTCOfferAnswerOptions options;
4256 options.offer_to_receive_audio =
4257 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004258 cricket::MediaSessionOptions session_options;
4259 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004260
4261 for (auto& o : observers) {
4262 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004263 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004264 }
4265
4266 session_.reset();
4267
tommi0f620f42015-07-09 03:25:02 -07004268 for (auto& o : observers) {
4269 // We expect to have received a notification now even if the session was
4270 // terminated. The offer creation may or may not have succeeded, but we
4271 // must have received a notification which, so the only invalid state
4272 // is kInit.
4273 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4274 }
4275}
4276
stefanc1aeaf02015-10-15 07:26:07 -07004277TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4278 TestPacketOptions();
4279}
4280
deadbeef057ecf02016-01-20 14:30:43 -08004281// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4282// is destroyed.
4283TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4284 Init();
4285 session_.reset();
4286 EXPECT_TRUE(session_destroyed_);
4287}
4288
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004289// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4290// currently fails because upon disconnection and reconnection OnIceComplete is
4291// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004292
deadbeefcbecd352015-09-23 11:50:27 -07004293INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4294 WebRtcSessionTest,
4295 testing::Values(ALREADY_GENERATED,
4296 DTLS_IDENTITY_STORE));