blob: f503db3e130d35e457a2c2293efd5780092e5777 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kwiberg0eb15ed2015-12-17 03:04:15 -080011#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070012#include <vector>
13
Henrik Kjellander15583c12016-02-10 10:53:12 +010014#include "webrtc/api/audiotrack.h"
15#include "webrtc/api/fakemediacontroller.h"
16#include "webrtc/api/fakemetricsobserver.h"
17#include "webrtc/api/jsepicecandidate.h"
18#include "webrtc/api/jsepsessiondescription.h"
19#include "webrtc/api/peerconnection.h"
20#include "webrtc/api/sctputils.h"
21#include "webrtc/api/streamcollection.h"
22#include "webrtc/api/streamcollection.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010023#include "webrtc/api/test/fakedtlsidentitystore.h"
24#include "webrtc/api/videotrack.h"
25#include "webrtc/api/webrtcsession.h"
26#include "webrtc/api/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000027#include "webrtc/base/fakenetwork.h"
28#include "webrtc/base/firewallsocketserver.h"
29#include "webrtc/base/gunit.h"
30#include "webrtc/base/logging.h"
31#include "webrtc/base/network.h"
32#include "webrtc/base/physicalsocketserver.h"
33#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020034#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000035#include "webrtc/base/sslstreamadapter.h"
36#include "webrtc/base/stringutils.h"
37#include "webrtc/base/thread.h"
38#include "webrtc/base/virtualsocketserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080039#include "webrtc/media/base/fakemediaengine.h"
40#include "webrtc/media/base/fakevideorenderer.h"
41#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010042#include "webrtc/media/engine/fakewebrtccall.h"
kjellandera96e2d72016-02-04 23:52:28 -080043#include "webrtc/p2p/base/stunserver.h"
44#include "webrtc/p2p/base/teststunserver.h"
45#include "webrtc/p2p/base/testturnserver.h"
46#include "webrtc/p2p/base/transportchannel.h"
47#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010048#include "webrtc/pc/channelmanager.h"
49#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050
51#define MAYBE_SKIP_TEST(feature) \
52 if (!(feature())) { \
53 LOG(LS_INFO) << "Feature disabled... skipping"; \
54 return; \
55 }
56
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000059using rtc::SocketAddress;
60using rtc::scoped_ptr;
61using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000063using webrtc::CreateSessionDescriptionObserver;
64using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070065using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020066using webrtc::DtlsIdentityStoreInterface;
jbauchac8869e2015-07-03 01:36:14 -070067using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070069using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070using webrtc::JsepIceCandidate;
71using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000072using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073using webrtc::PeerConnectionInterface;
74using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070075using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000077using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000078using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000079using webrtc::kCreateChannelFailed;
80using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000082using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000083using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000084using webrtc::kSdpWithoutDtlsFingerprint;
85using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000087using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000088using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000090typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
91
wu@webrtc.org364f2042013-11-20 21:49:41 +000092static const int kClientAddrPort = 0;
93static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000094static const char kClientIPv6AddrHost1[] =
95 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000096static const char kClientAddrHost2[] = "22.22.22.22";
97static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000098static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
99static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000100static const char kTurnUsername[] = "test";
101static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
103static const char kSessionVersion[] = "1";
104
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105// Media index of candidates belonging to the first media content.
106static const int kMediaContentIndex0 = 0;
107static const char kMediaContentName0[] = "audio";
108
109// Media index of candidates belonging to the second media content.
110static const int kMediaContentIndex1 = 1;
111static const char kMediaContentName1[] = "video";
112
113static const int kIceCandidatesTimeout = 10000;
114
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000115static const char kFakeDtlsFingerprint[] =
116 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
117 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
118
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000119static const char kTooLongIceUfragPwd[] =
120 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
121 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
122 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
123 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
124
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000125static const char kSdpWithRtx[] =
126 "v=0\r\n"
127 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
128 "s=-\r\n"
129 "t=0 0\r\n"
130 "a=msid-semantic: WMS stream1\r\n"
131 "m=video 9 RTP/SAVPF 0 96\r\n"
132 "c=IN IP4 0.0.0.0\r\n"
133 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
134 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
135 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
136 "a=mid:video\r\n"
137 "a=sendrecv\r\n"
138 "a=rtcp-mux\r\n"
139 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
140 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
141 "a=rtpmap:0 fake_video_codec/90000\r\n"
142 "a=rtpmap:96 rtx/90000\r\n"
143 "a=fmtp:96 apt=0\r\n";
144
deadbeefab9b2d12015-10-14 11:33:11 -0700145static const char kStream1[] = "stream1";
146static const char kVideoTrack1[] = "video1";
147static const char kAudioTrack1[] = "audio1";
148
149static const char kStream2[] = "stream2";
150static const char kVideoTrack2[] = "video2";
151static const char kAudioTrack2[] = "audio2";
152
Henrik Boström87713d02015-08-25 09:53:21 +0200153enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
154
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155class MockIceObserver : public webrtc::IceObserver {
156 public:
157 MockIceObserver()
158 : oncandidatesready_(false),
159 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
160 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
161 }
162
perkjdfb769d2016-02-09 03:09:43 -0800163 void OnIceConnectionChange(
164 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 ice_connection_state_ = new_state;
166 }
perkjdfb769d2016-02-09 03:09:43 -0800167 void OnIceGatheringChange(
168 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 // We can never transition back to "new".
170 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
171 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800172 oncandidatesready_ =
173 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174 }
175
176 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800177 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000178 switch (candidate->sdp_mline_index()) {
179 case kMediaContentIndex0:
180 mline_0_candidates_.push_back(candidate->candidate());
181 break;
182 case kMediaContentIndex1:
183 mline_1_candidates_.push_back(candidate->candidate());
184 break;
185 default:
186 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000188
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 // The ICE gathering state should always be Gathering when a candidate is
190 // received (or possibly Completed in the case of the final candidate).
191 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
192 }
193
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 bool oncandidatesready_;
195 std::vector<cricket::Candidate> mline_0_candidates_;
196 std::vector<cricket::Candidate> mline_1_candidates_;
197 PeerConnectionInterface::IceConnectionState ice_connection_state_;
198 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
199};
200
201class WebRtcSessionForTest : public webrtc::WebRtcSession {
202 public:
stefanc1aeaf02015-10-15 07:26:07 -0700203 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000204 rtc::Thread* signaling_thread,
205 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700207 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700208 : WebRtcSession(media_controller,
209 signaling_thread,
210 worker_thread,
211 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 RegisterIceObserver(ice_observer);
213 }
214 virtual ~WebRtcSessionForTest() {}
215
deadbeefcbecd352015-09-23 11:50:27 -0700216 // Note that these methods are only safe to use if the signaling thread
217 // is the same as the worker thread
218 cricket::TransportChannel* voice_rtp_transport_channel() {
219 return rtp_transport_channel(voice_channel());
220 }
221
222 cricket::TransportChannel* voice_rtcp_transport_channel() {
223 return rtcp_transport_channel(voice_channel());
224 }
225
226 cricket::TransportChannel* video_rtp_transport_channel() {
227 return rtp_transport_channel(video_channel());
228 }
229
230 cricket::TransportChannel* video_rtcp_transport_channel() {
231 return rtcp_transport_channel(video_channel());
232 }
233
234 cricket::TransportChannel* data_rtp_transport_channel() {
235 return rtp_transport_channel(data_channel());
236 }
237
238 cricket::TransportChannel* data_rtcp_transport_channel() {
239 return rtcp_transport_channel(data_channel());
240 }
241
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 using webrtc::WebRtcSession::SetAudioPlayout;
243 using webrtc::WebRtcSession::SetAudioSend;
244 using webrtc::WebRtcSession::SetCaptureDevice;
245 using webrtc::WebRtcSession::SetVideoPlayout;
246 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700247
248 private:
249 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
250 if (!ch) {
251 return nullptr;
252 }
253 return ch->transport_channel();
254 }
255
256 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
257 if (!ch) {
258 return nullptr;
259 }
260 return ch->rtcp_transport_channel();
261 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262};
263
wu@webrtc.org91053e72013-08-10 07:18:04 +0000264class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000265 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000266 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000267 enum State {
268 kInit,
269 kFailed,
270 kSucceeded,
271 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000272 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000273
274 // CreateSessionDescriptionObserver implementation.
275 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000276 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000277 state_ = kSucceeded;
278 }
279 virtual void OnFailure(const std::string& error) {
280 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281 }
282
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000283 SessionDescriptionInterface* description() { return description_.get(); }
284
285 SessionDescriptionInterface* ReleaseDescription() {
286 return description_.release();
287 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288
wu@webrtc.org91053e72013-08-10 07:18:04 +0000289 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290
wu@webrtc.org91053e72013-08-10 07:18:04 +0000291 protected:
292 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293
294 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000295 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000296 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297};
298
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000299class FakeAudioRenderer : public cricket::AudioRenderer {
300 public:
solenberg98c68862015-10-09 03:27:14 -0700301 FakeAudioRenderer() : sink_(NULL) {}
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000302 virtual ~FakeAudioRenderer() {
303 if (sink_)
304 sink_->OnClose();
305 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000306
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000307 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000308
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000309 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000310 private:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000311 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000312};
313
Henrik Boström87713d02015-08-25 09:53:21 +0200314class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700315 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
316 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 protected:
318 // TODO Investigate why ChannelManager crashes, if it's created
319 // after stun_server.
320 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700321 : media_engine_(new cricket::FakeMediaEngine()),
322 data_engine_(new cricket::FakeDataEngine()),
323 channel_manager_(
324 new cricket::ChannelManager(media_engine_,
325 data_engine_,
326 new cricket::CaptureManager(),
327 rtc::Thread::Current())),
328 fake_call_(webrtc::Call::Config()),
329 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800330 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
331 rtc::Thread::Current(),
stefanc1aeaf02015-10-15 07:26:07 -0700332 channel_manager_.get())),
333 tdesc_factory_(new cricket::TransportDescriptionFactory()),
334 desc_factory_(
335 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
336 tdesc_factory_.get())),
337 pss_(new rtc::PhysicalSocketServer),
338 vss_(new rtc::VirtualSocketServer(pss_.get())),
339 fss_(new rtc::FirewallSocketServer(vss_.get())),
340 ss_scope_(fss_.get()),
341 stun_socket_addr_(
342 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
343 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
344 stun_socket_addr_)),
345 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
346 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000347 cricket::ServerAddresses stun_servers;
348 stun_servers.insert(stun_socket_addr_);
349 allocator_.reset(new cricket::BasicPortAllocator(
350 &network_manager_,
351 stun_servers,
352 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000353 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700354 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 EXPECT_TRUE(channel_manager_->Init());
356 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000357 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 }
359
360 void AddInterface(const SocketAddress& addr) {
361 network_manager_.AddInterface(addr);
362 }
363
Henrik Boström87713d02015-08-25 09:53:21 +0200364 // If |dtls_identity_store| != null or |rtc_configuration| contains
365 // |certificates| then DTLS will be enabled unless explicitly disabled by
366 // |rtc_configuration| options. When DTLS is enabled a certificate will be
367 // used if provided, otherwise one will be generated using the
368 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000369 void Init(
htaa2a49d92016-03-04 02:51:39 -0800370 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371 ASSERT_TRUE(session_.get() == NULL);
372 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700373 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700374 allocator_.get(), &observer_));
375 session_->SignalDataChannelOpenMessage.connect(
376 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800377 session_->GetOnDestroyedSignal()->connect(
378 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379
380 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
381 observer_.ice_connection_state_);
382 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
383 observer_.ice_gathering_state_);
384
htaa2a49d92016-03-04 02:51:39 -0800385 EXPECT_TRUE(session_->Initialize(options_, std::move(dtls_identity_store),
386 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700387 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 }
389
deadbeefab9b2d12015-10-14 11:33:11 -0700390 void OnDataChannelOpenMessage(const std::string& label,
391 const InternalDataChannelInit& config) {
392 last_data_channel_label_ = label;
393 last_data_channel_config_ = config;
394 }
395
deadbeef057ecf02016-01-20 14:30:43 -0800396 void OnSessionDestroyed() { session_destroyed_ = true; }
397
htaa2a49d92016-03-04 02:51:39 -0800398 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000399
400 void InitWithIceTransport(
401 PeerConnectionInterface::IceTransportsType ice_transport_type) {
htaa2a49d92016-03-04 02:51:39 -0800402 configuration_.type = ice_transport_type;
403 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000404 }
405
406 void InitWithBundlePolicy(
407 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800408 configuration_.bundle_policy = bundle_policy;
409 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700410 }
411
412 void InitWithRtcpMuxPolicy(
413 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
414 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800415 configuration_.rtcp_mux_policy = rtcp_mux_policy;
416 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000417 }
418
Henrik Boström87713d02015-08-25 09:53:21 +0200419 // Successfully init with DTLS; with a certificate generated and supplied or
420 // with a store that generates it for us.
421 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
422 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
Henrik Boström87713d02015-08-25 09:53:21 +0200423 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800424 configuration_.certificates.push_back(
Henrik Boström87713d02015-08-25 09:53:21 +0200425 FakeDtlsIdentityStore::GenerateCertificate());
426 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
427 dtls_identity_store.reset(new FakeDtlsIdentityStore());
428 dtls_identity_store->set_should_fail(false);
429 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700430 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200431 }
htaa2a49d92016-03-04 02:51:39 -0800432 Init(std::move(dtls_identity_store));
Henrik Boström87713d02015-08-25 09:53:21 +0200433 }
434
435 // Init with DTLS with a store that will fail to generate a certificate.
436 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200437 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
438 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200439 dtls_identity_store->set_should_fail(true);
htaa2a49d92016-03-04 02:51:39 -0800440 Init(std::move(dtls_identity_store));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000441 }
442
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443 void InitWithDtmfCodec() {
444 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000445 const cricket::AudioCodec kTelephoneEventCodec(
446 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447 std::vector<cricket::AudioCodec> codecs;
448 codecs.push_back(kTelephoneEventCodec);
449 media_engine_->SetAudioCodecs(codecs);
450 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000451 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452 }
453
deadbeefab9b2d12015-10-14 11:33:11 -0700454 void SendAudioVideoStream1() {
455 send_stream_1_ = true;
456 send_stream_2_ = false;
457 send_audio_ = true;
458 send_video_ = true;
459 }
460
461 void SendAudioVideoStream2() {
462 send_stream_1_ = false;
463 send_stream_2_ = true;
464 send_audio_ = true;
465 send_video_ = true;
466 }
467
468 void SendAudioVideoStream1And2() {
469 send_stream_1_ = true;
470 send_stream_2_ = true;
471 send_audio_ = true;
472 send_video_ = true;
473 }
474
475 void SendNothing() {
476 send_stream_1_ = false;
477 send_stream_2_ = false;
478 send_audio_ = false;
479 send_video_ = false;
480 }
481
482 void SendAudioOnlyStream2() {
483 send_stream_1_ = false;
484 send_stream_2_ = true;
485 send_audio_ = true;
486 send_video_ = false;
487 }
488
489 void SendVideoOnlyStream2() {
490 send_stream_1_ = false;
491 send_stream_2_ = true;
492 send_audio_ = false;
493 send_video_ = true;
494 }
495
496 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
497 if (send_stream_1_ && send_audio_) {
498 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
499 kStream1);
500 }
501 if (send_stream_1_ && send_video_) {
502 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
503 kStream1);
504 }
505 if (send_stream_2_ && send_audio_) {
506 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
507 kStream2);
508 }
509 if (send_stream_2_ && send_video_) {
510 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
511 kStream2);
512 }
513 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
514 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
515 data_channel_->label(),
516 data_channel_->label());
517 }
518 }
519
520 void GetOptionsForOffer(
521 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
522 cricket::MediaSessionOptions* session_options) {
htaa2a49d92016-03-04 02:51:39 -0800523 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700524
deadbeefc80741f2015-10-22 13:14:45 -0700525 AddStreamsToOptions(session_options);
526 if (rtc_options.offer_to_receive_audio ==
527 RTCOfferAnswerOptions::kUndefined) {
528 session_options->recv_audio =
529 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
530 }
531 if (rtc_options.offer_to_receive_video ==
532 RTCOfferAnswerOptions::kUndefined) {
533 session_options->recv_video =
534 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
535 }
536 session_options->bundle_enabled =
537 session_options->bundle_enabled &&
538 (session_options->has_audio() || session_options->has_video() ||
539 session_options->has_data());
540
deadbeefab9b2d12015-10-14 11:33:11 -0700541 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
542 session_options->data_channel_type = cricket::DCT_SCTP;
543 }
544 }
545
htaa2a49d92016-03-04 02:51:39 -0800546 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
547 // ParseConstraintsForAnswer is used to set some defaults.
548 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700549
deadbeefc80741f2015-10-22 13:14:45 -0700550 AddStreamsToOptions(session_options);
551 session_options->bundle_enabled =
552 session_options->bundle_enabled &&
553 (session_options->has_audio() || session_options->has_video() ||
554 session_options->has_data());
555
deadbeefab9b2d12015-10-14 11:33:11 -0700556 if (session_->data_channel_type() == cricket::DCT_SCTP) {
557 session_options->data_channel_type = cricket::DCT_SCTP;
558 }
559 }
560
561 // Creates a local offer and applies it. Starts ICE.
562 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000563 // to decide which streams to create.
564 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000565 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000566 SetLocalDescriptionWithoutError(offer);
567 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
568 observer_.ice_gathering_state_,
569 kIceCandidatesTimeout);
570 }
571
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000572 SessionDescriptionInterface* CreateOffer() {
573 PeerConnectionInterface::RTCOfferAnswerOptions options;
574 options.offer_to_receive_audio =
575 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
576
577 return CreateOffer(options);
578 }
579
wu@webrtc.org91053e72013-08-10 07:18:04 +0000580 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800581 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000582 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000583 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700584 cricket::MediaSessionOptions session_options;
585 GetOptionsForOffer(options, &session_options);
586 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000587 EXPECT_TRUE_WAIT(
588 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000589 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000590 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000591 }
592
593 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800594 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000595 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000596 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800597 cricket::MediaSessionOptions session_options = options;
598 GetOptionsForAnswer(&session_options);
599 // Overwrite recv_audio and recv_video with passed-in values.
600 session_options.recv_video = options.recv_video;
601 session_options.recv_audio = options.recv_audio;
602 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000603 EXPECT_TRUE_WAIT(
604 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000605 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000606 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000607 }
608
htaa2a49d92016-03-04 02:51:39 -0800609 SessionDescriptionInterface* CreateAnswer() {
610 cricket::MediaSessionOptions options;
611 options.recv_video = true;
612 options.recv_audio = true;
613 return CreateAnswer(options);
614 }
615
wu@webrtc.org364f2042013-11-20 21:49:41 +0000616 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000617 return (session_->voice_channel() != NULL &&
618 session_->video_channel() != NULL);
619 }
620
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000621 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
622 ASSERT_TRUE(session_.get() != NULL);
623 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
624 ASSERT_TRUE(content != NULL);
625 const cricket::AudioContentDescription* audio_content =
626 static_cast<const cricket::AudioContentDescription*>(
627 content->description);
628 ASSERT_TRUE(audio_content != NULL);
629 ASSERT_EQ(1U, audio_content->cryptos().size());
630 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
631 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
632 audio_content->cryptos()[0].cipher_suite);
633 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
634 audio_content->protocol());
635
636 content = cricket::GetFirstVideoContent(sdp);
637 ASSERT_TRUE(content != NULL);
638 const cricket::VideoContentDescription* video_content =
639 static_cast<const cricket::VideoContentDescription*>(
640 content->description);
641 ASSERT_TRUE(video_content != NULL);
642 ASSERT_EQ(1U, video_content->cryptos().size());
643 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
644 video_content->cryptos()[0].cipher_suite);
645 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
646 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
647 video_content->protocol());
648 }
649
650 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
651 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
652 ASSERT_TRUE(content != NULL);
653 const cricket::AudioContentDescription* audio_content =
654 static_cast<const cricket::AudioContentDescription*>(
655 content->description);
656 ASSERT_TRUE(audio_content != NULL);
657 ASSERT_EQ(0U, audio_content->cryptos().size());
658
659 content = cricket::GetFirstVideoContent(sdp);
660 ASSERT_TRUE(content != NULL);
661 const cricket::VideoContentDescription* video_content =
662 static_cast<const cricket::VideoContentDescription*>(
663 content->description);
664 ASSERT_TRUE(video_content != NULL);
665 ASSERT_EQ(0U, video_content->cryptos().size());
666
667 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700668 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000669 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700670 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000671 video_content->protocol());
672 } else {
673 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
674 audio_content->protocol());
675 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
676 video_content->protocol());
677 }
678 }
679
680 // Set the internal fake description factories to do DTLS-SRTP.
681 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000682 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000684 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200685 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800686 tdesc_factory_->set_certificate(
687 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
688 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
690 }
691
692 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
693 bool expected) {
694 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
695 ASSERT_TRUE(audio != NULL);
696 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 const TransportInfo* video = sdp->GetTransportInfoByName("video");
698 ASSERT_TRUE(video != NULL);
699 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 }
701
702 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000703 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000705 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000706 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000708 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000710 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
711 offer);
htaa2a49d92016-03-04 02:51:39 -0800712 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 // Answer should be NULL as no crypto params in offer.
714 ASSERT_TRUE(answer == NULL);
715 }
716
717 void VerifyAnswerFromCryptoOffer() {
718 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000719 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000720 options.bundle_enabled = true;
721 scoped_ptr<JsepSessionDescription> offer(
722 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
723 ASSERT_TRUE(offer.get() != NULL);
724 VerifyCryptoParams(offer->description());
725 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -0800726 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727 ASSERT_TRUE(answer.get() != NULL);
728 VerifyCryptoParams(answer->description());
729 }
730
deadbeef0ed85b22016-02-23 17:24:52 -0800731 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
732 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800734 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735 }
736
737 const cricket::ContentInfos& contents = desc1->contents();
738 cricket::ContentInfos::const_iterator it = contents.begin();
739
740 for (; it != contents.end(); ++it) {
741 const cricket::TransportDescription* transport_desc1 =
742 desc1->GetTransportDescriptionByName(it->name);
743 const cricket::TransportDescription* transport_desc2 =
744 desc2->GetTransportDescriptionByName(it->name);
745 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800746 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747 }
748 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
749 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800750 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000751 }
752 }
deadbeef0ed85b22016-02-23 17:24:52 -0800753 return true;
754 }
755
756 // Compares ufrag/password only for the specified |media_type|.
757 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
758 const cricket::SessionDescription* desc2,
759 cricket::MediaType media_type) {
760 if (desc1->contents().size() != desc2->contents().size()) {
761 return false;
762 }
763
764 const cricket::ContentInfo* cinfo =
765 cricket::GetFirstMediaContent(desc1->contents(), media_type);
766 const cricket::TransportDescription* transport_desc1 =
767 desc1->GetTransportDescriptionByName(cinfo->name);
768 const cricket::TransportDescription* transport_desc2 =
769 desc2->GetTransportDescriptionByName(cinfo->name);
770 if (!transport_desc1 || !transport_desc2) {
771 return false;
772 }
773 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
774 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
775 return false;
776 }
777 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000779
780 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
781 std::string *sdp) {
782 const cricket::SessionDescription* desc = current_desc->description();
783 EXPECT_TRUE(current_desc->ToString(sdp));
784
785 const cricket::ContentInfos& contents = desc->contents();
786 cricket::ContentInfos::const_iterator it = contents.begin();
787 // Replace ufrag and pwd lines with empty strings.
788 for (; it != contents.end(); ++it) {
789 const cricket::TransportDescription* transport_desc =
790 desc->GetTransportDescriptionByName(it->name);
791 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
792 + "\r\n";
793 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
794 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000795 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000796 "", 0,
797 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000798 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000799 "", 0,
800 sdp);
801 }
802 }
803
deadbeef0ed85b22016-02-23 17:24:52 -0800804 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
805 const std::string& ufrag,
806 const std::string& pwd) {
807 cricket::SessionDescription* desc = current_desc->description();
808 for (TransportInfo& transport_info : desc->transport_infos()) {
809 cricket::TransportDescription& transport_desc =
810 transport_info.description;
811 transport_desc.ice_ufrag = ufrag;
812 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000813 }
814 }
815
deadbeef0ed85b22016-02-23 17:24:52 -0800816 // Sets ufrag/pwd for specified |media_type|.
817 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
818 cricket::MediaType media_type,
819 const std::string& ufrag,
820 const std::string& pwd) {
821 cricket::SessionDescription* desc = current_desc->description();
822 const cricket::ContentInfo* cinfo =
823 cricket::GetFirstMediaContent(desc->contents(), media_type);
824 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
825 cricket::TransportDescription* transport_desc =
826 &transport_info->description;
827 transport_desc->ice_ufrag = ufrag;
828 transport_desc->ice_pwd = pwd;
829 }
830
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 // Creates a remote offer and and applies it as a remote description,
832 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700833 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 // to decide which local and remote streams to create.
835 void CreateAndSetRemoteOfferAndLocalAnswer() {
836 SessionDescriptionInterface* offer = CreateRemoteOffer();
837 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800838 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 SetLocalDescriptionWithoutError(answer);
840 }
841 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
842 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700843 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 }
845 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700846 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 SetLocalDescriptionWithoutError(desc);
848 EXPECT_EQ(expected_state, session_->state());
849 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000850 void SetLocalDescriptionExpectError(const std::string& action,
851 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 SessionDescriptionInterface* desc) {
853 std::string error;
854 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000855 std::string sdp_type = "local ";
856 sdp_type.append(action);
857 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 EXPECT_NE(std::string::npos, error.find(expected_error));
859 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000860 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
861 SessionDescriptionInterface* desc) {
862 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
863 expected_error, desc);
864 }
865 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
866 SessionDescriptionInterface* desc) {
867 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
868 expected_error, desc);
869 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
871 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
872 }
873 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700874 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 SetRemoteDescriptionWithoutError(desc);
876 EXPECT_EQ(expected_state, session_->state());
877 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000878 void SetRemoteDescriptionExpectError(const std::string& action,
879 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 SessionDescriptionInterface* desc) {
881 std::string error;
882 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000883 std::string sdp_type = "remote ";
884 sdp_type.append(action);
885 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886 EXPECT_NE(std::string::npos, error.find(expected_error));
887 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000888 void SetRemoteDescriptionOfferExpectError(
889 const std::string& expected_error, SessionDescriptionInterface* desc) {
890 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
891 expected_error, desc);
892 }
893 void SetRemoteDescriptionPranswerExpectError(
894 const std::string& expected_error, SessionDescriptionInterface* desc) {
895 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
896 expected_error, desc);
897 }
898 void SetRemoteDescriptionAnswerExpectError(
899 const std::string& expected_error, SessionDescriptionInterface* desc) {
900 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
901 expected_error, desc);
902 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903
904 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
905 SessionDescriptionInterface** nocrypto_answer) {
906 // Create a SDP without Crypto.
907 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000908 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 options.bundle_enabled = true;
910 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
911 ASSERT_TRUE(*offer != NULL);
912 VerifyCryptoParams((*offer)->description());
913
914 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
915 cricket::SEC_DISABLED);
916 EXPECT_TRUE(*nocrypto_answer != NULL);
917 }
918
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000919 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
920 SessionDescriptionInterface** nodtls_answer) {
921 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000922 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000923 options.bundle_enabled = true;
924
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000925 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000926 CreateRemoteOffer(options, cricket::SEC_ENABLED));
927
928 *nodtls_answer =
929 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
930 EXPECT_TRUE(*nodtls_answer != NULL);
931 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
932 VerifyCryptoParams((*nodtls_answer)->description());
933
934 SetFactoryDtlsSrtp();
935 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
936 ASSERT_TRUE(*offer != NULL);
937 VerifyFingerprintStatus((*offer)->description(), true);
938 VerifyCryptoParams((*offer)->description());
939 }
940
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 JsepSessionDescription* CreateRemoteOfferWithVersion(
942 cricket::MediaSessionOptions options,
943 cricket::SecurePolicy secure_policy,
944 const std::string& session_version,
945 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000946 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 const cricket::SessionDescription* cricket_desc = NULL;
948 if (current_desc) {
949 cricket_desc = current_desc->description();
950 session_id = current_desc->session_id();
951 }
952
953 desc_factory_->set_secure(secure_policy);
954 JsepSessionDescription* offer(
955 new JsepSessionDescription(JsepSessionDescription::kOffer));
956 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
957 session_id, session_version)) {
958 delete offer;
959 offer = NULL;
960 }
961 return offer;
962 }
963 JsepSessionDescription* CreateRemoteOffer(
964 cricket::MediaSessionOptions options) {
965 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
966 kSessionVersion, NULL);
967 }
968 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000969 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
970 return CreateRemoteOfferWithVersion(
971 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 }
973 JsepSessionDescription* CreateRemoteOffer(
974 cricket::MediaSessionOptions options,
975 const SessionDescriptionInterface* current_desc) {
976 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
977 kSessionVersion, current_desc);
978 }
979
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000980 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
981 const char* sctp_stream_name, int new_port,
982 cricket::MediaSessionOptions options) {
983 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000984 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
985 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000986 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
987 }
988
989 // Takes ownership of offer_basis (and deletes it).
990 JsepSessionDescription* ChangeSDPSctpPort(
991 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
992 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
993 // SessionDescription from the mutated string.
994 const char* default_port_str = "5000";
995 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000996 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000997 std::string offer_str;
998 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000999 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001000 new_port_str, strlen(new_port_str),
1001 &offer_str);
1002 JsepSessionDescription* offer = new JsepSessionDescription(
1003 offer_basis->type());
1004 delete offer_basis;
1005 offer->Initialize(offer_str, NULL);
1006 return offer;
1007 }
1008
deadbeefab9b2d12015-10-14 11:33:11 -07001009 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010 // before this function to decide which streams to create.
1011 JsepSessionDescription* CreateRemoteOffer() {
1012 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001013 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001014 return CreateRemoteOffer(options, session_->remote_description());
1015 }
1016
1017 JsepSessionDescription* CreateRemoteAnswer(
1018 const SessionDescriptionInterface* offer,
1019 cricket::MediaSessionOptions options,
1020 cricket::SecurePolicy policy) {
1021 desc_factory_->set_secure(policy);
1022 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001023 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001024 JsepSessionDescription* answer(
1025 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1026 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1027 options, NULL),
1028 session_id, kSessionVersion)) {
1029 delete answer;
1030 answer = NULL;
1031 }
1032 return answer;
1033 }
1034
1035 JsepSessionDescription* CreateRemoteAnswer(
1036 const SessionDescriptionInterface* offer,
1037 cricket::MediaSessionOptions options) {
1038 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1039 }
1040
deadbeefab9b2d12015-10-14 11:33:11 -07001041 // Creates an answer session description.
1042 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001043 // to decide which streams to create.
1044 JsepSessionDescription* CreateRemoteAnswer(
1045 const SessionDescriptionInterface* offer) {
1046 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001047 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001048 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1049 }
1050
1051 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001052 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001053 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001054 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001055
1056 PeerConnectionInterface::RTCOfferAnswerOptions options;
1057 options.use_rtp_mux = bundle;
1058
1059 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1061 // and answer.
1062 SetLocalDescriptionWithoutError(offer);
1063
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001064 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001065 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001066 std::string sdp;
1067 EXPECT_TRUE(answer->ToString(&sdp));
1068
1069 size_t expected_candidate_num = 2;
1070 if (!rtcp_mux) {
1071 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1072 // for rtp and rtcp.
1073 expected_candidate_num = 4;
1074 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 const std::string kRtcpMux = "a=rtcp-mux";
1076 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001077 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 kXRtcpMux.c_str(), kXRtcpMux.length(),
1079 &sdp);
1080 }
1081
1082 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1083 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084
1085 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001086 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1088 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001089 if (bundle) {
1090 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1091 } else {
1092 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093 }
1094 }
1095 // Tests that we can only send DTMF when the dtmf codec is supported.
1096 void TestCanInsertDtmf(bool can) {
1097 if (can) {
1098 InitWithDtmfCodec();
1099 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001100 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 }
deadbeefab9b2d12015-10-14 11:33:11 -07001102 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001103 CreateAndSetRemoteOfferAndLocalAnswer();
1104 EXPECT_FALSE(session_->CanInsertDtmf(""));
1105 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1106 }
1107
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001108 // Helper class to configure loopback network and verify Best
1109 // Connection using right IP protocol for TestLoopbackCall
1110 // method. LoopbackNetworkManager applies firewall rules to block
1111 // all ping traffic once ICE completed, and remove them to observe
1112 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1113 // verifies the best connection is using the right IP protocol after
1114 // initial ICE convergences.
1115
1116 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001117 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001118 LoopbackNetworkConfiguration()
1119 : test_ipv6_network_(false),
1120 test_extra_ipv4_network_(false),
1121 best_connection_after_initial_ice_converged_(1, 0) {}
1122
1123 // Used to track the expected best connection count in each IP protocol.
1124 struct ExpectedBestConnection {
1125 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1126 : ipv4_count_(ipv4_count),
1127 ipv6_count_(ipv6_count) {}
1128
1129 int ipv4_count_;
1130 int ipv6_count_;
1131 };
1132
1133 bool test_ipv6_network_;
1134 bool test_extra_ipv4_network_;
1135 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1136
1137 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001138 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001139 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1140 }
1141
1142 private:
jbauchac8869e2015-07-03 01:36:14 -07001143 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001144 const ExpectedBestConnection& expected) const {
1145 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001146 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1147 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001148 expected.ipv4_count_);
1149 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001150 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1151 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001152 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001153 // This is used in the loopback call so there is only single host to host
1154 // candidate pair.
1155 EXPECT_EQ(metrics_observer->GetEnumCounter(
1156 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1157 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001158 0);
1159 EXPECT_EQ(metrics_observer->GetEnumCounter(
1160 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1161 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001162 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001163 }
1164 };
1165
1166 class LoopbackNetworkManager {
1167 public:
1168 LoopbackNetworkManager(WebRtcSessionTest* session,
1169 const LoopbackNetworkConfiguration& config)
1170 : config_(config) {
1171 session->AddInterface(
1172 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1173 if (config_.test_extra_ipv4_network_) {
1174 session->AddInterface(
1175 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1176 }
1177 if (config_.test_ipv6_network_) {
1178 session->AddInterface(
1179 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1180 }
1181 }
1182
1183 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1184 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1185 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1186 if (config_.test_extra_ipv4_network_) {
1187 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1188 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1189 }
1190 if (config_.test_ipv6_network_) {
1191 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1192 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1193 }
1194 }
1195
1196 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1197
1198 private:
1199 LoopbackNetworkConfiguration config_;
1200 };
1201
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001202 // The method sets up a call from the session to itself, in a loopback
1203 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001204 // disconnection, and then a permanent disconnection.
1205 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001206 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1207 // While running the call, this method also checks if the session goes through
1208 // the correct sequence of ICE states when a connection is established,
1209 // broken, and re-established.
1210 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001211 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1212 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001213 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001214
stefanc1aeaf02015-10-15 07:26:07 -07001215 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001216 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001217 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001218 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001219
1220 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1221 observer_.ice_gathering_state_);
1222 SetLocalDescriptionWithoutError(offer);
1223 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1224 observer_.ice_connection_state_);
1225 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001226 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001227 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1228 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001229 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001230
1231 std::string sdp;
1232 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001233 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1234 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 ASSERT_TRUE(desc != NULL);
1236 SetRemoteDescriptionWithoutError(desc);
1237
1238 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001239 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001240
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001241 // The ice connection state is "Connected" too briefly to catch in a test.
1242 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001243 observer_.ice_connection_state_, kIceCandidatesTimeout);
1244 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001245
stefanc1aeaf02015-10-15 07:26:07 -07001246 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1247 LoopbackNetworkManager loopback_network_manager(this, config);
1248 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001249 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001250 // Adding firewall rule to block ping requests, which should cause
1251 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001252
1253 loopback_network_manager.ApplyFirewallRules(fss_.get());
1254
1255 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1257 observer_.ice_connection_state_,
1258 kIceCandidatesTimeout);
1259
jbauchac8869e2015-07-03 01:36:14 -07001260 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001261
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001262 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001263 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001265 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001266 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001267 observer_.ice_connection_state_,
1268 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001269
1270 // Now we block ping requests and wait until the ICE connection transitions
1271 // to the Failed state. This will take at least 30 seconds because it must
1272 // wait for the Port to timeout.
1273 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001274
1275 loopback_network_manager.ApplyFirewallRules(fss_.get());
1276 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001277 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001278 observer_.ice_connection_state_,
1279 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280 }
1281
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001282 void TestLoopbackCall() {
1283 LoopbackNetworkConfiguration config;
1284 TestLoopbackCall(config);
1285 }
1286
stefanc1aeaf02015-10-15 07:26:07 -07001287 void TestPacketOptions() {
1288 media_controller_.reset(
1289 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1290 LoopbackNetworkConfiguration config;
1291 LoopbackNetworkManager loopback_network_manager(this, config);
1292
1293 SetupLoopbackCall();
1294
1295 uint8_t test_packet[15] = {0};
1296 rtc::PacketOptions options;
1297 options.packet_id = 10;
1298 media_engine_->GetVideoChannel(0)
1299 ->SendRtp(test_packet, sizeof(test_packet), options);
1300
1301 const int kPacketTimeout = 2000;
1302 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1303 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1304 }
1305
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1307 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001308 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1309 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1310
1311 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001312 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1313 codecs.push_back(kCNCodec1);
1314 codecs.push_back(kCNCodec2);
1315 media_engine_->SetAudioCodecs(codecs);
1316 desc_factory_->set_audio_codecs(codecs);
1317 }
1318
1319 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1320 const cricket::ContentDescription* description = content->description;
1321 ASSERT(description != NULL);
1322 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001323 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324 ASSERT(audio_content_desc != NULL);
1325 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1326 if (audio_content_desc->codecs()[i].name == "CN")
1327 return false;
1328 }
1329 return true;
1330 }
1331
deadbeefab9b2d12015-10-14 11:33:11 -07001332 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001333 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001334 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001335 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1336 data_channel_ = DataChannel::Create(
1337 session_.get(), session_->data_channel_type(), "datachannel", dci);
1338 }
1339
1340 void SetLocalDescriptionWithDataChannel() {
1341 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001342 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 SetLocalDescriptionWithoutError(offer);
1344 }
1345
wu@webrtc.org91053e72013-08-10 07:18:04 +00001346 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001347 RTCCertificateGenerationMethod cert_gen_method,
1348 CreateSessionDescriptionRequest::Type type) {
1349 InitWithDtls(cert_gen_method);
1350 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1351 }
1352
1353 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1354 CreateSessionDescriptionRequest::Type type) {
1355 InitWithDtlsIdentityGenFail();
1356 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1357 }
1358
1359 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001360 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001361 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001362 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001363 if (type == CreateSessionDescriptionRequest::kAnswer) {
1364 cricket::MediaSessionOptions options;
1365 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001366 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001367 ASSERT_TRUE(offer.get() != NULL);
1368 SetRemoteDescriptionWithoutError(offer.release());
1369 }
1370
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001371 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001372 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001373 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001374 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001375 observers[kNumber];
1376 for (int i = 0; i < kNumber; ++i) {
1377 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1378 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001379 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001380 } else {
htaa2a49d92016-03-04 02:51:39 -08001381 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001382 }
1383 }
1384
1385 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1386 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1387 WebRtcSessionCreateSDPObserverForTest::kFailed;
1388
1389 for (int i = 0; i < kNumber; ++i) {
1390 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1391 if (success) {
1392 EXPECT_TRUE(observers[i]->description() != NULL);
1393 } else {
1394 EXPECT_TRUE(observers[i]->description() == NULL);
1395 }
1396 }
1397 }
1398
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001399 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001400 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001401 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001402 turn_server.credentials = credentials;
1403 turn_server.ports.push_back(
1404 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1405 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001406 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001407 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001408 }
1409
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001410 cricket::FakeMediaEngine* media_engine_;
1411 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001412 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001413 cricket::FakeCall fake_call_;
1414 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001415 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001416 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1417 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1418 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1419 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1420 rtc::SocketServerScope ss_scope_;
1421 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001422 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001423 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001424 rtc::FakeNetworkManager network_manager_;
1425 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001426 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001427 PeerConnectionInterface::RTCConfiguration configuration_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001428 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001429 MockIceObserver observer_;
1430 cricket::FakeVideoMediaChannel* video_channel_;
1431 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001432 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001433 // The following flags affect options created for CreateOffer/CreateAnswer.
1434 bool send_stream_1_ = false;
1435 bool send_stream_2_ = false;
1436 bool send_audio_ = false;
1437 bool send_video_ = false;
1438 rtc::scoped_refptr<DataChannel> data_channel_;
1439 // Last values received from data channel creation signal.
1440 std::string last_data_channel_label_;
1441 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001442 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001443};
1444
Henrik Boström87713d02015-08-25 09:53:21 +02001445TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1446 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001447 // SDES is disabled when DTLS is on.
1448 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001449}
1450
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001451TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001452 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001453 // SDES is required if DTLS is off.
1454 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001455}
1456
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001457TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1458 TestSessionCandidatesWithBundleRtcpMux(false, false);
1459}
1460
1461// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1462// with rtcp-mux and/or bundle.
1463TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1464 TestSessionCandidatesWithBundleRtcpMux(false, true);
1465}
1466
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1468 TestSessionCandidatesWithBundleRtcpMux(true, true);
1469}
1470
1471TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001472 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1473 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001474 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001475 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001476 InitiateCall();
1477 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1478 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1479 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1480}
1481
minyuec8930ba2016-01-22 06:17:46 -08001482// Crashes on Win only. See webrtc:5411.
1483#if defined(WEBRTC_WIN)
1484#define MAYBE_TestStunError DISABLED_TestStunError
1485#else
1486#define MAYBE_TestStunError TestStunError
1487#endif
1488TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001489 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1490 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001491 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001492 rtc::FP_UDP,
1493 rtc::FD_ANY,
1494 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001495 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001496 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001497 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001498 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001499 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1500 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1501 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1502}
1503
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001504// Test session delivers no candidates gathered when constraint set to "none".
1505TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1506 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001507 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001508 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001509 InitiateCall();
1510 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1511 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1512 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1513}
1514
1515// Test session delivers only relay candidates gathered when constaint set to
1516// "relay".
1517TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1518 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1519 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001520 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001521 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001522 InitiateCall();
1523 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1524 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1525 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1526 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1527 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1528 observer_.mline_0_candidates_[i].type());
1529 }
1530 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1531 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1532 observer_.mline_1_candidates_[i].type());
1533 }
1534}
1535
1536// Test session delivers all candidates gathered when constaint set to "all".
1537TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1538 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001539 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001540 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001541 InitiateCall();
1542 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1543 // Host + STUN. By default allocator is disabled to gather relay candidates.
1544 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1545 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1546}
1547
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001548TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001549 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001550 SessionDescriptionInterface* offer = NULL;
1551 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1552 std::string unknown_action;
1553 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1554 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1555}
1556
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001557// Test creating offers and receive answers and make sure the
1558// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001559TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001560 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001561 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001562 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563 const std::string session_id_orig = offer->session_id();
1564 const std::string session_version_orig = offer->session_version();
1565 SetLocalDescriptionWithoutError(offer);
1566
deadbeefab9b2d12015-10-14 11:33:11 -07001567 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568 SessionDescriptionInterface* answer =
1569 CreateRemoteAnswer(session_->local_description());
1570 SetRemoteDescriptionWithoutError(answer);
1571
1572 video_channel_ = media_engine_->GetVideoChannel(0);
1573 voice_channel_ = media_engine_->GetVoiceChannel(0);
1574
1575 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1576 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1577
1578 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1579 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1580
1581 ASSERT_EQ(1u, video_channel_->send_streams().size());
1582 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1583 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1584 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1585
1586 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001587 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001588 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589
1590 // Verify the session id is the same and the session version is
1591 // increased.
1592 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001593 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1594 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595
1596 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001597 EXPECT_EQ(0u, video_channel_->send_streams().size());
1598 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599
deadbeefab9b2d12015-10-14 11:33:11 -07001600 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 answer = CreateRemoteAnswer(session_->local_description());
1602 SetRemoteDescriptionWithoutError(answer);
1603
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 // Make sure the receive streams have not changed.
1605 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1606 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1607 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1608 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1609}
1610
1611// Test receiving offers and creating answers and make sure the
1612// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001613TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001614 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001615 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001616 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001617 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618 SetRemoteDescriptionWithoutError(offer);
1619
deadbeefab9b2d12015-10-14 11:33:11 -07001620 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001621 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001622 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623 SetLocalDescriptionWithoutError(answer);
1624
1625 const std::string session_id_orig = answer->session_id();
1626 const std::string session_version_orig = answer->session_version();
1627
1628 video_channel_ = media_engine_->GetVideoChannel(0);
1629 voice_channel_ = media_engine_->GetVoiceChannel(0);
1630
htaa2a49d92016-03-04 02:51:39 -08001631 ASSERT_TRUE(video_channel_);
1632 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1634 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1635
1636 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1637 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1638
1639 ASSERT_EQ(1u, video_channel_->send_streams().size());
1640 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1641 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1642 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1643
deadbeefab9b2d12015-10-14 11:33:11 -07001644 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001645 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001646 SetRemoteDescriptionWithoutError(offer);
1647
1648 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001649 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001650 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001651
1652 // Verify the session id is the same and the session version is
1653 // increased.
1654 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001655 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1656 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 SetLocalDescriptionWithoutError(answer);
1658
1659 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1660 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1661 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1662 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1663 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1664 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1665
1666 // Make sure we have no send streams.
1667 EXPECT_EQ(0u, video_channel_->send_streams().size());
1668 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1669}
1670
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001671TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001672 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001673 media_engine_->set_fail_create_channel(true);
1674
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001675 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001676 ASSERT_TRUE(offer != NULL);
1677 // SetRemoteDescription and SetLocalDescription will take the ownership of
1678 // the offer.
1679 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001680 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001681 ASSERT_TRUE(offer != NULL);
1682 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1683}
1684
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001685//
1686// Tests for creating/setting SDP under different SDES/DTLS polices:
1687//
1688// --DTLS off and SDES on
1689// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1690// set local/remote offer/answer with crypto --> success
1691// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1692// failure
1693// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1694// failure
1695// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1696// failure
1697//
1698// --DTLS on and SDES off
1699// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1700// set local/remote offer/answer with DTLS fingerprint --> success
1701// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1702// fingerprint --> failure
1703// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1704// --> failure
1705// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1706// --> failure
1707//
1708// --Encryption disabled: DTLS off and SDES off
1709// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1710// answer without SDES or DTLS --> success
1711// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1712// answer without SDES or DTLS --> success
1713//
1714
1715// Test that we return a failure when applying a remote/local offer that doesn't
1716// have cryptos enabled when DTLS is off.
1717TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001718 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001720 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001721 JsepSessionDescription* offer = CreateRemoteOffer(
1722 options, cricket::SEC_DISABLED);
1723 ASSERT_TRUE(offer != NULL);
1724 VerifyNoCryptoParams(offer->description(), false);
1725 // SetRemoteDescription and SetLocalDescription will take the ownership of
1726 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001727 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1729 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001730 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731}
1732
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001733// Test that we return a failure when applying a local answer that doesn't have
1734// cryptos enabled when DTLS is off.
1735TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001736 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 SessionDescriptionInterface* offer = NULL;
1738 SessionDescriptionInterface* answer = NULL;
1739 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1740 // SetRemoteDescription and SetLocalDescription will take the ownership of
1741 // the offer.
1742 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001743 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744}
1745
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001746// Test we will return fail when apply an remote answer that doesn't have
1747// crypto enabled when DTLS is off.
1748TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001749 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750 SessionDescriptionInterface* offer = NULL;
1751 SessionDescriptionInterface* answer = NULL;
1752 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1753 // SetRemoteDescription and SetLocalDescription will take the ownership of
1754 // the offer.
1755 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001756 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757}
1758
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001759// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1760// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001761TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001762 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001763 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001764 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 SetFactoryDtlsSrtp();
1766 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001767 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001768 JsepSessionDescription* offer =
1769 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770 ASSERT_TRUE(offer != NULL);
1771 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001772 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773
1774 // SetRemoteDescription will take the ownership of the offer.
1775 SetRemoteDescriptionWithoutError(offer);
1776
1777 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001778 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779 ASSERT_TRUE(answer != NULL);
1780 VerifyFingerprintStatus(answer->description(), true);
1781 // Check that we don't have an a=crypto line in the answer.
1782 VerifyNoCryptoParams(answer->description(), true);
1783
1784 // Now set the local description, which should work, even without a=crypto.
1785 SetLocalDescriptionWithoutError(answer);
1786}
1787
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001788// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1789// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001790TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001791 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001792 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001793 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001794 SetFactoryDtlsSrtp();
1795
1796 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001797 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001798 ASSERT_TRUE(offer != NULL);
1799 VerifyFingerprintStatus(offer->description(), true);
1800 // Check that we don't have an a=crypto line in the offer.
1801 VerifyNoCryptoParams(offer->description(), true);
1802
1803 // Now set the local description, which should work, even without a=crypto.
1804 SetLocalDescriptionWithoutError(offer);
1805
1806 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001807 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001808 JsepSessionDescription* answer =
1809 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1810 ASSERT_TRUE(answer != NULL);
1811 VerifyFingerprintStatus(answer->description(), true);
1812 VerifyNoCryptoParams(answer->description(), true);
1813
1814 // SetRemoteDescription will take the ownership of the answer.
1815 SetRemoteDescriptionWithoutError(answer);
1816}
1817
1818// Test that if we support DTLS and the other side didn't offer a fingerprint,
1819// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001820TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001821 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001822 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001824 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001825 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826 JsepSessionDescription* offer = CreateRemoteOffer(
1827 options, cricket::SEC_REQUIRED);
1828 ASSERT_TRUE(offer != NULL);
1829 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001830 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001832 // SetRemoteDescription will take the ownership of the offer.
1833 SetRemoteDescriptionOfferExpectError(
1834 kSdpWithoutDtlsFingerprint, offer);
1835
1836 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1837 // SetLocalDescription will take the ownership of the offer.
1838 SetLocalDescriptionOfferExpectError(
1839 kSdpWithoutDtlsFingerprint, offer);
1840}
1841
1842// Test that we return a failure when applying a local answer that doesn't have
1843// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001844TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001845 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001846 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001847 SessionDescriptionInterface* offer = NULL;
1848 SessionDescriptionInterface* answer = NULL;
1849 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1850
1851 // SetRemoteDescription and SetLocalDescription will take the ownership of
1852 // the offer and answer.
1853 SetRemoteDescriptionWithoutError(offer);
1854 SetLocalDescriptionAnswerExpectError(
1855 kSdpWithoutDtlsFingerprint, answer);
1856}
1857
1858// Test that we return a failure when applying a remote answer that doesn't have
1859// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001860TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001861 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001862 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001863 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001864 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001865 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001866 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1867 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001868 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001869 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001870
1871 // SetRemoteDescription and SetLocalDescription will take the ownership of
1872 // the offer and answer.
1873 SetLocalDescriptionWithoutError(offer);
1874 SetRemoteDescriptionAnswerExpectError(
1875 kSdpWithoutDtlsFingerprint, answer);
1876}
1877
1878// Test that we create a local offer without SDES or DTLS and accept a remote
1879// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001880TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001881 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001882 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001883 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001884
1885 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001886 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001887 ASSERT_TRUE(offer != NULL);
1888 VerifyFingerprintStatus(offer->description(), false);
1889 // Check that we don't have an a=crypto line in the offer.
1890 VerifyNoCryptoParams(offer->description(), false);
1891
1892 // Now set the local description, which should work, even without a=crypto.
1893 SetLocalDescriptionWithoutError(offer);
1894
1895 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001896 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001897 JsepSessionDescription* answer =
1898 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1899 ASSERT_TRUE(answer != NULL);
1900 VerifyFingerprintStatus(answer->description(), false);
1901 VerifyNoCryptoParams(answer->description(), false);
1902
1903 // SetRemoteDescription will take the ownership of the answer.
1904 SetRemoteDescriptionWithoutError(answer);
1905}
1906
1907// Test that we create a local answer without SDES or DTLS and accept a remote
1908// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001909TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001910 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001911 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001912
1913 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001914 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001915 JsepSessionDescription* offer =
1916 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1917 ASSERT_TRUE(offer != NULL);
1918 VerifyFingerprintStatus(offer->description(), false);
1919 VerifyNoCryptoParams(offer->description(), false);
1920
1921 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001922 SetRemoteDescriptionWithoutError(offer);
1923
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001924 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001925 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001926 ASSERT_TRUE(answer != NULL);
1927 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001928 // Check that we don't have an a=crypto line in the answer.
1929 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001931 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001932 SetLocalDescriptionWithoutError(answer);
1933}
1934
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001935// Test that we can create and set an answer correctly when different
1936// SSL roles have been negotiated for different transports.
1937// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1938TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1939 SendAudioVideoStream1();
1940 InitWithDtls(GetParam());
1941 SetFactoryDtlsSrtp();
1942
1943 SessionDescriptionInterface* offer = CreateOffer();
1944 SetLocalDescriptionWithoutError(offer);
1945
1946 cricket::MediaSessionOptions options;
1947 options.recv_video = true;
1948
1949 // First, negotiate different SSL roles.
1950 SessionDescriptionInterface* answer =
1951 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1952 TransportInfo* audio_transport_info =
1953 answer->description()->GetTransportInfoByName("audio");
1954 audio_transport_info->description.connection_role =
1955 cricket::CONNECTIONROLE_ACTIVE;
1956 TransportInfo* video_transport_info =
1957 answer->description()->GetTransportInfoByName("video");
1958 video_transport_info->description.connection_role =
1959 cricket::CONNECTIONROLE_PASSIVE;
1960 SetRemoteDescriptionWithoutError(answer);
1961
1962 // Now create an offer in the reverse direction, and ensure the initial
1963 // offerer responds with an answer with correct SSL roles.
1964 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1965 kSessionVersion,
1966 session_->remote_description());
1967 SetRemoteDescriptionWithoutError(offer);
1968
htaa2a49d92016-03-04 02:51:39 -08001969 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001970 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1971 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1972 audio_transport_info->description.connection_role);
1973 video_transport_info = answer->description()->GetTransportInfoByName("video");
1974 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1975 video_transport_info->description.connection_role);
1976 SetLocalDescriptionWithoutError(answer);
1977
1978 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1979 // audio is transferred over to video in the answer that completes the BUNDLE
1980 // negotiation.
1981 options.bundle_enabled = true;
1982 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1983 kSessionVersion,
1984 session_->remote_description());
1985 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08001986 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001987 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1988 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1989 audio_transport_info->description.connection_role);
1990 video_transport_info = answer->description()->GetTransportInfoByName("video");
1991 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1992 video_transport_info->description.connection_role);
1993 SetLocalDescriptionWithoutError(answer);
1994}
1995
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001997 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001998 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002000 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 SetLocalDescriptionWithoutError(offer);
2002
2003 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002004 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 SetLocalDescriptionWithoutError(offer2);
2006}
2007
2008TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002009 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002010 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002012 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013 SetRemoteDescriptionWithoutError(offer);
2014
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002015 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016 SetRemoteDescriptionWithoutError(offer2);
2017}
2018
2019TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002020 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002021 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002022 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002024 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002025 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2026 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027}
2028
2029TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002030 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002031 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002032 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002034 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002035 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002036 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037}
2038
2039TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002040 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002041 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002043 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044
htaa2a49d92016-03-04 02:51:39 -08002045 JsepSessionDescription* pranswer =
2046 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002048 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049
deadbeefab9b2d12015-10-14 11:33:11 -07002050 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002051 JsepSessionDescription* pranswer2 =
2052 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2054
deadbeefd59daf82015-10-14 15:02:44 -07002055 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056
deadbeefab9b2d12015-10-14 11:33:11 -07002057 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002058 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002059 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060}
2061
2062TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002063 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002064 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002065 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002066 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067
2068 JsepSessionDescription* pranswer =
2069 CreateRemoteAnswer(session_->local_description());
2070 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2071
2072 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002073 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074
deadbeefab9b2d12015-10-14 11:33:11 -07002075 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002076 JsepSessionDescription* pranswer2 =
2077 CreateRemoteAnswer(session_->local_description());
2078 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2079
2080 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002081 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082
deadbeefab9b2d12015-10-14 11:33:11 -07002083 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084 SessionDescriptionInterface* answer =
2085 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002086 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087}
2088
2089TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002090 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002091 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002092 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2093
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094 SessionDescriptionInterface* answer =
2095 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002096 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2097 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098}
2099
2100TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002101 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002102 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002103 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2104
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105 SessionDescriptionInterface* answer =
2106 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002107 SetRemoteDescriptionAnswerExpectError(
2108 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109}
2110
2111TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002112 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002113 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114
2115 cricket::Candidate candidate;
2116 candidate.set_component(1);
2117 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2118
deadbeefd59daf82015-10-14 15:02:44 -07002119 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2121
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002122 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002124
2125 // Fail since we have not set a remote description.
2126 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127
2128 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2129 session_->local_description());
2130 SetRemoteDescriptionWithoutError(answer);
2131
deadbeefd59daf82015-10-14 15:02:44 -07002132 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2133 candidate.set_component(2);
2134 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2135 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2136
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137 // Verifying the candidates are copied properly from internal vector.
2138 const SessionDescriptionInterface* remote_desc =
2139 session_->remote_description();
2140 ASSERT_TRUE(remote_desc != NULL);
2141 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2142 const IceCandidateCollection* candidates =
2143 remote_desc->candidates(kMediaContentIndex0);
2144 ASSERT_EQ(2u, candidates->count());
2145 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2146 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2147 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2148 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2149
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002150 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2151 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 candidate.set_component(2);
2153 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2154 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002155 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156
2157 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2158 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2159}
2160
2161// Test that a remote candidate is added to the remote session description and
2162// that it is retained if the remote session description is changed.
2163TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002164 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165 cricket::Candidate candidate1;
2166 candidate1.set_component(1);
2167 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2168 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002169 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 CreateAndSetRemoteOfferAndLocalAnswer();
2171
2172 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2173 const SessionDescriptionInterface* remote_desc =
2174 session_->remote_description();
2175 ASSERT_TRUE(remote_desc != NULL);
2176 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2177 const IceCandidateCollection* candidates =
2178 remote_desc->candidates(kMediaContentIndex0);
2179 ASSERT_EQ(1u, candidates->count());
2180 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2181
2182 // Update the RemoteSessionDescription with a new session description and
2183 // a candidate and check that the new remote session description contains both
2184 // candidates.
2185 SessionDescriptionInterface* offer = CreateRemoteOffer();
2186 cricket::Candidate candidate2;
2187 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2188 candidate2);
2189 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2190 SetRemoteDescriptionWithoutError(offer);
2191
2192 remote_desc = session_->remote_description();
2193 ASSERT_TRUE(remote_desc != NULL);
2194 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2195 candidates = remote_desc->candidates(kMediaContentIndex0);
2196 ASSERT_EQ(2u, candidates->count());
2197 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2198 // Username and password have be updated with the TransportInfo of the
2199 // SessionDescription, won't be equal to the original one.
2200 candidate2.set_username(candidates->at(0)->candidate().username());
2201 candidate2.set_password(candidates->at(0)->candidate().password());
2202 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2203 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2204 // No need to verify the username and password.
2205 candidate1.set_username(candidates->at(1)->candidate().username());
2206 candidate1.set_password(candidates->at(1)->candidate().password());
2207 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2208
2209 // Test that the candidate is ignored if we can add the same candidate again.
2210 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2211}
2212
2213// Test that local candidates are added to the local session description and
2214// that they are retained if the local session description is changed.
2215TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002216 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002217 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002218 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219 CreateAndSetRemoteOfferAndLocalAnswer();
2220
2221 const SessionDescriptionInterface* local_desc = session_->local_description();
2222 const IceCandidateCollection* candidates =
2223 local_desc->candidates(kMediaContentIndex0);
2224 ASSERT_TRUE(candidates != NULL);
2225 EXPECT_EQ(0u, candidates->count());
2226
2227 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2228
2229 local_desc = session_->local_description();
2230 candidates = local_desc->candidates(kMediaContentIndex0);
2231 ASSERT_TRUE(candidates != NULL);
2232 EXPECT_LT(0u, candidates->count());
2233 candidates = local_desc->candidates(1);
2234 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002235 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002236
2237 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002238 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 CreateAndSetRemoteOfferAndLocalAnswer();
2240
2241 local_desc = session_->local_description();
2242 candidates = local_desc->candidates(kMediaContentIndex0);
2243 ASSERT_TRUE(candidates != NULL);
2244 EXPECT_LT(0u, candidates->count());
2245 candidates = local_desc->candidates(1);
2246 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002247 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002248}
2249
2250// Test that we can set a remote session description with remote candidates.
2251TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002252 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253
2254 cricket::Candidate candidate1;
2255 candidate1.set_component(1);
2256 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2257 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002258 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002259 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260
2261 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2262 SetRemoteDescriptionWithoutError(offer);
2263
2264 const SessionDescriptionInterface* remote_desc =
2265 session_->remote_description();
2266 ASSERT_TRUE(remote_desc != NULL);
2267 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2268 const IceCandidateCollection* candidates =
2269 remote_desc->candidates(kMediaContentIndex0);
2270 ASSERT_EQ(1u, candidates->count());
2271 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2272
htaa2a49d92016-03-04 02:51:39 -08002273 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274 SetLocalDescriptionWithoutError(answer);
2275}
2276
2277// Test that offers and answers contains ice candidates when Ice candidates have
2278// been gathered.
2279TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002280 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002281 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002282 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 // Ice is started but candidates are not provided until SetLocalDescription
2284 // is called.
2285 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2286 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2287 CreateAndSetRemoteOfferAndLocalAnswer();
2288 // Wait until at least one local candidate has been collected.
2289 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2290 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002292 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2293
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2295 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002296
2297 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2298 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002299 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2301 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302 SetLocalDescriptionWithoutError(answer);
2303}
2304
2305// Verifies TransportProxy and media channels are created with content names
2306// present in the SessionDescription.
2307TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002308 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002309 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002310 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311
2312 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002313 // "video". Goal is to modify these content names and verify transport
2314 // channels
2315 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 // present in SDP.
2317 std::string sdp;
2318 EXPECT_TRUE(offer->ToString(&sdp));
2319 const std::string kAudioMid = "a=mid:audio";
2320 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2321 const std::string kVideoMid = "a=mid:video";
2322 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2323
2324 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002325 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 kAudioMidReplaceStr.c_str(),
2327 kAudioMidReplaceStr.length(),
2328 &sdp);
2329 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002330 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331 kVideoMidReplaceStr.c_str(),
2332 kVideoMidReplaceStr.length(),
2333 &sdp);
2334
2335 SessionDescriptionInterface* modified_offer =
2336 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2337
2338 SetRemoteDescriptionWithoutError(modified_offer);
2339
htaa2a49d92016-03-04 02:51:39 -08002340 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341 SetLocalDescriptionWithoutError(answer);
2342
deadbeefcbecd352015-09-23 11:50:27 -07002343 cricket::TransportChannel* voice_transport_channel =
2344 session_->voice_rtp_transport_channel();
2345 EXPECT_TRUE(voice_transport_channel != NULL);
2346 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2347 cricket::TransportChannel* video_transport_channel =
2348 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002349 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002350 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2352 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2353}
2354
2355// Test that an offer contains the correct media content descriptions based on
2356// the send streams when no constraints have been set.
2357TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002358 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002359 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2360
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 ASSERT_TRUE(offer != NULL);
2362 const cricket::ContentInfo* content =
2363 cricket::GetFirstAudioContent(offer->description());
2364 EXPECT_TRUE(content != NULL);
2365 content = cricket::GetFirstVideoContent(offer->description());
2366 EXPECT_TRUE(content == NULL);
2367}
2368
2369// Test that an offer contains the correct media content descriptions based on
2370// the send streams when no constraints have been set.
2371TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002372 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002374 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002375 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2376
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 const cricket::ContentInfo* content =
2378 cricket::GetFirstAudioContent(offer->description());
2379 EXPECT_TRUE(content != NULL);
2380 content = cricket::GetFirstVideoContent(offer->description());
2381 EXPECT_TRUE(content == NULL);
2382
2383 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002384 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002385 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386 content = cricket::GetFirstAudioContent(offer->description());
2387 EXPECT_TRUE(content != NULL);
2388 content = cricket::GetFirstVideoContent(offer->description());
2389 EXPECT_TRUE(content != NULL);
2390}
2391
2392// Test that an offer contains no media content descriptions if
2393// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2394TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002395 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002396 PeerConnectionInterface::RTCOfferAnswerOptions options;
2397 options.offer_to_receive_audio = 0;
2398 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002400 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002401 CreateOffer(options));
2402
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403 ASSERT_TRUE(offer != NULL);
2404 const cricket::ContentInfo* content =
2405 cricket::GetFirstAudioContent(offer->description());
2406 EXPECT_TRUE(content == NULL);
2407 content = cricket::GetFirstVideoContent(offer->description());
2408 EXPECT_TRUE(content == NULL);
2409}
2410
2411// Test that an offer contains only audio media content descriptions if
2412// kOfferToReceiveAudio constraints are set to true.
2413TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002414 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002415 PeerConnectionInterface::RTCOfferAnswerOptions options;
2416 options.offer_to_receive_audio =
2417 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2418
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002419 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002420 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002421
2422 const cricket::ContentInfo* content =
2423 cricket::GetFirstAudioContent(offer->description());
2424 EXPECT_TRUE(content != NULL);
2425 content = cricket::GetFirstVideoContent(offer->description());
2426 EXPECT_TRUE(content == NULL);
2427}
2428
2429// Test that an offer contains audio and video media content descriptions if
2430// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2431TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002432 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002434 PeerConnectionInterface::RTCOfferAnswerOptions options;
2435 options.offer_to_receive_audio =
2436 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2437 options.offer_to_receive_video =
2438 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2439
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002440 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002441 CreateOffer(options));
2442
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002443 const cricket::ContentInfo* content =
2444 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002445 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002446
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447 content = cricket::GetFirstVideoContent(offer->description());
2448 EXPECT_TRUE(content != NULL);
2449
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002450 // Sets constraints to false and verifies that audio/video contents are
2451 // removed.
2452 options.offer_to_receive_audio = 0;
2453 options.offer_to_receive_video = 0;
2454 offer.reset(CreateOffer(options));
2455
2456 content = cricket::GetFirstAudioContent(offer->description());
2457 EXPECT_TRUE(content == NULL);
2458 content = cricket::GetFirstVideoContent(offer->description());
2459 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460}
2461
2462// Test that an answer can not be created if the last remote description is not
2463// an offer.
2464TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002465 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002466 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002467 SetLocalDescriptionWithoutError(offer);
2468 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2469 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002470 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471}
2472
2473// Test that an answer contains the correct media content descriptions when no
2474// constraints have been set.
2475TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002476 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002478 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002479 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -08002480 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481 const cricket::ContentInfo* content =
2482 cricket::GetFirstAudioContent(answer->description());
2483 ASSERT_TRUE(content != NULL);
2484 EXPECT_FALSE(content->rejected);
2485
2486 content = cricket::GetFirstVideoContent(answer->description());
2487 ASSERT_TRUE(content != NULL);
2488 EXPECT_FALSE(content->rejected);
2489}
2490
2491// Test that an answer contains the correct media content descriptions when no
2492// constraints have been set and the offer only contain audio.
2493TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002494 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495 // Create a remote offer with audio only.
2496 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002497
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002498 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002499 CreateRemoteOffer(options));
2500 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2501 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2502
2503 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -08002504 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002505 const cricket::ContentInfo* content =
2506 cricket::GetFirstAudioContent(answer->description());
2507 ASSERT_TRUE(content != NULL);
2508 EXPECT_FALSE(content->rejected);
2509
2510 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2511}
2512
2513// Test that an answer contains the correct media content descriptions when no
2514// constraints have been set.
2515TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002516 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002517 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002518 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002519 SetRemoteDescriptionWithoutError(offer.release());
2520 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002521 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002522 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002523 const cricket::ContentInfo* content =
2524 cricket::GetFirstAudioContent(answer->description());
2525 ASSERT_TRUE(content != NULL);
2526 EXPECT_FALSE(content->rejected);
2527
2528 content = cricket::GetFirstVideoContent(answer->description());
2529 ASSERT_TRUE(content != NULL);
2530 EXPECT_FALSE(content->rejected);
2531}
2532
2533// Test that an answer contains the correct media content descriptions when
2534// constraints have been set but no stream is sent.
2535TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002536 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002537 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002538 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539 SetRemoteDescriptionWithoutError(offer.release());
2540
htaa2a49d92016-03-04 02:51:39 -08002541 cricket::MediaSessionOptions session_options;
2542 session_options.recv_audio = false;
2543 session_options.recv_video = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002544 rtc::scoped_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002545 CreateAnswer(session_options));
2546
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547 const cricket::ContentInfo* content =
2548 cricket::GetFirstAudioContent(answer->description());
2549 ASSERT_TRUE(content != NULL);
2550 EXPECT_TRUE(content->rejected);
2551
2552 content = cricket::GetFirstVideoContent(answer->description());
2553 ASSERT_TRUE(content != NULL);
2554 EXPECT_TRUE(content->rejected);
2555}
2556
2557// Test that an answer contains the correct media content descriptions when
2558// constraints have been set and streams are sent.
2559TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002560 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002561 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002562 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002563 SetRemoteDescriptionWithoutError(offer.release());
2564
htaa2a49d92016-03-04 02:51:39 -08002565 cricket::MediaSessionOptions options;
2566 options.recv_audio = false;
2567 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002568
2569 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002570 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002571 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002572
2573 // TODO(perkj): Should the direction be set to SEND_ONLY?
2574 const cricket::ContentInfo* content =
2575 cricket::GetFirstAudioContent(answer->description());
2576 ASSERT_TRUE(content != NULL);
2577 EXPECT_FALSE(content->rejected);
2578
2579 // TODO(perkj): Should the direction be set to SEND_ONLY?
2580 content = cricket::GetFirstVideoContent(answer->description());
2581 ASSERT_TRUE(content != NULL);
2582 EXPECT_FALSE(content->rejected);
2583}
2584
2585TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2586 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002587 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002588 PeerConnectionInterface::RTCOfferAnswerOptions options;
2589 options.offer_to_receive_audio =
2590 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2591 options.voice_activity_detection = false;
2592
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002593 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002594 CreateOffer(options));
2595
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002596 const cricket::ContentInfo* content =
2597 cricket::GetFirstAudioContent(offer->description());
2598 EXPECT_TRUE(content != NULL);
2599 EXPECT_TRUE(VerifyNoCNCodecs(content));
2600}
2601
2602TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2603 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002604 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002605 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002606 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002607 SetRemoteDescriptionWithoutError(offer.release());
2608
htaa2a49d92016-03-04 02:51:39 -08002609 cricket::MediaSessionOptions options;
2610 options.vad_enabled = false;
2611 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002612 const cricket::ContentInfo* content =
2613 cricket::GetFirstAudioContent(answer->description());
2614 ASSERT_TRUE(content != NULL);
2615 EXPECT_TRUE(VerifyNoCNCodecs(content));
2616}
2617
2618// This test verifies the call setup when remote answer with audio only and
2619// later updates with video.
2620TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002621 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002622 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2623 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2624
deadbeefab9b2d12015-10-14 11:33:11 -07002625 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002626 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002627
2628 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002629 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2630
2631 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2632 // and answer;
2633 SetLocalDescriptionWithoutError(offer);
2634 SetRemoteDescriptionWithoutError(answer);
2635
2636 video_channel_ = media_engine_->GetVideoChannel(0);
2637 voice_channel_ = media_engine_->GetVoiceChannel(0);
2638
2639 ASSERT_TRUE(video_channel_ == NULL);
2640
2641 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2642 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2643 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2644
2645 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002646 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002647 CreateAndSetRemoteOfferAndLocalAnswer();
2648
2649 video_channel_ = media_engine_->GetVideoChannel(0);
2650 voice_channel_ = media_engine_->GetVoiceChannel(0);
2651
2652 ASSERT_TRUE(video_channel_ != NULL);
2653 ASSERT_TRUE(voice_channel_ != NULL);
2654
2655 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2656 ASSERT_EQ(1u, video_channel_->send_streams().size());
2657 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2658 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2659 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2660 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2661 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2662 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2663
2664 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002665 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002666 CreateAndSetRemoteOfferAndLocalAnswer();
2667
2668 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2669 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2670 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2671 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2672 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2673}
2674
2675// This test verifies the call setup when remote answer with video only and
2676// later updates with audio.
2677TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002678 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002679 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2680 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002681 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002682 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002683
2684 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002685 options.recv_audio = false;
2686 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002687 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2688 offer, options, cricket::SEC_ENABLED);
2689
2690 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2691 // and answer.
2692 SetLocalDescriptionWithoutError(offer);
2693 SetRemoteDescriptionWithoutError(answer);
2694
2695 video_channel_ = media_engine_->GetVideoChannel(0);
2696 voice_channel_ = media_engine_->GetVoiceChannel(0);
2697
2698 ASSERT_TRUE(voice_channel_ == NULL);
2699 ASSERT_TRUE(video_channel_ != NULL);
2700
2701 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2702 ASSERT_EQ(1u, video_channel_->send_streams().size());
2703 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2704
2705 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002706 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002707 CreateAndSetRemoteOfferAndLocalAnswer();
2708
2709 voice_channel_ = media_engine_->GetVoiceChannel(0);
2710 ASSERT_TRUE(voice_channel_ != NULL);
2711
2712 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2713 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2714 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2715 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2716
2717 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002718 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002719 CreateAndSetRemoteOfferAndLocalAnswer();
2720
2721 video_channel_ = media_engine_->GetVideoChannel(0);
2722 voice_channel_ = media_engine_->GetVoiceChannel(0);
2723
2724 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2725 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2726 ASSERT_EQ(1u, video_channel_->send_streams().size());
2727 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2728}
2729
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002730TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002731 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002732 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002733 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002734 VerifyCryptoParams(offer->description());
2735 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -08002736 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002737 VerifyCryptoParams(answer->description());
2738}
2739
2740TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002741 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002742 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002743 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002744 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002745 VerifyNoCryptoParams(offer->description(), false);
2746}
2747
2748TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002749 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002750 VerifyAnswerFromNonCryptoOffer();
2751}
2752
2753TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002754 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002755 VerifyAnswerFromCryptoOffer();
2756}
2757
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002758// This test verifies that setLocalDescription fails if
2759// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2760TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002761 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002762 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002763 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2764
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002765 std::string sdp;
2766 RemoveIceUfragPwdLines(offer.get(), &sdp);
2767 SessionDescriptionInterface* modified_offer =
2768 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002769 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002770}
2771
2772// This test verifies that setRemoteDescription fails if
2773// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2774TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002775 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002776 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002777 std::string sdp;
2778 RemoveIceUfragPwdLines(offer.get(), &sdp);
2779 SessionDescriptionInterface* modified_offer =
2780 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002781 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002782}
2783
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002784// This test verifies that setLocalDescription fails if local offer has
2785// too short ice ufrag and pwd strings.
2786TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002787 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002788 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002789 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002790 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2791 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002792 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002793 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002794 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002795
2796 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002797 offer.reset(CreateOffer());
2798 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2799 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002800}
2801
2802// This test verifies that setRemoteDescription fails if remote offer has
2803// too short ice ufrag and pwd strings.
2804TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002805 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002806 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002807 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2808 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002809 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002810 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002811 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002812
deadbeef0ed85b22016-02-23 17:24:52 -08002813 offer.reset(CreateRemoteOffer());
2814 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2815 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002816}
2817
Honghai Zhang04e91462015-12-11 14:26:22 -08002818// Test that if the remote offer indicates the peer requested ICE restart (via
2819// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2820TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002821 Init();
honghaiz503726c2015-07-31 12:37:38 -07002822
2823 // Create the first offer.
deadbeef0ed85b22016-02-23 17:24:52 -08002824 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2825 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002826 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2827 0, "", "", "relay", 0, "");
2828 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2829 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002830 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2831 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002832 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2833
2834 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002835 offer.reset(CreateRemoteOffer());
2836 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002837 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2838 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2839 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002840 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2841 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002842 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2843
2844 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002845 offer.reset(CreateRemoteOffer());
2846 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002847 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2848 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2849 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002850 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2851 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002852 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2853
2854 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002855 offer.reset(CreateRemoteOffer());
2856 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2857 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002858 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2859}
2860
Honghai Zhang04e91462015-12-11 14:26:22 -08002861// Test that if the remote answer indicates the peer requested ICE restart (via
2862// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2863TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2864 Init();
2865 SessionDescriptionInterface* offer = CreateOffer();
2866 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002867
2868 // Create the first answer.
deadbeef0ed85b22016-02-23 17:24:52 -08002869 scoped_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
2870 answer->set_type(JsepSessionDescription::kPrAnswer);
2871 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002872 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2873 0, "", "", "relay", 0, "");
2874 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2875 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002876 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2877 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002878 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2879
2880 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002881 answer.reset(CreateRemoteAnswer(offer));
2882 answer->set_type(JsepSessionDescription::kPrAnswer);
2883 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002884 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2885 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2886 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002887 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2888 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002889 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2890
2891 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002892 answer.reset(CreateRemoteAnswer(offer));
2893 answer->set_type(JsepSessionDescription::kPrAnswer);
2894 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002895 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2896 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2897 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002898 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2899 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002900 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2901
2902 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002903 answer.reset(CreateRemoteAnswer(offer));
2904 answer->set_type(JsepSessionDescription::kPrAnswer);
2905 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2906 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002907 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2908}
2909
Donald Curtisd4f769d2015-05-28 09:48:21 -07002910// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002911// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002912TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2913 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2914
2915 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002916 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002917
2918 PeerConnectionInterface::RTCOfferAnswerOptions options;
2919 options.use_rtp_mux = true;
2920
2921 SessionDescriptionInterface* offer = CreateRemoteOffer();
2922 SetRemoteDescriptionWithoutError(offer);
2923
htaa2a49d92016-03-04 02:51:39 -08002924 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002925 SetLocalDescriptionWithoutError(answer);
2926
deadbeefcbecd352015-09-23 11:50:27 -07002927 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2928 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002929
deadbeefcbecd352015-09-23 11:50:27 -07002930 cricket::BaseChannel* voice_channel = session_->voice_channel();
2931 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002932
2933 // Checks if one of the transport channels contains a connection using a given
2934 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002935 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002936 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002937 session_->GetChannelTransportStats(voice_channel, &stats);
2938 for (auto& kv : stats.transport_stats) {
2939 for (auto& chan_stat : kv.second.channel_stats) {
2940 for (auto& conn_info : chan_stat.connection_infos) {
2941 if (conn_info.remote_candidate.address().port() == port) {
2942 return true;
2943 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002944 }
2945 }
2946 }
2947 return false;
2948 };
2949
2950 EXPECT_FALSE(connection_with_remote_port(5000));
2951 EXPECT_FALSE(connection_with_remote_port(5001));
2952 EXPECT_FALSE(connection_with_remote_port(6000));
2953
2954 // The way the *_WAIT checks work is they only wait if the condition fails,
2955 // which does not help in the case where state is not changing. This is
2956 // problematic in this test since we want to verify that adding a video
2957 // candidate does _not_ change state. So we interleave candidates and assume
2958 // that messages are executed in the order they were posted.
2959
2960 // First audio candidate.
2961 cricket::Candidate candidate0;
2962 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2963 candidate0.set_component(1);
2964 candidate0.set_protocol("udp");
2965 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2966 candidate0);
2967 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2968
2969 // Video candidate.
2970 cricket::Candidate candidate1;
2971 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2972 candidate1.set_component(1);
2973 candidate1.set_protocol("udp");
2974 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2975 candidate1);
2976 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2977
2978 // Second audio candidate.
2979 cricket::Candidate candidate2;
2980 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2981 candidate2.set_component(1);
2982 candidate2.set_protocol("udp");
2983 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2984 candidate2);
2985 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2986
2987 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2988 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2989
2990 // No need here for a _WAIT check since we are checking that state hasn't
2991 // changed: if this is false we would be doing waits for nothing and if this
2992 // is true then there will be no messages processed anyways.
2993 EXPECT_FALSE(connection_with_remote_port(6000));
2994}
2995
deadbeefcbecd352015-09-23 11:50:27 -07002996// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002997TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2998 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002999 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003000
3001 PeerConnectionInterface::RTCOfferAnswerOptions options;
3002 options.use_rtp_mux = true;
3003
3004 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003005 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003006
deadbeefcbecd352015-09-23 11:50:27 -07003007 EXPECT_NE(session_->voice_rtp_transport_channel(),
3008 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003009
deadbeefab9b2d12015-10-14 11:33:11 -07003010 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003011 SessionDescriptionInterface* answer =
3012 CreateRemoteAnswer(session_->local_description());
3013 SetRemoteDescriptionWithoutError(answer);
3014
deadbeefcbecd352015-09-23 11:50:27 -07003015 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3016 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003017}
3018
deadbeefcbecd352015-09-23 11:50:27 -07003019// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003020TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3021 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003022 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003023
Donald Curtis0e209b02015-03-24 09:29:54 -07003024 PeerConnectionInterface::RTCOfferAnswerOptions options;
3025 options.use_rtp_mux = true;
3026
3027 SessionDescriptionInterface* offer = CreateOffer(options);
3028 SetLocalDescriptionWithoutError(offer);
3029
deadbeefcbecd352015-09-23 11:50:27 -07003030 EXPECT_NE(session_->voice_rtp_transport_channel(),
3031 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003032
deadbeefab9b2d12015-10-14 11:33:11 -07003033 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003034
3035 // Remove BUNDLE from the answer.
3036 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3037 CreateRemoteAnswer(session_->local_description()));
3038 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3039 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3040 JsepSessionDescription* modified_answer =
3041 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3042 modified_answer->Initialize(answer_copy, "1", "1");
3043 SetRemoteDescriptionWithoutError(modified_answer); //
3044
deadbeefcbecd352015-09-23 11:50:27 -07003045 EXPECT_NE(session_->voice_rtp_transport_channel(),
3046 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003047}
3048
3049// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3050TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3051 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003052 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003053
3054 PeerConnectionInterface::RTCOfferAnswerOptions options;
3055 options.use_rtp_mux = true;
3056
3057 SessionDescriptionInterface* offer = CreateOffer(options);
3058 SetLocalDescriptionWithoutError(offer);
3059
deadbeefcbecd352015-09-23 11:50:27 -07003060 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3061 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003062
deadbeefab9b2d12015-10-14 11:33:11 -07003063 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003064 SessionDescriptionInterface* answer =
3065 CreateRemoteAnswer(session_->local_description());
3066 SetRemoteDescriptionWithoutError(answer);
3067
deadbeefcbecd352015-09-23 11:50:27 -07003068 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3069 session_->video_rtp_transport_channel());
3070}
3071
3072// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3073// audio content in the answer.
3074TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3075 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003076 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003077
3078 PeerConnectionInterface::RTCOfferAnswerOptions options;
3079 options.use_rtp_mux = true;
3080
3081 SessionDescriptionInterface* offer = CreateOffer(options);
3082 SetLocalDescriptionWithoutError(offer);
3083
3084 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3085 session_->video_rtp_transport_channel());
3086
deadbeefab9b2d12015-10-14 11:33:11 -07003087 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003088 cricket::MediaSessionOptions recv_options;
3089 recv_options.recv_audio = false;
3090 recv_options.recv_video = true;
3091 SessionDescriptionInterface* answer =
3092 CreateRemoteAnswer(session_->local_description(), recv_options);
3093 SetRemoteDescriptionWithoutError(answer);
3094
deadbeefd59daf82015-10-14 15:02:44 -07003095 EXPECT_TRUE(nullptr == session_->voice_channel());
3096 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003097
deadbeefd59daf82015-10-14 15:02:44 -07003098 session_->Close();
3099 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3100 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3101 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3102 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003103}
3104
3105// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3106TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3107 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003108 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003109
Donald Curtis0e209b02015-03-24 09:29:54 -07003110 PeerConnectionInterface::RTCOfferAnswerOptions options;
3111 options.use_rtp_mux = true;
3112
3113 SessionDescriptionInterface* offer = CreateOffer(options);
3114 SetLocalDescriptionWithoutError(offer);
3115
deadbeefcbecd352015-09-23 11:50:27 -07003116 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3117 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003118
deadbeefab9b2d12015-10-14 11:33:11 -07003119 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003120
3121 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003122 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003123 CreateRemoteAnswer(session_->local_description()));
3124 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3125 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3126 JsepSessionDescription* modified_answer =
3127 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3128 modified_answer->Initialize(answer_copy, "1", "1");
3129 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003130
deadbeefcbecd352015-09-23 11:50:27 -07003131 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3132 session_->video_rtp_transport_channel());
3133}
3134
3135// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3136TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3137 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003138 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003139
3140 SessionDescriptionInterface* offer = CreateRemoteOffer();
3141 SetRemoteDescriptionWithoutError(offer);
3142
3143 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3144 session_->video_rtp_transport_channel());
3145
deadbeefab9b2d12015-10-14 11:33:11 -07003146 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003147 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003148 SetLocalDescriptionWithoutError(answer);
3149
3150 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3151 session_->video_rtp_transport_channel());
3152}
3153
3154// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3155TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3156 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003157 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003158
3159 // Remove BUNDLE from the offer.
3160 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3161 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3162 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3163 JsepSessionDescription* modified_offer =
3164 new JsepSessionDescription(JsepSessionDescription::kOffer);
3165 modified_offer->Initialize(offer_copy, "1", "1");
3166
3167 // Expect an error when applying the remote description
3168 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3169 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003170}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003171
Peter Thatcher4eddf182015-04-30 10:55:59 -07003172// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003173TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3174 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003175 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003176
Donald Curtis0e209b02015-03-24 09:29:54 -07003177 PeerConnectionInterface::RTCOfferAnswerOptions options;
3178 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003179
Donald Curtis0e209b02015-03-24 09:29:54 -07003180 SessionDescriptionInterface* offer = CreateOffer(options);
3181 SetLocalDescriptionWithoutError(offer);
3182
deadbeefcbecd352015-09-23 11:50:27 -07003183 EXPECT_NE(session_->voice_rtp_transport_channel(),
3184 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003185
deadbeefab9b2d12015-10-14 11:33:11 -07003186 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003187 SessionDescriptionInterface* answer =
3188 CreateRemoteAnswer(session_->local_description());
3189 SetRemoteDescriptionWithoutError(answer);
3190
3191 // This should lead to an audio-only call but isn't implemented
3192 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003193 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3194 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003195}
3196
deadbeefcbecd352015-09-23 11:50:27 -07003197// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003198TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3199 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003200 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003201 PeerConnectionInterface::RTCOfferAnswerOptions options;
3202 options.use_rtp_mux = true;
3203
3204 SessionDescriptionInterface* offer = CreateOffer(options);
3205 SetLocalDescriptionWithoutError(offer);
3206
deadbeefcbecd352015-09-23 11:50:27 -07003207 EXPECT_NE(session_->voice_rtp_transport_channel(),
3208 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003209
deadbeefab9b2d12015-10-14 11:33:11 -07003210 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003211
3212 // Remove BUNDLE from the answer.
3213 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3214 CreateRemoteAnswer(session_->local_description()));
3215 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3216 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3217 JsepSessionDescription* modified_answer =
3218 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3219 modified_answer->Initialize(answer_copy, "1", "1");
3220 SetRemoteDescriptionWithoutError(modified_answer); //
3221
deadbeefcbecd352015-09-23 11:50:27 -07003222 EXPECT_NE(session_->voice_rtp_transport_channel(),
3223 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003224}
3225
Peter Thatcher4eddf182015-04-30 10:55:59 -07003226// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3227TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3228 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003229 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003230
3231 PeerConnectionInterface::RTCOfferAnswerOptions options;
3232 options.use_rtp_mux = true;
3233
3234 SessionDescriptionInterface* offer = CreateOffer(options);
3235 SetRemoteDescriptionWithoutError(offer);
3236
deadbeefcbecd352015-09-23 11:50:27 -07003237 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3238 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003239}
3240
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003241TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3242 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003243 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003244
3245 PeerConnectionInterface::RTCOfferAnswerOptions options;
3246 SessionDescriptionInterface* offer = CreateOffer(options);
3247 SetLocalDescriptionWithoutError(offer);
3248
deadbeefcbecd352015-09-23 11:50:27 -07003249 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3250 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003251
deadbeefab9b2d12015-10-14 11:33:11 -07003252 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003253 SessionDescriptionInterface* answer =
3254 CreateRemoteAnswer(session_->local_description());
3255 SetRemoteDescriptionWithoutError(answer);
3256
deadbeefcbecd352015-09-23 11:50:27 -07003257 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3258 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003259}
3260
3261TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3262 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003263 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003264
3265 PeerConnectionInterface::RTCOfferAnswerOptions options;
3266 SessionDescriptionInterface* offer = CreateOffer(options);
3267 SetLocalDescriptionWithoutError(offer);
3268
deadbeefcbecd352015-09-23 11:50:27 -07003269 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3270 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003271
deadbeefab9b2d12015-10-14 11:33:11 -07003272 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003273 SessionDescriptionInterface* answer =
3274 CreateRemoteAnswer(session_->local_description());
3275 SetRemoteDescriptionWithoutError(answer);
3276
deadbeefcbecd352015-09-23 11:50:27 -07003277 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3278 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003279}
3280
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003281// This test verifies that SetLocalDescription and SetRemoteDescription fails
3282// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3283TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003284 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003285 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003286
3287 PeerConnectionInterface::RTCOfferAnswerOptions options;
3288 options.use_rtp_mux = true;
3289
3290 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003291 std::string offer_str;
3292 offer->ToString(&offer_str);
3293 // Disable rtcp-mux
3294 const std::string rtcp_mux = "rtcp-mux";
3295 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003296 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003297 xrtcp_mux.c_str(), xrtcp_mux.length(),
3298 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003299 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003300 new JsepSessionDescription(JsepSessionDescription::kOffer);
3301 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003302 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003303 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003304 new JsepSessionDescription(JsepSessionDescription::kOffer);
3305 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003306 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003307 // Trying unmodified SDP.
3308 SetLocalDescriptionWithoutError(offer);
3309}
3310
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003311TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003312 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003313 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003314 CreateAndSetRemoteOfferAndLocalAnswer();
3315 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3316 ASSERT_TRUE(channel != NULL);
3317 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003318 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003319 double volume;
3320 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3321 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003322 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003323 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3324 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003325 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003326 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3327 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003328}
3329
3330TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003331 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003332 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003333 CreateAndSetRemoteOfferAndLocalAnswer();
3334 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3335 ASSERT_TRUE(channel != NULL);
3336 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003337 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003338 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3339
3340 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003341 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003342
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003343 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003344 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003345 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003346 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003347 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003348
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003349 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003350 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003351 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003352 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003353 EXPECT_TRUE(renderer->sink() == NULL);
3354}
3355
3356TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003357 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003358 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003359 CreateAndSetRemoteOfferAndLocalAnswer();
3360 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3361 ASSERT_TRUE(channel != NULL);
3362 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003363 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003364
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003365 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003366 cricket::AudioOptions options;
3367 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3368 EXPECT_TRUE(renderer->sink() != NULL);
3369
3370 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3371 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3372 // SetSink(NULL) callback afterwards.
3373 renderer.reset();
3374
3375 // This will trigger SetSink(NULL) if no OnClose() callback.
3376 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003377}
3378
3379TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003380 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003381 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003382 CreateAndSetRemoteOfferAndLocalAnswer();
3383 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3384 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003385 ASSERT_LT(0u, channel->sinks().size());
3386 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003387 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003388 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003389 cricket::FakeVideoRenderer renderer;
3390 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003391 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003392 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003393 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003394}
3395
3396TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003397 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003398 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003399 CreateAndSetRemoteOfferAndLocalAnswer();
3400 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3401 ASSERT_TRUE(channel != NULL);
3402 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003403 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003404 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3405 cricket::VideoOptions* options = NULL;
3406 session_->SetVideoSend(send_ssrc, false, options);
3407 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3408 session_->SetVideoSend(send_ssrc, true, options);
3409 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3410}
3411
3412TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3413 TestCanInsertDtmf(false);
3414}
3415
3416TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3417 TestCanInsertDtmf(true);
3418}
3419
3420TEST_F(WebRtcSessionTest, InsertDtmf) {
3421 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003422 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003423 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003424 CreateAndSetRemoteOfferAndLocalAnswer();
3425 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3426 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3427
3428 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003429 const int expected_duration = 90;
3430 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3431 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3432 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3433
3434 // Verify
3435 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003436 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003437 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
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()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003440 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003441 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003442 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003443}
3444
deadbeefd59daf82015-10-14 15:02:44 -07003445// This test verifies the |initial_offerer| flag when session initiates the
3446// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003447TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003448 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003449 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003450 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003451 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3452 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003453 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003454 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003455 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003456}
3457
deadbeefd59daf82015-10-14 15:02:44 -07003458// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003460 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003461 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003462 SessionDescriptionInterface* offer = CreateRemoteOffer();
3463 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003464 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003465
deadbeefd59daf82015-10-14 15:02:44 -07003466 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003467 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003468 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003469}
3470
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003471// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3472TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003473 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003474 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003475 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003477 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003478 CreateRemoteAnswer(session_->local_description()));
3479
3480 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3481 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003482 JsepSessionDescription* modified_answer =
3483 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003484
3485 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3486 answer->session_id(),
3487 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003488 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003489
wu@webrtc.org4e393072014-04-07 17:04:35 +00003490 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003491 std::string sdp;
3492 EXPECT_TRUE(answer->ToString(&sdp));
3493 const std::string kAudioMid = "a=mid:audio";
3494 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003495 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003496 kAudioMidReplaceStr.c_str(),
3497 kAudioMidReplaceStr.length(),
3498 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003499 SessionDescriptionInterface* modified_answer1 =
3500 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003501 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003502
wu@webrtc.org4e393072014-04-07 17:04:35 +00003503 // Different media types.
3504 EXPECT_TRUE(answer->ToString(&sdp));
3505 const std::string kAudioMline = "m=audio";
3506 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003507 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003508 kAudioMlineReplaceStr.c_str(),
3509 kAudioMlineReplaceStr.length(),
3510 &sdp);
3511 SessionDescriptionInterface* modified_answer2 =
3512 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3513 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3514
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003515 SetRemoteDescriptionWithoutError(answer.release());
3516}
3517
3518// Verifying remote offer and local answer have matching m-lines as per
3519// RFC 3264.
3520TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003521 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003522 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003523 SessionDescriptionInterface* offer = CreateRemoteOffer();
3524 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003525 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003526
3527 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3528 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003529 JsepSessionDescription* modified_answer =
3530 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003531
3532 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3533 answer->session_id(),
3534 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003535 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003536 SetLocalDescriptionWithoutError(answer);
3537}
3538
3539// This test verifies that WebRtcSession does not start candidate allocation
3540// before SetLocalDescription is called.
3541TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003542 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003543 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003544 SessionDescriptionInterface* offer = CreateRemoteOffer();
3545 cricket::Candidate candidate;
3546 candidate.set_component(1);
3547 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3548 candidate);
3549 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3550 cricket::Candidate candidate1;
3551 candidate1.set_component(1);
3552 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3553 candidate1);
3554 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3555 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003556 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3557 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003558
3559 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003560 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003561 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3562 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3563
htaa2a49d92016-03-04 02:51:39 -08003564 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003565 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003566 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3567}
3568
3569// This test verifies that crypto parameter is updated in local session
3570// description as per security policy set in MediaSessionDescriptionFactory.
3571TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003572 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003573 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003574 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003575
3576 // Making sure SetLocalDescription correctly sets crypto value in
3577 // SessionDescription object after de-serialization of sdp string. The value
3578 // will be set as per MediaSessionDescriptionFactory.
3579 std::string offer_str;
3580 offer->ToString(&offer_str);
3581 SessionDescriptionInterface* jsep_offer_str =
3582 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3583 SetLocalDescriptionWithoutError(jsep_offer_str);
3584 EXPECT_TRUE(session_->voice_channel()->secure_required());
3585 EXPECT_TRUE(session_->video_channel()->secure_required());
3586}
3587
3588// This test verifies the crypto parameter when security is disabled.
3589TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003590 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003591 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003592 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003593 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003594
3595 // Making sure SetLocalDescription correctly sets crypto value in
3596 // SessionDescription object after de-serialization of sdp string. The value
3597 // will be set as per MediaSessionDescriptionFactory.
3598 std::string offer_str;
3599 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003600 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003601 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3602 SetLocalDescriptionWithoutError(jsep_offer_str);
3603 EXPECT_FALSE(session_->voice_channel()->secure_required());
3604 EXPECT_FALSE(session_->video_channel()->secure_required());
3605}
3606
3607// This test verifies that an answer contains new ufrag and password if an offer
3608// with new ufrag and password is received.
3609TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003610 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003611 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003612 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003613 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003614 CreateRemoteOffer(options));
3615 SetRemoteDescriptionWithoutError(offer.release());
3616
deadbeefab9b2d12015-10-14 11:33:11 -07003617 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003618 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003619 SetLocalDescriptionWithoutError(answer.release());
3620
3621 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003622 for (const cricket::ContentInfo& content :
3623 session_->local_description()->description()->contents()) {
3624 options.transport_options[content.name].ice_restart = true;
3625 }
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003626 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003627 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003628 SetRemoteDescriptionWithoutError(updated_offer1.release());
3629
htaa2a49d92016-03-04 02:51:39 -08003630 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003631
deadbeef0ed85b22016-02-23 17:24:52 -08003632 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3633 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003634
deadbeef0ed85b22016-02-23 17:24:52 -08003635 // Even a second answer (created before the description is set) should have
3636 // a new ufrag/password.
htaa2a49d92016-03-04 02:51:39 -08003637 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003638
3639 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3640 session_->local_description()->description()));
3641
3642 SetLocalDescriptionWithoutError(updated_answer2.release());
3643}
3644
3645// This test verifies that an answer contains new ufrag and password if an offer
3646// that changes either the ufrag or password (but not both) is received.
3647// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3648// a=ice-pwd attributes compared to the previous SDP from the peer, it
3649// indicates that ICE is restarting for this media stream."
3650TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3651 Init();
3652 cricket::MediaSessionOptions options;
3653 options.recv_audio = true;
3654 options.recv_video = true;
3655 // Create an offer with audio and video.
3656 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3657 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3658 SetRemoteDescriptionWithoutError(offer.release());
3659
3660 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003661 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003662 SetLocalDescriptionWithoutError(answer.release());
3663
3664 // Receive an offer with a new ufrag but stale password.
3665 rtc::scoped_ptr<JsepSessionDescription> ufrag_changed_offer(
3666 CreateRemoteOffer(options, session_->remote_description()));
3667 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3668 "original_password12345");
3669 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3670
htaa2a49d92016-03-04 02:51:39 -08003671 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003672 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3673 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003674 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003675
3676 // Receive an offer with a new password but stale ufrag.
3677 rtc::scoped_ptr<JsepSessionDescription> password_changed_offer(
3678 CreateRemoteOffer(options, session_->remote_description()));
3679 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3680 "modified_password12345");
3681 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3682
htaa2a49d92016-03-04 02:51:39 -08003683 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003684 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3685 session_->local_description()->description()));
3686 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003687}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003688
wu@webrtc.org91053e72013-08-10 07:18:04 +00003689// This test verifies that an answer contains old ufrag and password if an offer
3690// with old ufrag and password is received.
3691TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003692 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003693 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003694 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003695 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003696 CreateRemoteOffer(options));
3697 SetRemoteDescriptionWithoutError(offer.release());
3698
deadbeefab9b2d12015-10-14 11:33:11 -07003699 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003700 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003701 SetLocalDescriptionWithoutError(answer.release());
3702
3703 // Receive an offer without changed ufrag or password.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003704 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003705 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003706 SetRemoteDescriptionWithoutError(updated_offer2.release());
3707
htaa2a49d92016-03-04 02:51:39 -08003708 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003709
deadbeef0ed85b22016-02-23 17:24:52 -08003710 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3711 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003712
3713 SetLocalDescriptionWithoutError(updated_answer2.release());
3714}
3715
deadbeef0ed85b22016-02-23 17:24:52 -08003716// This test verifies that if an offer does an ICE restart on some, but not all
3717// media sections, the answer will change the ufrag/password in the correct
3718// media sections.
3719TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3720 Init();
3721 cricket::MediaSessionOptions options;
3722 options.recv_video = true;
3723 options.recv_audio = true;
3724 options.bundle_enabled = false;
3725 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3726
3727 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3728 "aaaaaaaaaaaaaaaaaaaaaa");
3729 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3730 "bbbbbbbbbbbbbbbbbbbbbb");
3731 SetRemoteDescriptionWithoutError(offer.release());
3732
3733 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003734 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003735 SetLocalDescriptionWithoutError(answer.release());
3736
3737 // Receive an offer with new ufrag and password, but only for the video media
3738 // section.
3739 rtc::scoped_ptr<JsepSessionDescription> updated_offer(
3740 CreateRemoteOffer(options, session_->remote_description()));
3741 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3742 "cccccccccccccccccccccc");
3743 SetRemoteDescriptionWithoutError(updated_offer.release());
3744
htaa2a49d92016-03-04 02:51:39 -08003745 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003746
3747 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3748 session_->local_description()->description(),
3749 cricket::MEDIA_TYPE_AUDIO));
3750
3751 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3752 session_->local_description()->description(),
3753 cricket::MEDIA_TYPE_VIDEO));
3754
3755 SetLocalDescriptionWithoutError(updated_answer.release());
3756}
3757
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003758TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003759 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003760 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003761 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003762 const std::string session_id_orig = offer->session_id();
3763 const std::string session_version_orig = offer->session_version();
3764 SetLocalDescriptionWithoutError(offer);
3765
3766 video_channel_ = media_engine_->GetVideoChannel(0);
3767 video_channel_->set_fail_set_send_codecs(true);
3768
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003769 SessionDescriptionInterface* answer =
3770 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003771 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003772
3773 // Test that after a content error, setting any description will
3774 // result in an error.
3775 video_channel_->set_fail_set_send_codecs(false);
3776 answer = CreateRemoteAnswer(session_->local_description());
3777 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3778 offer = CreateRemoteOffer();
3779 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003780}
3781
3782// Runs the loopback call test with BUNDLE and STUN disabled.
3783TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3784 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003785 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003786 cricket::PORTALLOCATOR_DISABLE_STUN |
3787 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003788 TestLoopbackCall();
3789}
3790
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003791TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003792 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003793 cricket::PORTALLOCATOR_DISABLE_STUN |
3794 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3795 cricket::PORTALLOCATOR_DISABLE_RELAY);
3796
3797 // best connection is IPv6 since it has higher network preference.
3798 LoopbackNetworkConfiguration config;
3799 config.test_ipv6_network_ = true;
3800 config.best_connection_after_initial_ice_converged_ =
3801 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3802
3803 TestLoopbackCall(config);
3804}
3805
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003806// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003807TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003808 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3809 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003810 TestLoopbackCall();
3811}
3812
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003813TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003814 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003815 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003816 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003817 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003818 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3819}
3820
Henrik Boström87713d02015-08-25 09:53:21 +02003821TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003822 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003823
htaa2a49d92016-03-04 02:51:39 -08003824 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003825 options_.disable_sctp_data_channels = false;
3826
Henrik Boström87713d02015-08-25 09:53:21 +02003827 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003828
3829 SetLocalDescriptionWithDataChannel();
3830 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3831}
3832
Henrik Boström87713d02015-08-25 09:53:21 +02003833TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003834 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003835
Henrik Boström87713d02015-08-25 09:53:21 +02003836 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003837
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003838 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003839 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003840 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3841}
3842
Henrik Boström87713d02015-08-25 09:53:21 +02003843TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003844 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003845 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003846 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003847
3848 // Create remote offer with SCTP.
3849 cricket::MediaSessionOptions options;
3850 options.data_channel_type = cricket::DCT_SCTP;
3851 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003852 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003853 SetRemoteDescriptionWithoutError(offer);
3854
3855 // Verifies the answer contains SCTP.
htaa2a49d92016-03-04 02:51:39 -08003856 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003857 EXPECT_TRUE(answer != NULL);
3858 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3859 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003860}
3861
Henrik Boström87713d02015-08-25 09:53:21 +02003862TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003863 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003864 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003865
3866 SetLocalDescriptionWithDataChannel();
3867 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3868}
3869
Henrik Boström87713d02015-08-25 09:53:21 +02003870TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003871 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003872
Henrik Boström87713d02015-08-25 09:53:21 +02003873 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003874
3875 SetLocalDescriptionWithDataChannel();
3876 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3877}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003878
Henrik Boström87713d02015-08-25 09:53:21 +02003879TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003880 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003881 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003882 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003883
3884 SetLocalDescriptionWithDataChannel();
3885 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3886}
3887
Henrik Boström87713d02015-08-25 09:53:21 +02003888TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003889 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003890 const int new_send_port = 9998;
3891 const int new_recv_port = 7775;
3892
Henrik Boström87713d02015-08-25 09:53:21 +02003893 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003894 SetFactoryDtlsSrtp();
3895
3896 // By default, don't actually add the codecs to desc_factory_; they don't
3897 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3898 // let the session description get parsed. That'll get the proper codecs
3899 // into the stream.
3900 cricket::MediaSessionOptions options;
3901 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3902 "stream1", new_send_port, options);
3903
3904 // SetRemoteDescription will take the ownership of the offer.
3905 SetRemoteDescriptionWithoutError(offer);
3906
htaa2a49d92016-03-04 02:51:39 -08003907 SessionDescriptionInterface* answer =
3908 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003909 ASSERT_TRUE(answer != NULL);
3910
3911 // Now set the local description, which'll take ownership of the answer.
3912 SetLocalDescriptionWithoutError(answer);
3913
3914 // TEST PLAN: Set the port number to something new, set it in the SDP,
3915 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003916 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003917 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003918
3919 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3920 int portnum = -1;
3921 ASSERT_TRUE(ch != NULL);
3922 ASSERT_EQ(1UL, ch->send_codecs().size());
3923 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003924 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003925 ch->send_codecs()[0].name.c_str()));
3926 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3927 &portnum));
3928 EXPECT_EQ(new_send_port, portnum);
3929
3930 ASSERT_EQ(1UL, ch->recv_codecs().size());
3931 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003932 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003933 ch->recv_codecs()[0].name.c_str()));
3934 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3935 &portnum));
3936 EXPECT_EQ(new_recv_port, portnum);
3937}
3938
deadbeefab9b2d12015-10-14 11:33:11 -07003939// Verifies that when a session's DataChannel receives an OPEN message,
3940// WebRtcSession signals the DataChannel creation request with the expected
3941// config.
3942TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3943 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3944
3945 InitWithDtls(GetParam());
3946
3947 SetLocalDescriptionWithDataChannel();
3948 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3949
3950 webrtc::DataChannelInit config;
3951 config.id = 1;
3952 rtc::Buffer payload;
3953 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3954 cricket::ReceiveDataParams params;
3955 params.ssrc = config.id;
3956 params.type = cricket::DMT_CONTROL;
3957
3958 cricket::DataChannel* data_channel = session_->data_channel();
3959 data_channel->SignalDataReceived(data_channel, params, payload);
3960
3961 EXPECT_EQ("a", last_data_channel_label_);
3962 EXPECT_EQ(config.id, last_data_channel_config_.id);
3963 EXPECT_FALSE(last_data_channel_config_.negotiated);
3964 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3965 last_data_channel_config_.open_handshake_role);
3966}
3967
3968TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003969 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3970 FakeDtlsIdentityStore::GenerateCertificate();
3971
htaa2a49d92016-03-04 02:51:39 -08003972 configuration_.certificates.push_back(certificate);
3973 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02003974 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3975
3976 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3977}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003978
Henrik Boström87713d02015-08-25 09:53:21 +02003979// Verifies that CreateOffer succeeds when CreateOffer is called before async
3980// identity generation is finished (even if a certificate is provided this is
3981// an async op).
3982TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3983 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3984 InitWithDtls(GetParam());
3985
Henrik Boströmd8281982015-08-27 10:12:24 +02003986 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003987 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003988 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3989
wu@webrtc.org91053e72013-08-10 07:18:04 +00003990 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003991 VerifyNoCryptoParams(offer->description(), true);
3992 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003993}
3994
3995// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003996// identity generation is finished (even if a certificate is provided this is
3997// an async op).
3998TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003999 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004000 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004001 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004002
4003 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004004 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00004005 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004006 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004007 ASSERT_TRUE(offer.get() != NULL);
4008 SetRemoteDescriptionWithoutError(offer.release());
4009
htaa2a49d92016-03-04 02:51:39 -08004010 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004011 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004012 VerifyNoCryptoParams(answer->description(), true);
4013 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004014}
4015
4016// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004017// identity generation is finished (even if a certificate is provided this is
4018// an async op).
4019TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004020 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004021 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004022
Henrik Boströmd8281982015-08-27 10:12:24 +02004023 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004024
4025 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004026 EXPECT_TRUE(offer != NULL);
4027}
4028
4029// Verifies that CreateOffer fails when CreateOffer is called after async
4030// identity generation fails.
4031TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004032 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004033 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004034
Henrik Boströmd8281982015-08-27 10:12:24 +02004035 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004036
4037 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004038 EXPECT_TRUE(offer == NULL);
4039}
4040
4041// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4042// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004043TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004044 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004045 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004046 VerifyMultipleAsyncCreateDescription(GetParam(),
4047 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004048}
4049
4050// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4051// before async identity generation fails.
4052TEST_F(WebRtcSessionTest,
4053 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004054 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004055 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4056 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004057}
4058
4059// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4060// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004061TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004062 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004063 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004064 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004065 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004066}
4067
4068// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4069// before async identity generation fails.
4070TEST_F(WebRtcSessionTest,
4071 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004072 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004073 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4074 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004075}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004076
4077// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4078// offer has no SDES crypto but only DTLS fingerprint.
4079TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4080 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004081 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004082 // Create a remote offer with secured transport disabled.
4083 cricket::MediaSessionOptions options;
4084 JsepSessionDescription* offer(CreateRemoteOffer(
4085 options, cricket::SEC_DISABLED));
4086 // Adds a DTLS fingerprint to the remote offer.
4087 cricket::SessionDescription* sdp = offer->description();
4088 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4089 ASSERT_TRUE(audio != NULL);
4090 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4091 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004092 rtc::SSLFingerprint::CreateFromRfc4572(
4093 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004094 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004095 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004096}
4097
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004098TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004099 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004100 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004101 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004102 SessionDescriptionInterface* offer = CreateOffer();
4103
4104 SetLocalDescriptionWithoutError(offer);
4105
4106 voice_channel_ = media_engine_->GetVoiceChannel(0);
4107
4108 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004109 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004110 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004111}
4112
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004113// Tests that we can renegotiate new media content with ICE candidates in the
4114// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004115TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004116 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004117 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004118 SetFactoryDtlsSrtp();
4119
deadbeefab9b2d12015-10-14 11:33:11 -07004120 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004121 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004122 SetLocalDescriptionWithoutError(offer);
4123
4124 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4125 SetRemoteDescriptionWithoutError(answer);
4126
4127 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004128 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004129 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4130
4131 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004132 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004133 candidate1.set_component(1);
4134 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4135 candidate1);
4136 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4137 SetRemoteDescriptionWithoutError(offer);
4138
htaa2a49d92016-03-04 02:51:39 -08004139 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004140 SetLocalDescriptionWithoutError(answer);
4141}
4142
4143// Tests that we can renegotiate new media content with ICE candidates separated
4144// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004145TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004146 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004147 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004148 SetFactoryDtlsSrtp();
4149
deadbeefab9b2d12015-10-14 11:33:11 -07004150 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004151 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004152 SetLocalDescriptionWithoutError(offer);
4153
4154 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4155 SetRemoteDescriptionWithoutError(answer);
4156
4157 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004158 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004159 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4160 SetRemoteDescriptionWithoutError(offer);
4161
4162 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004163 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004164 candidate1.set_component(1);
4165 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4166 candidate1);
4167 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4168
htaa2a49d92016-03-04 02:51:39 -08004169 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004170 SetLocalDescriptionWithoutError(answer);
4171}
honghaiz7f777492016-02-02 21:54:01 -08004172
4173// Flaky on Win and Mac only. See webrtc:4943
4174#if defined(WEBRTC_WIN) || defined(WEBRTC_MAC)
4175#define MAYBE_TestRtxRemovedByCreateAnswer DISABLED_TestRtxRemovedByCreateAnswer
4176#else
4177#define MAYBE_TestRtxRemovedByCreateAnswer TestRtxRemovedByCreateAnswer
4178#endif
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004179// Tests that RTX codec is removed from the answer when it isn't supported
4180// by local side.
honghaiz7f777492016-02-02 21:54:01 -08004181TEST_F(WebRtcSessionTest, MAYBE_TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004182 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004183 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004184 std::string offer_sdp(kSdpWithRtx);
4185
4186 SessionDescriptionInterface* offer =
4187 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4188 EXPECT_TRUE(offer->ToString(&offer_sdp));
4189
4190 // Offer SDP contains the RTX codec.
4191 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4192 SetRemoteDescriptionWithoutError(offer);
4193
htaa2a49d92016-03-04 02:51:39 -08004194 SessionDescriptionInterface* answer = CreateAnswer();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004195 std::string answer_sdp;
4196 answer->ToString(&answer_sdp);
4197 // Answer SDP removes the unsupported RTX codec.
4198 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4199 SetLocalDescriptionWithoutError(answer);
4200}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004201
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004202// This verifies that the voice channel after bundle has both options from video
4203// and voice channels.
4204TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4205 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004206 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004207
4208 PeerConnectionInterface::RTCOfferAnswerOptions options;
4209 options.use_rtp_mux = true;
4210
4211 SessionDescriptionInterface* offer = CreateOffer(options);
4212 SetLocalDescriptionWithoutError(offer);
4213
4214 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4215 rtc::Socket::Option::OPT_SNDBUF, 4000);
4216
4217 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4218 rtc::Socket::Option::OPT_RCVBUF, 8000);
4219
4220 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004221 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004222 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4223 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004224 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004225 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4226
deadbeefcbecd352015-09-23 11:50:27 -07004227 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004228 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4229 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004230 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004231 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4232
deadbeefcbecd352015-09-23 11:50:27 -07004233 EXPECT_NE(session_->voice_rtp_transport_channel(),
4234 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004235
deadbeefab9b2d12015-10-14 11:33:11 -07004236 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004237 SessionDescriptionInterface* answer =
4238 CreateRemoteAnswer(session_->local_description());
4239 SetRemoteDescriptionWithoutError(answer);
4240
deadbeefcbecd352015-09-23 11:50:27 -07004241 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004242 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4243 EXPECT_EQ(4000, option_val);
4244
deadbeefcbecd352015-09-23 11:50:27 -07004245 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004246 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4247 EXPECT_EQ(8000, option_val);
4248}
4249
tommi0f620f42015-07-09 03:25:02 -07004250// Test creating a session, request multiple offers, destroy the session
4251// and make sure we got success/failure callbacks for all of the requests.
4252// Background: crbug.com/507307
4253TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4254 Init();
4255
4256 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4257 PeerConnectionInterface::RTCOfferAnswerOptions options;
4258 options.offer_to_receive_audio =
4259 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004260 cricket::MediaSessionOptions session_options;
4261 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004262
4263 for (auto& o : observers) {
4264 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004265 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004266 }
4267
4268 session_.reset();
4269
tommi0f620f42015-07-09 03:25:02 -07004270 for (auto& o : observers) {
4271 // We expect to have received a notification now even if the session was
4272 // terminated. The offer creation may or may not have succeeded, but we
4273 // must have received a notification which, so the only invalid state
4274 // is kInit.
4275 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4276 }
4277}
4278
stefanc1aeaf02015-10-15 07:26:07 -07004279TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4280 TestPacketOptions();
4281}
4282
deadbeef057ecf02016-01-20 14:30:43 -08004283// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4284// is destroyed.
4285TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4286 Init();
4287 session_.reset();
4288 EXPECT_TRUE(session_destroyed_);
4289}
4290
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004291// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4292// currently fails because upon disconnection and reconnection OnIceComplete is
4293// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004294
deadbeefcbecd352015-09-23 11:50:27 -07004295INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4296 WebRtcSessionTest,
4297 testing::Values(ALREADY_GENERATED,
4298 DTLS_IDENTITY_STORE));