blob: b0ee1be67ced55f9b3b7f8cef38982c02a3aa5fa [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kwiberg0eb15ed2015-12-17 03:04:15 -080011#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070012#include <vector>
13
Henrik Kjellander15583c12016-02-10 10:53:12 +010014#include "webrtc/api/audiotrack.h"
15#include "webrtc/api/fakemediacontroller.h"
16#include "webrtc/api/fakemetricsobserver.h"
17#include "webrtc/api/jsepicecandidate.h"
18#include "webrtc/api/jsepsessiondescription.h"
19#include "webrtc/api/peerconnection.h"
20#include "webrtc/api/sctputils.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010021#include "webrtc/api/test/fakedtlsidentitystore.h"
22#include "webrtc/api/videotrack.h"
23#include "webrtc/api/webrtcsession.h"
24#include "webrtc/api/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000025#include "webrtc/base/fakenetwork.h"
26#include "webrtc/base/firewallsocketserver.h"
27#include "webrtc/base/gunit.h"
28#include "webrtc/base/logging.h"
29#include "webrtc/base/network.h"
30#include "webrtc/base/physicalsocketserver.h"
31#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020032#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000033#include "webrtc/base/sslstreamadapter.h"
34#include "webrtc/base/stringutils.h"
35#include "webrtc/base/thread.h"
36#include "webrtc/base/virtualsocketserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080037#include "webrtc/media/base/fakemediaengine.h"
38#include "webrtc/media/base/fakevideorenderer.h"
39#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010040#include "webrtc/media/engine/fakewebrtccall.h"
kjellandera96e2d72016-02-04 23:52:28 -080041#include "webrtc/p2p/base/stunserver.h"
42#include "webrtc/p2p/base/teststunserver.h"
43#include "webrtc/p2p/base/testturnserver.h"
44#include "webrtc/p2p/base/transportchannel.h"
45#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010046#include "webrtc/pc/channelmanager.h"
47#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048
49#define MAYBE_SKIP_TEST(feature) \
50 if (!(feature())) { \
51 LOG(LS_INFO) << "Feature disabled... skipping"; \
52 return; \
53 }
54
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000057using rtc::SocketAddress;
58using rtc::scoped_ptr;
59using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000061using webrtc::CreateSessionDescriptionObserver;
62using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070063using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020064using webrtc::DtlsIdentityStoreInterface;
jbauchac8869e2015-07-03 01:36:14 -070065using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070067using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068using webrtc::JsepIceCandidate;
69using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000070using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071using webrtc::PeerConnectionInterface;
72using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070073using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000075using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000076using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000077using webrtc::kCreateChannelFailed;
78using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000080using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000081using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000082using webrtc::kSdpWithoutDtlsFingerprint;
83using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000085using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000086using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000088typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
89
wu@webrtc.org364f2042013-11-20 21:49:41 +000090static const int kClientAddrPort = 0;
91static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000092static const char kClientIPv6AddrHost1[] =
93 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000094static const char kClientAddrHost2[] = "22.22.22.22";
95static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000096static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
97static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000098static const char kTurnUsername[] = "test";
99static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
101static const char kSessionVersion[] = "1";
102
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103// Media index of candidates belonging to the first media content.
104static const int kMediaContentIndex0 = 0;
105static const char kMediaContentName0[] = "audio";
106
107// Media index of candidates belonging to the second media content.
108static const int kMediaContentIndex1 = 1;
109static const char kMediaContentName1[] = "video";
110
111static const int kIceCandidatesTimeout = 10000;
112
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000113static const char kFakeDtlsFingerprint[] =
114 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
115 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
116
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000117static const char kTooLongIceUfragPwd[] =
118 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
119 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
120 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
121 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
122
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000123static const char kSdpWithRtx[] =
124 "v=0\r\n"
125 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
126 "s=-\r\n"
127 "t=0 0\r\n"
128 "a=msid-semantic: WMS stream1\r\n"
129 "m=video 9 RTP/SAVPF 0 96\r\n"
130 "c=IN IP4 0.0.0.0\r\n"
131 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
132 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
133 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
134 "a=mid:video\r\n"
135 "a=sendrecv\r\n"
136 "a=rtcp-mux\r\n"
137 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
138 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
139 "a=rtpmap:0 fake_video_codec/90000\r\n"
140 "a=rtpmap:96 rtx/90000\r\n"
141 "a=fmtp:96 apt=0\r\n";
142
deadbeefab9b2d12015-10-14 11:33:11 -0700143static const char kStream1[] = "stream1";
144static const char kVideoTrack1[] = "video1";
145static const char kAudioTrack1[] = "audio1";
146
147static const char kStream2[] = "stream2";
148static const char kVideoTrack2[] = "video2";
149static const char kAudioTrack2[] = "audio2";
150
Henrik Boström87713d02015-08-25 09:53:21 +0200151enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
152
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153class MockIceObserver : public webrtc::IceObserver {
154 public:
155 MockIceObserver()
156 : oncandidatesready_(false),
157 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
158 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
159 }
160
perkjdfb769d2016-02-09 03:09:43 -0800161 void OnIceConnectionChange(
162 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 ice_connection_state_ = new_state;
164 }
perkjdfb769d2016-02-09 03:09:43 -0800165 void OnIceGatheringChange(
166 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 // We can never transition back to "new".
168 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
169 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800170 oncandidatesready_ =
171 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 }
173
174 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800175 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000176 switch (candidate->sdp_mline_index()) {
177 case kMediaContentIndex0:
178 mline_0_candidates_.push_back(candidate->candidate());
179 break;
180 case kMediaContentIndex1:
181 mline_1_candidates_.push_back(candidate->candidate());
182 break;
183 default:
184 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000186
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 // The ICE gathering state should always be Gathering when a candidate is
188 // received (or possibly Completed in the case of the final candidate).
189 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
190 }
191
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 bool oncandidatesready_;
193 std::vector<cricket::Candidate> mline_0_candidates_;
194 std::vector<cricket::Candidate> mline_1_candidates_;
195 PeerConnectionInterface::IceConnectionState ice_connection_state_;
196 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
197};
198
199class WebRtcSessionForTest : public webrtc::WebRtcSession {
200 public:
stefanc1aeaf02015-10-15 07:26:07 -0700201 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000202 rtc::Thread* signaling_thread,
203 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700205 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700206 : WebRtcSession(media_controller,
207 signaling_thread,
208 worker_thread,
209 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 RegisterIceObserver(ice_observer);
211 }
212 virtual ~WebRtcSessionForTest() {}
213
deadbeefcbecd352015-09-23 11:50:27 -0700214 // Note that these methods are only safe to use if the signaling thread
215 // is the same as the worker thread
216 cricket::TransportChannel* voice_rtp_transport_channel() {
217 return rtp_transport_channel(voice_channel());
218 }
219
220 cricket::TransportChannel* voice_rtcp_transport_channel() {
221 return rtcp_transport_channel(voice_channel());
222 }
223
224 cricket::TransportChannel* video_rtp_transport_channel() {
225 return rtp_transport_channel(video_channel());
226 }
227
228 cricket::TransportChannel* video_rtcp_transport_channel() {
229 return rtcp_transport_channel(video_channel());
230 }
231
232 cricket::TransportChannel* data_rtp_transport_channel() {
233 return rtp_transport_channel(data_channel());
234 }
235
236 cricket::TransportChannel* data_rtcp_transport_channel() {
237 return rtcp_transport_channel(data_channel());
238 }
239
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 using webrtc::WebRtcSession::SetAudioPlayout;
241 using webrtc::WebRtcSession::SetAudioSend;
242 using webrtc::WebRtcSession::SetCaptureDevice;
243 using webrtc::WebRtcSession::SetVideoPlayout;
244 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700245
246 private:
247 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
248 if (!ch) {
249 return nullptr;
250 }
251 return ch->transport_channel();
252 }
253
254 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
255 if (!ch) {
256 return nullptr;
257 }
258 return ch->rtcp_transport_channel();
259 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260};
261
wu@webrtc.org91053e72013-08-10 07:18:04 +0000262class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000263 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000265 enum State {
266 kInit,
267 kFailed,
268 kSucceeded,
269 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000270 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000271
272 // CreateSessionDescriptionObserver implementation.
273 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000274 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000275 state_ = kSucceeded;
276 }
277 virtual void OnFailure(const std::string& error) {
278 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279 }
280
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000281 SessionDescriptionInterface* description() { return description_.get(); }
282
283 SessionDescriptionInterface* ReleaseDescription() {
284 return description_.release();
285 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286
wu@webrtc.org91053e72013-08-10 07:18:04 +0000287 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288
wu@webrtc.org91053e72013-08-10 07:18:04 +0000289 protected:
290 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000291
292 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000293 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000294 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295};
296
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000297class FakeAudioRenderer : public cricket::AudioRenderer {
298 public:
solenberg98c68862015-10-09 03:27:14 -0700299 FakeAudioRenderer() : sink_(NULL) {}
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000300 virtual ~FakeAudioRenderer() {
301 if (sink_)
302 sink_->OnClose();
303 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000304
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000305 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000306
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000307 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000308 private:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000309 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000310};
311
Henrik Boström87713d02015-08-25 09:53:21 +0200312class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700313 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
314 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315 protected:
316 // TODO Investigate why ChannelManager crashes, if it's created
317 // after stun_server.
318 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700319 : media_engine_(new cricket::FakeMediaEngine()),
320 data_engine_(new cricket::FakeDataEngine()),
321 channel_manager_(
322 new cricket::ChannelManager(media_engine_,
323 data_engine_,
stefanc1aeaf02015-10-15 07:26:07 -0700324 rtc::Thread::Current())),
325 fake_call_(webrtc::Call::Config()),
326 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800327 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
328 rtc::Thread::Current(),
stefanc1aeaf02015-10-15 07:26:07 -0700329 channel_manager_.get())),
330 tdesc_factory_(new cricket::TransportDescriptionFactory()),
331 desc_factory_(
332 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
333 tdesc_factory_.get())),
334 pss_(new rtc::PhysicalSocketServer),
335 vss_(new rtc::VirtualSocketServer(pss_.get())),
336 fss_(new rtc::FirewallSocketServer(vss_.get())),
337 ss_scope_(fss_.get()),
338 stun_socket_addr_(
339 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
340 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
341 stun_socket_addr_)),
342 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
343 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000344 cricket::ServerAddresses stun_servers;
345 stun_servers.insert(stun_socket_addr_);
346 allocator_.reset(new cricket::BasicPortAllocator(
347 &network_manager_,
348 stun_servers,
349 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000350 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700351 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 EXPECT_TRUE(channel_manager_->Init());
353 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000354 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 }
356
357 void AddInterface(const SocketAddress& addr) {
358 network_manager_.AddInterface(addr);
359 }
360
Henrik Boström87713d02015-08-25 09:53:21 +0200361 // If |dtls_identity_store| != null or |rtc_configuration| contains
362 // |certificates| then DTLS will be enabled unless explicitly disabled by
363 // |rtc_configuration| options. When DTLS is enabled a certificate will be
364 // used if provided, otherwise one will be generated using the
365 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000366 void Init(
htaa2a49d92016-03-04 02:51:39 -0800367 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 ASSERT_TRUE(session_.get() == NULL);
369 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700370 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700371 allocator_.get(), &observer_));
372 session_->SignalDataChannelOpenMessage.connect(
373 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800374 session_->GetOnDestroyedSignal()->connect(
375 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376
377 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
378 observer_.ice_connection_state_);
379 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
380 observer_.ice_gathering_state_);
381
htaa2a49d92016-03-04 02:51:39 -0800382 EXPECT_TRUE(session_->Initialize(options_, std::move(dtls_identity_store),
383 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700384 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385 }
386
deadbeefab9b2d12015-10-14 11:33:11 -0700387 void OnDataChannelOpenMessage(const std::string& label,
388 const InternalDataChannelInit& config) {
389 last_data_channel_label_ = label;
390 last_data_channel_config_ = config;
391 }
392
deadbeef057ecf02016-01-20 14:30:43 -0800393 void OnSessionDestroyed() { session_destroyed_ = true; }
394
htaa2a49d92016-03-04 02:51:39 -0800395 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000396
397 void InitWithIceTransport(
398 PeerConnectionInterface::IceTransportsType ice_transport_type) {
htaa2a49d92016-03-04 02:51:39 -0800399 configuration_.type = ice_transport_type;
400 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000401 }
402
403 void InitWithBundlePolicy(
404 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800405 configuration_.bundle_policy = bundle_policy;
406 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700407 }
408
409 void InitWithRtcpMuxPolicy(
410 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
411 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800412 configuration_.rtcp_mux_policy = rtcp_mux_policy;
413 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000414 }
415
Henrik Boström87713d02015-08-25 09:53:21 +0200416 // Successfully init with DTLS; with a certificate generated and supplied or
417 // with a store that generates it for us.
418 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
419 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
Henrik Boström87713d02015-08-25 09:53:21 +0200420 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800421 configuration_.certificates.push_back(
Henrik Boström87713d02015-08-25 09:53:21 +0200422 FakeDtlsIdentityStore::GenerateCertificate());
423 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
424 dtls_identity_store.reset(new FakeDtlsIdentityStore());
425 dtls_identity_store->set_should_fail(false);
426 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700427 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200428 }
htaa2a49d92016-03-04 02:51:39 -0800429 Init(std::move(dtls_identity_store));
Henrik Boström87713d02015-08-25 09:53:21 +0200430 }
431
432 // Init with DTLS with a store that will fail to generate a certificate.
433 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200434 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
435 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200436 dtls_identity_store->set_should_fail(true);
htaa2a49d92016-03-04 02:51:39 -0800437 Init(std::move(dtls_identity_store));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000438 }
439
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440 void InitWithDtmfCodec() {
441 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000442 const cricket::AudioCodec kTelephoneEventCodec(
443 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000444 std::vector<cricket::AudioCodec> codecs;
445 codecs.push_back(kTelephoneEventCodec);
446 media_engine_->SetAudioCodecs(codecs);
447 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000448 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449 }
450
deadbeefab9b2d12015-10-14 11:33:11 -0700451 void SendAudioVideoStream1() {
452 send_stream_1_ = true;
453 send_stream_2_ = false;
454 send_audio_ = true;
455 send_video_ = true;
456 }
457
458 void SendAudioVideoStream2() {
459 send_stream_1_ = false;
460 send_stream_2_ = true;
461 send_audio_ = true;
462 send_video_ = true;
463 }
464
465 void SendAudioVideoStream1And2() {
466 send_stream_1_ = true;
467 send_stream_2_ = true;
468 send_audio_ = true;
469 send_video_ = true;
470 }
471
472 void SendNothing() {
473 send_stream_1_ = false;
474 send_stream_2_ = false;
475 send_audio_ = false;
476 send_video_ = false;
477 }
478
479 void SendAudioOnlyStream2() {
480 send_stream_1_ = false;
481 send_stream_2_ = true;
482 send_audio_ = true;
483 send_video_ = false;
484 }
485
486 void SendVideoOnlyStream2() {
487 send_stream_1_ = false;
488 send_stream_2_ = true;
489 send_audio_ = false;
490 send_video_ = true;
491 }
492
493 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
494 if (send_stream_1_ && send_audio_) {
495 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
496 kStream1);
497 }
498 if (send_stream_1_ && send_video_) {
499 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
500 kStream1);
501 }
502 if (send_stream_2_ && send_audio_) {
503 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
504 kStream2);
505 }
506 if (send_stream_2_ && send_video_) {
507 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
508 kStream2);
509 }
510 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
511 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
512 data_channel_->label(),
513 data_channel_->label());
514 }
515 }
516
517 void GetOptionsForOffer(
518 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
519 cricket::MediaSessionOptions* session_options) {
htaa2a49d92016-03-04 02:51:39 -0800520 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700521
deadbeefc80741f2015-10-22 13:14:45 -0700522 AddStreamsToOptions(session_options);
523 if (rtc_options.offer_to_receive_audio ==
524 RTCOfferAnswerOptions::kUndefined) {
525 session_options->recv_audio =
526 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
527 }
528 if (rtc_options.offer_to_receive_video ==
529 RTCOfferAnswerOptions::kUndefined) {
530 session_options->recv_video =
531 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
532 }
533 session_options->bundle_enabled =
534 session_options->bundle_enabled &&
535 (session_options->has_audio() || session_options->has_video() ||
536 session_options->has_data());
537
deadbeefab9b2d12015-10-14 11:33:11 -0700538 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
539 session_options->data_channel_type = cricket::DCT_SCTP;
540 }
541 }
542
htaa2a49d92016-03-04 02:51:39 -0800543 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
544 // ParseConstraintsForAnswer is used to set some defaults.
545 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700546
deadbeefc80741f2015-10-22 13:14:45 -0700547 AddStreamsToOptions(session_options);
548 session_options->bundle_enabled =
549 session_options->bundle_enabled &&
550 (session_options->has_audio() || session_options->has_video() ||
551 session_options->has_data());
552
deadbeefab9b2d12015-10-14 11:33:11 -0700553 if (session_->data_channel_type() == cricket::DCT_SCTP) {
554 session_options->data_channel_type = cricket::DCT_SCTP;
555 }
556 }
557
558 // Creates a local offer and applies it. Starts ICE.
559 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 // to decide which streams to create.
561 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000562 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000563 SetLocalDescriptionWithoutError(offer);
564 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
565 observer_.ice_gathering_state_,
566 kIceCandidatesTimeout);
567 }
568
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000569 SessionDescriptionInterface* CreateOffer() {
570 PeerConnectionInterface::RTCOfferAnswerOptions options;
571 options.offer_to_receive_audio =
572 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
573
574 return CreateOffer(options);
575 }
576
wu@webrtc.org91053e72013-08-10 07:18:04 +0000577 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800578 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000579 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000580 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700581 cricket::MediaSessionOptions session_options;
582 GetOptionsForOffer(options, &session_options);
583 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000584 EXPECT_TRUE_WAIT(
585 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000586 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000587 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000588 }
589
590 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800591 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000592 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000593 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800594 cricket::MediaSessionOptions session_options = options;
595 GetOptionsForAnswer(&session_options);
596 // Overwrite recv_audio and recv_video with passed-in values.
597 session_options.recv_video = options.recv_video;
598 session_options.recv_audio = options.recv_audio;
599 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000600 EXPECT_TRUE_WAIT(
601 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000602 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000603 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000604 }
605
htaa2a49d92016-03-04 02:51:39 -0800606 SessionDescriptionInterface* CreateAnswer() {
607 cricket::MediaSessionOptions options;
608 options.recv_video = true;
609 options.recv_audio = true;
610 return CreateAnswer(options);
611 }
612
wu@webrtc.org364f2042013-11-20 21:49:41 +0000613 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000614 return (session_->voice_channel() != NULL &&
615 session_->video_channel() != NULL);
616 }
617
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
619 ASSERT_TRUE(session_.get() != NULL);
620 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
621 ASSERT_TRUE(content != NULL);
622 const cricket::AudioContentDescription* audio_content =
623 static_cast<const cricket::AudioContentDescription*>(
624 content->description);
625 ASSERT_TRUE(audio_content != NULL);
626 ASSERT_EQ(1U, audio_content->cryptos().size());
627 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
628 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
629 audio_content->cryptos()[0].cipher_suite);
630 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
631 audio_content->protocol());
632
633 content = cricket::GetFirstVideoContent(sdp);
634 ASSERT_TRUE(content != NULL);
635 const cricket::VideoContentDescription* video_content =
636 static_cast<const cricket::VideoContentDescription*>(
637 content->description);
638 ASSERT_TRUE(video_content != NULL);
639 ASSERT_EQ(1U, video_content->cryptos().size());
640 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
641 video_content->cryptos()[0].cipher_suite);
642 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
643 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
644 video_content->protocol());
645 }
646
647 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
648 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
649 ASSERT_TRUE(content != NULL);
650 const cricket::AudioContentDescription* audio_content =
651 static_cast<const cricket::AudioContentDescription*>(
652 content->description);
653 ASSERT_TRUE(audio_content != NULL);
654 ASSERT_EQ(0U, audio_content->cryptos().size());
655
656 content = cricket::GetFirstVideoContent(sdp);
657 ASSERT_TRUE(content != NULL);
658 const cricket::VideoContentDescription* video_content =
659 static_cast<const cricket::VideoContentDescription*>(
660 content->description);
661 ASSERT_TRUE(video_content != NULL);
662 ASSERT_EQ(0U, video_content->cryptos().size());
663
664 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700665 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700667 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000668 video_content->protocol());
669 } else {
670 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
671 audio_content->protocol());
672 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
673 video_content->protocol());
674 }
675 }
676
677 // Set the internal fake description factories to do DTLS-SRTP.
678 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000679 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000680 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000681 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200682 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800683 tdesc_factory_->set_certificate(
684 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
685 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
687 }
688
689 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
690 bool expected) {
691 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
692 ASSERT_TRUE(audio != NULL);
693 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 const TransportInfo* video = sdp->GetTransportInfoByName("video");
695 ASSERT_TRUE(video != NULL);
696 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 }
698
699 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000700 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000702 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000703 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000705 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000707 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
708 offer);
htaa2a49d92016-03-04 02:51:39 -0800709 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 // Answer should be NULL as no crypto params in offer.
711 ASSERT_TRUE(answer == NULL);
712 }
713
714 void VerifyAnswerFromCryptoOffer() {
715 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000716 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 options.bundle_enabled = true;
718 scoped_ptr<JsepSessionDescription> offer(
719 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
720 ASSERT_TRUE(offer.get() != NULL);
721 VerifyCryptoParams(offer->description());
722 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -0800723 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 ASSERT_TRUE(answer.get() != NULL);
725 VerifyCryptoParams(answer->description());
726 }
727
deadbeef0ed85b22016-02-23 17:24:52 -0800728 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
729 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800731 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 }
733
734 const cricket::ContentInfos& contents = desc1->contents();
735 cricket::ContentInfos::const_iterator it = contents.begin();
736
737 for (; it != contents.end(); ++it) {
738 const cricket::TransportDescription* transport_desc1 =
739 desc1->GetTransportDescriptionByName(it->name);
740 const cricket::TransportDescription* transport_desc2 =
741 desc2->GetTransportDescriptionByName(it->name);
742 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800743 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744 }
745 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
746 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800747 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000748 }
749 }
deadbeef0ed85b22016-02-23 17:24:52 -0800750 return true;
751 }
752
753 // Compares ufrag/password only for the specified |media_type|.
754 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
755 const cricket::SessionDescription* desc2,
756 cricket::MediaType media_type) {
757 if (desc1->contents().size() != desc2->contents().size()) {
758 return false;
759 }
760
761 const cricket::ContentInfo* cinfo =
762 cricket::GetFirstMediaContent(desc1->contents(), media_type);
763 const cricket::TransportDescription* transport_desc1 =
764 desc1->GetTransportDescriptionByName(cinfo->name);
765 const cricket::TransportDescription* transport_desc2 =
766 desc2->GetTransportDescriptionByName(cinfo->name);
767 if (!transport_desc1 || !transport_desc2) {
768 return false;
769 }
770 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
771 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
772 return false;
773 }
774 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000776
777 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
778 std::string *sdp) {
779 const cricket::SessionDescription* desc = current_desc->description();
780 EXPECT_TRUE(current_desc->ToString(sdp));
781
782 const cricket::ContentInfos& contents = desc->contents();
783 cricket::ContentInfos::const_iterator it = contents.begin();
784 // Replace ufrag and pwd lines with empty strings.
785 for (; it != contents.end(); ++it) {
786 const cricket::TransportDescription* transport_desc =
787 desc->GetTransportDescriptionByName(it->name);
788 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
789 + "\r\n";
790 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
791 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000792 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000793 "", 0,
794 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000795 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000796 "", 0,
797 sdp);
798 }
799 }
800
deadbeef0ed85b22016-02-23 17:24:52 -0800801 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
802 const std::string& ufrag,
803 const std::string& pwd) {
804 cricket::SessionDescription* desc = current_desc->description();
805 for (TransportInfo& transport_info : desc->transport_infos()) {
806 cricket::TransportDescription& transport_desc =
807 transport_info.description;
808 transport_desc.ice_ufrag = ufrag;
809 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000810 }
811 }
812
deadbeef0ed85b22016-02-23 17:24:52 -0800813 // Sets ufrag/pwd for specified |media_type|.
814 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
815 cricket::MediaType media_type,
816 const std::string& ufrag,
817 const std::string& pwd) {
818 cricket::SessionDescription* desc = current_desc->description();
819 const cricket::ContentInfo* cinfo =
820 cricket::GetFirstMediaContent(desc->contents(), media_type);
821 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
822 cricket::TransportDescription* transport_desc =
823 &transport_info->description;
824 transport_desc->ice_ufrag = ufrag;
825 transport_desc->ice_pwd = pwd;
826 }
827
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 // Creates a remote offer and and applies it as a remote description,
829 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700830 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 // to decide which local and remote streams to create.
832 void CreateAndSetRemoteOfferAndLocalAnswer() {
833 SessionDescriptionInterface* offer = CreateRemoteOffer();
834 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800835 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836 SetLocalDescriptionWithoutError(answer);
837 }
838 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
839 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700840 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841 }
842 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700843 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 SetLocalDescriptionWithoutError(desc);
845 EXPECT_EQ(expected_state, session_->state());
846 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000847 void SetLocalDescriptionExpectError(const std::string& action,
848 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 SessionDescriptionInterface* desc) {
850 std::string error;
851 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000852 std::string sdp_type = "local ";
853 sdp_type.append(action);
854 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 EXPECT_NE(std::string::npos, error.find(expected_error));
856 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000857 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
858 SessionDescriptionInterface* desc) {
859 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
860 expected_error, desc);
861 }
862 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
863 SessionDescriptionInterface* desc) {
864 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
865 expected_error, desc);
866 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
868 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
869 }
870 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700871 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872 SetRemoteDescriptionWithoutError(desc);
873 EXPECT_EQ(expected_state, session_->state());
874 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000875 void SetRemoteDescriptionExpectError(const std::string& action,
876 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 SessionDescriptionInterface* desc) {
878 std::string error;
879 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000880 std::string sdp_type = "remote ";
881 sdp_type.append(action);
882 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 EXPECT_NE(std::string::npos, error.find(expected_error));
884 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000885 void SetRemoteDescriptionOfferExpectError(
886 const std::string& expected_error, SessionDescriptionInterface* desc) {
887 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
888 expected_error, desc);
889 }
890 void SetRemoteDescriptionPranswerExpectError(
891 const std::string& expected_error, SessionDescriptionInterface* desc) {
892 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
893 expected_error, desc);
894 }
895 void SetRemoteDescriptionAnswerExpectError(
896 const std::string& expected_error, SessionDescriptionInterface* desc) {
897 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
898 expected_error, desc);
899 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900
901 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
902 SessionDescriptionInterface** nocrypto_answer) {
903 // Create a SDP without Crypto.
904 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000905 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 options.bundle_enabled = true;
907 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
908 ASSERT_TRUE(*offer != NULL);
909 VerifyCryptoParams((*offer)->description());
910
911 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
912 cricket::SEC_DISABLED);
913 EXPECT_TRUE(*nocrypto_answer != NULL);
914 }
915
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000916 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
917 SessionDescriptionInterface** nodtls_answer) {
918 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000919 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000920 options.bundle_enabled = true;
921
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000922 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000923 CreateRemoteOffer(options, cricket::SEC_ENABLED));
924
925 *nodtls_answer =
926 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
927 EXPECT_TRUE(*nodtls_answer != NULL);
928 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
929 VerifyCryptoParams((*nodtls_answer)->description());
930
931 SetFactoryDtlsSrtp();
932 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
933 ASSERT_TRUE(*offer != NULL);
934 VerifyFingerprintStatus((*offer)->description(), true);
935 VerifyCryptoParams((*offer)->description());
936 }
937
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938 JsepSessionDescription* CreateRemoteOfferWithVersion(
939 cricket::MediaSessionOptions options,
940 cricket::SecurePolicy secure_policy,
941 const std::string& session_version,
942 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000943 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 const cricket::SessionDescription* cricket_desc = NULL;
945 if (current_desc) {
946 cricket_desc = current_desc->description();
947 session_id = current_desc->session_id();
948 }
949
950 desc_factory_->set_secure(secure_policy);
951 JsepSessionDescription* offer(
952 new JsepSessionDescription(JsepSessionDescription::kOffer));
953 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
954 session_id, session_version)) {
955 delete offer;
956 offer = NULL;
957 }
958 return offer;
959 }
960 JsepSessionDescription* CreateRemoteOffer(
961 cricket::MediaSessionOptions options) {
962 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
963 kSessionVersion, NULL);
964 }
965 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000966 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
967 return CreateRemoteOfferWithVersion(
968 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 }
970 JsepSessionDescription* CreateRemoteOffer(
971 cricket::MediaSessionOptions options,
972 const SessionDescriptionInterface* current_desc) {
973 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
974 kSessionVersion, current_desc);
975 }
976
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000977 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
978 const char* sctp_stream_name, int new_port,
979 cricket::MediaSessionOptions options) {
980 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000981 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
982 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000983 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
984 }
985
986 // Takes ownership of offer_basis (and deletes it).
987 JsepSessionDescription* ChangeSDPSctpPort(
988 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
989 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
990 // SessionDescription from the mutated string.
991 const char* default_port_str = "5000";
992 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000993 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000994 std::string offer_str;
995 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000996 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000997 new_port_str, strlen(new_port_str),
998 &offer_str);
999 JsepSessionDescription* offer = new JsepSessionDescription(
1000 offer_basis->type());
1001 delete offer_basis;
1002 offer->Initialize(offer_str, NULL);
1003 return offer;
1004 }
1005
deadbeefab9b2d12015-10-14 11:33:11 -07001006 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007 // before this function to decide which streams to create.
1008 JsepSessionDescription* CreateRemoteOffer() {
1009 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001010 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011 return CreateRemoteOffer(options, session_->remote_description());
1012 }
1013
1014 JsepSessionDescription* CreateRemoteAnswer(
1015 const SessionDescriptionInterface* offer,
1016 cricket::MediaSessionOptions options,
1017 cricket::SecurePolicy policy) {
1018 desc_factory_->set_secure(policy);
1019 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001020 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001021 JsepSessionDescription* answer(
1022 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1023 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1024 options, NULL),
1025 session_id, kSessionVersion)) {
1026 delete answer;
1027 answer = NULL;
1028 }
1029 return answer;
1030 }
1031
1032 JsepSessionDescription* CreateRemoteAnswer(
1033 const SessionDescriptionInterface* offer,
1034 cricket::MediaSessionOptions options) {
1035 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1036 }
1037
deadbeefab9b2d12015-10-14 11:33:11 -07001038 // Creates an answer session description.
1039 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001040 // to decide which streams to create.
1041 JsepSessionDescription* CreateRemoteAnswer(
1042 const SessionDescriptionInterface* offer) {
1043 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001044 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1046 }
1047
1048 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001049 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001050 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001051 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001052
1053 PeerConnectionInterface::RTCOfferAnswerOptions options;
1054 options.use_rtp_mux = bundle;
1055
1056 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1058 // and answer.
1059 SetLocalDescriptionWithoutError(offer);
1060
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001061 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001062 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 std::string sdp;
1064 EXPECT_TRUE(answer->ToString(&sdp));
1065
1066 size_t expected_candidate_num = 2;
1067 if (!rtcp_mux) {
1068 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1069 // for rtp and rtcp.
1070 expected_candidate_num = 4;
1071 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 const std::string kRtcpMux = "a=rtcp-mux";
1073 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001074 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 kXRtcpMux.c_str(), kXRtcpMux.length(),
1076 &sdp);
1077 }
1078
1079 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1080 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001081
1082 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001083 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1085 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001086 if (bundle) {
1087 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1088 } else {
1089 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001090 }
1091 }
1092 // Tests that we can only send DTMF when the dtmf codec is supported.
1093 void TestCanInsertDtmf(bool can) {
1094 if (can) {
1095 InitWithDtmfCodec();
1096 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001097 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098 }
deadbeefab9b2d12015-10-14 11:33:11 -07001099 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 CreateAndSetRemoteOfferAndLocalAnswer();
1101 EXPECT_FALSE(session_->CanInsertDtmf(""));
1102 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1103 }
1104
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001105 // Helper class to configure loopback network and verify Best
1106 // Connection using right IP protocol for TestLoopbackCall
1107 // method. LoopbackNetworkManager applies firewall rules to block
1108 // all ping traffic once ICE completed, and remove them to observe
1109 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1110 // verifies the best connection is using the right IP protocol after
1111 // initial ICE convergences.
1112
1113 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001114 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001115 LoopbackNetworkConfiguration()
1116 : test_ipv6_network_(false),
1117 test_extra_ipv4_network_(false),
1118 best_connection_after_initial_ice_converged_(1, 0) {}
1119
1120 // Used to track the expected best connection count in each IP protocol.
1121 struct ExpectedBestConnection {
1122 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1123 : ipv4_count_(ipv4_count),
1124 ipv6_count_(ipv6_count) {}
1125
1126 int ipv4_count_;
1127 int ipv6_count_;
1128 };
1129
1130 bool test_ipv6_network_;
1131 bool test_extra_ipv4_network_;
1132 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1133
1134 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001135 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001136 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1137 }
1138
1139 private:
jbauchac8869e2015-07-03 01:36:14 -07001140 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001141 const ExpectedBestConnection& expected) const {
1142 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001143 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1144 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001145 expected.ipv4_count_);
1146 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001147 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1148 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001149 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001150 // This is used in the loopback call so there is only single host to host
1151 // candidate pair.
1152 EXPECT_EQ(metrics_observer->GetEnumCounter(
1153 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1154 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001155 0);
1156 EXPECT_EQ(metrics_observer->GetEnumCounter(
1157 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1158 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001159 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001160 }
1161 };
1162
1163 class LoopbackNetworkManager {
1164 public:
1165 LoopbackNetworkManager(WebRtcSessionTest* session,
1166 const LoopbackNetworkConfiguration& config)
1167 : config_(config) {
1168 session->AddInterface(
1169 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1170 if (config_.test_extra_ipv4_network_) {
1171 session->AddInterface(
1172 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1173 }
1174 if (config_.test_ipv6_network_) {
1175 session->AddInterface(
1176 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1177 }
1178 }
1179
1180 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1181 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1182 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1183 if (config_.test_extra_ipv4_network_) {
1184 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1185 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1186 }
1187 if (config_.test_ipv6_network_) {
1188 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1189 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1190 }
1191 }
1192
1193 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1194
1195 private:
1196 LoopbackNetworkConfiguration config_;
1197 };
1198
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001199 // The method sets up a call from the session to itself, in a loopback
1200 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001201 // disconnection, and then a permanent disconnection.
1202 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001203 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1204 // While running the call, this method also checks if the session goes through
1205 // the correct sequence of ICE states when a connection is established,
1206 // broken, and re-established.
1207 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001208 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1209 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001210 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001211
stefanc1aeaf02015-10-15 07:26:07 -07001212 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001213 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001214 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001215 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001216
1217 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1218 observer_.ice_gathering_state_);
1219 SetLocalDescriptionWithoutError(offer);
1220 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1221 observer_.ice_connection_state_);
1222 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001223 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001224 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1225 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001226 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001227
1228 std::string sdp;
1229 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001230 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1231 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 ASSERT_TRUE(desc != NULL);
1233 SetRemoteDescriptionWithoutError(desc);
1234
1235 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001236 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001237
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001238 // The ice connection state is "Connected" too briefly to catch in a test.
1239 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001240 observer_.ice_connection_state_, kIceCandidatesTimeout);
1241 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001242
stefanc1aeaf02015-10-15 07:26:07 -07001243 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1244 LoopbackNetworkManager loopback_network_manager(this, config);
1245 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001246 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001247 // Adding firewall rule to block ping requests, which should cause
1248 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001249
1250 loopback_network_manager.ApplyFirewallRules(fss_.get());
1251
1252 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001253 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1254 observer_.ice_connection_state_,
1255 kIceCandidatesTimeout);
1256
jbauchac8869e2015-07-03 01:36:14 -07001257 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001258
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001259 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001260 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001261
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001262 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001263 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264 observer_.ice_connection_state_,
1265 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001266
1267 // Now we block ping requests and wait until the ICE connection transitions
1268 // to the Failed state. This will take at least 30 seconds because it must
1269 // wait for the Port to timeout.
1270 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001271
1272 loopback_network_manager.ApplyFirewallRules(fss_.get());
1273 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001274 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001275 observer_.ice_connection_state_,
1276 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277 }
1278
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001279 void TestLoopbackCall() {
1280 LoopbackNetworkConfiguration config;
1281 TestLoopbackCall(config);
1282 }
1283
stefanc1aeaf02015-10-15 07:26:07 -07001284 void TestPacketOptions() {
1285 media_controller_.reset(
1286 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1287 LoopbackNetworkConfiguration config;
1288 LoopbackNetworkManager loopback_network_manager(this, config);
1289
1290 SetupLoopbackCall();
1291
1292 uint8_t test_packet[15] = {0};
1293 rtc::PacketOptions options;
1294 options.packet_id = 10;
1295 media_engine_->GetVideoChannel(0)
1296 ->SendRtp(test_packet, sizeof(test_packet), options);
1297
1298 const int kPacketTimeout = 2000;
1299 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1300 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1301 }
1302
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001303 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1304 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001305 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1306 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1307
1308 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001309 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1310 codecs.push_back(kCNCodec1);
1311 codecs.push_back(kCNCodec2);
1312 media_engine_->SetAudioCodecs(codecs);
1313 desc_factory_->set_audio_codecs(codecs);
1314 }
1315
1316 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1317 const cricket::ContentDescription* description = content->description;
1318 ASSERT(description != NULL);
1319 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001320 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001321 ASSERT(audio_content_desc != NULL);
1322 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1323 if (audio_content_desc->codecs()[i].name == "CN")
1324 return false;
1325 }
1326 return true;
1327 }
1328
deadbeefab9b2d12015-10-14 11:33:11 -07001329 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001330 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001331 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001332 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1333 data_channel_ = DataChannel::Create(
1334 session_.get(), session_->data_channel_type(), "datachannel", dci);
1335 }
1336
1337 void SetLocalDescriptionWithDataChannel() {
1338 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001339 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001340 SetLocalDescriptionWithoutError(offer);
1341 }
1342
wu@webrtc.org91053e72013-08-10 07:18:04 +00001343 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001344 RTCCertificateGenerationMethod cert_gen_method,
1345 CreateSessionDescriptionRequest::Type type) {
1346 InitWithDtls(cert_gen_method);
1347 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1348 }
1349
1350 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1351 CreateSessionDescriptionRequest::Type type) {
1352 InitWithDtlsIdentityGenFail();
1353 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1354 }
1355
1356 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001357 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001358 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001359 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001360 if (type == CreateSessionDescriptionRequest::kAnswer) {
1361 cricket::MediaSessionOptions options;
1362 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001363 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001364 ASSERT_TRUE(offer.get() != NULL);
1365 SetRemoteDescriptionWithoutError(offer.release());
1366 }
1367
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001368 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001369 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001370 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001371 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001372 observers[kNumber];
1373 for (int i = 0; i < kNumber; ++i) {
1374 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1375 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001376 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001377 } else {
htaa2a49d92016-03-04 02:51:39 -08001378 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001379 }
1380 }
1381
1382 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1383 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1384 WebRtcSessionCreateSDPObserverForTest::kFailed;
1385
1386 for (int i = 0; i < kNumber; ++i) {
1387 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1388 if (success) {
1389 EXPECT_TRUE(observers[i]->description() != NULL);
1390 } else {
1391 EXPECT_TRUE(observers[i]->description() == NULL);
1392 }
1393 }
1394 }
1395
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001396 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001397 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001398 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001399 turn_server.credentials = credentials;
1400 turn_server.ports.push_back(
1401 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1402 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001403 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001404 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001405 }
1406
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407 cricket::FakeMediaEngine* media_engine_;
1408 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001409 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001410 cricket::FakeCall fake_call_;
1411 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001412 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001413 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1414 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1415 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1416 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1417 rtc::SocketServerScope ss_scope_;
1418 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001419 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001420 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001421 rtc::FakeNetworkManager network_manager_;
1422 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001423 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001424 PeerConnectionInterface::RTCConfiguration configuration_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001425 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 MockIceObserver observer_;
1427 cricket::FakeVideoMediaChannel* video_channel_;
1428 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001429 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001430 // The following flags affect options created for CreateOffer/CreateAnswer.
1431 bool send_stream_1_ = false;
1432 bool send_stream_2_ = false;
1433 bool send_audio_ = false;
1434 bool send_video_ = false;
1435 rtc::scoped_refptr<DataChannel> data_channel_;
1436 // Last values received from data channel creation signal.
1437 std::string last_data_channel_label_;
1438 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001439 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001440};
1441
Henrik Boström87713d02015-08-25 09:53:21 +02001442TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1443 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001444 // SDES is disabled when DTLS is on.
1445 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446}
1447
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001448TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001449 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001450 // SDES is required if DTLS is off.
1451 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001452}
1453
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1455 TestSessionCandidatesWithBundleRtcpMux(false, false);
1456}
1457
1458// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1459// with rtcp-mux and/or bundle.
1460TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1461 TestSessionCandidatesWithBundleRtcpMux(false, true);
1462}
1463
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1465 TestSessionCandidatesWithBundleRtcpMux(true, true);
1466}
1467
1468TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001469 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1470 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001471 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001472 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473 InitiateCall();
1474 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1475 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1476 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1477}
1478
minyuec8930ba2016-01-22 06:17:46 -08001479// Crashes on Win only. See webrtc:5411.
1480#if defined(WEBRTC_WIN)
1481#define MAYBE_TestStunError DISABLED_TestStunError
1482#else
1483#define MAYBE_TestStunError TestStunError
1484#endif
1485TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001486 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1487 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001488 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001489 rtc::FP_UDP,
1490 rtc::FD_ANY,
1491 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001492 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001493 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001494 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001495 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001496 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1497 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1498 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1499}
1500
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001501// Test session delivers no candidates gathered when constraint set to "none".
1502TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1503 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001504 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001505 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001506 InitiateCall();
1507 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1508 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1509 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1510}
1511
1512// Test session delivers only relay candidates gathered when constaint set to
1513// "relay".
1514TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1515 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1516 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001517 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001518 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001519 InitiateCall();
1520 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1521 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1522 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1523 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1524 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1525 observer_.mline_0_candidates_[i].type());
1526 }
1527 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1528 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1529 observer_.mline_1_candidates_[i].type());
1530 }
1531}
1532
1533// Test session delivers all candidates gathered when constaint set to "all".
1534TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1535 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001536 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001537 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001538 InitiateCall();
1539 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1540 // Host + STUN. By default allocator is disabled to gather relay candidates.
1541 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1542 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1543}
1544
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001545TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001546 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001547 SessionDescriptionInterface* offer = NULL;
1548 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1549 std::string unknown_action;
1550 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1551 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1552}
1553
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554// Test creating offers and receive answers and make sure the
1555// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001556TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001557 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001558 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001559 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560 const std::string session_id_orig = offer->session_id();
1561 const std::string session_version_orig = offer->session_version();
1562 SetLocalDescriptionWithoutError(offer);
1563
deadbeefab9b2d12015-10-14 11:33:11 -07001564 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565 SessionDescriptionInterface* answer =
1566 CreateRemoteAnswer(session_->local_description());
1567 SetRemoteDescriptionWithoutError(answer);
1568
1569 video_channel_ = media_engine_->GetVideoChannel(0);
1570 voice_channel_ = media_engine_->GetVoiceChannel(0);
1571
1572 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1573 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1574
1575 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1576 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1577
1578 ASSERT_EQ(1u, video_channel_->send_streams().size());
1579 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1580 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1581 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1582
1583 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001584 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001585 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586
1587 // Verify the session id is the same and the session version is
1588 // increased.
1589 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001590 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1591 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592
1593 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001594 EXPECT_EQ(0u, video_channel_->send_streams().size());
1595 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596
deadbeefab9b2d12015-10-14 11:33:11 -07001597 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 answer = CreateRemoteAnswer(session_->local_description());
1599 SetRemoteDescriptionWithoutError(answer);
1600
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 // Make sure the receive streams have not changed.
1602 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1603 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1604 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1605 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1606}
1607
1608// Test receiving offers and creating answers and make sure the
1609// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001610TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001611 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001612 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001613 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001614 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 SetRemoteDescriptionWithoutError(offer);
1616
deadbeefab9b2d12015-10-14 11:33:11 -07001617 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001618 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001619 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001620 SetLocalDescriptionWithoutError(answer);
1621
1622 const std::string session_id_orig = answer->session_id();
1623 const std::string session_version_orig = answer->session_version();
1624
1625 video_channel_ = media_engine_->GetVideoChannel(0);
1626 voice_channel_ = media_engine_->GetVoiceChannel(0);
1627
htaa2a49d92016-03-04 02:51:39 -08001628 ASSERT_TRUE(video_channel_);
1629 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1631 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1632
1633 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1634 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1635
1636 ASSERT_EQ(1u, video_channel_->send_streams().size());
1637 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1638 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1639 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1640
deadbeefab9b2d12015-10-14 11:33:11 -07001641 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001642 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643 SetRemoteDescriptionWithoutError(offer);
1644
1645 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001646 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001647 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648
1649 // Verify the session id is the same and the session version is
1650 // increased.
1651 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001652 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1653 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 SetLocalDescriptionWithoutError(answer);
1655
1656 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1657 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1658 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1659 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1660 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1661 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1662
1663 // Make sure we have no send streams.
1664 EXPECT_EQ(0u, video_channel_->send_streams().size());
1665 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1666}
1667
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001668TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001669 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001670 media_engine_->set_fail_create_channel(true);
1671
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001672 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001673 ASSERT_TRUE(offer != NULL);
1674 // SetRemoteDescription and SetLocalDescription will take the ownership of
1675 // the offer.
1676 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001677 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001678 ASSERT_TRUE(offer != NULL);
1679 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1680}
1681
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001682//
1683// Tests for creating/setting SDP under different SDES/DTLS polices:
1684//
1685// --DTLS off and SDES on
1686// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1687// set local/remote offer/answer with crypto --> success
1688// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1689// failure
1690// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1691// failure
1692// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1693// failure
1694//
1695// --DTLS on and SDES off
1696// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1697// set local/remote offer/answer with DTLS fingerprint --> success
1698// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1699// fingerprint --> failure
1700// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1701// --> failure
1702// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1703// --> failure
1704//
1705// --Encryption disabled: DTLS off and SDES off
1706// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1707// answer without SDES or DTLS --> success
1708// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1709// answer without SDES or DTLS --> success
1710//
1711
1712// Test that we return a failure when applying a remote/local offer that doesn't
1713// have cryptos enabled when DTLS is off.
1714TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001715 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001717 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 JsepSessionDescription* offer = CreateRemoteOffer(
1719 options, cricket::SEC_DISABLED);
1720 ASSERT_TRUE(offer != NULL);
1721 VerifyNoCryptoParams(offer->description(), false);
1722 // SetRemoteDescription and SetLocalDescription will take the ownership of
1723 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001724 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1726 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001727 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728}
1729
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001730// Test that we return a failure when applying a local answer that doesn't have
1731// cryptos enabled when DTLS is off.
1732TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001733 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001734 SessionDescriptionInterface* offer = NULL;
1735 SessionDescriptionInterface* answer = NULL;
1736 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1737 // SetRemoteDescription and SetLocalDescription will take the ownership of
1738 // the offer.
1739 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001740 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741}
1742
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001743// Test we will return fail when apply an remote answer that doesn't have
1744// crypto enabled when DTLS is off.
1745TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001746 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747 SessionDescriptionInterface* offer = NULL;
1748 SessionDescriptionInterface* answer = NULL;
1749 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1750 // SetRemoteDescription and SetLocalDescription will take the ownership of
1751 // the offer.
1752 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001753 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754}
1755
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001756// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1757// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001758TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001759 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001760 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001761 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762 SetFactoryDtlsSrtp();
1763 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001764 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001765 JsepSessionDescription* offer =
1766 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 ASSERT_TRUE(offer != NULL);
1768 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001769 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770
1771 // SetRemoteDescription will take the ownership of the offer.
1772 SetRemoteDescriptionWithoutError(offer);
1773
1774 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001775 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 ASSERT_TRUE(answer != NULL);
1777 VerifyFingerprintStatus(answer->description(), true);
1778 // Check that we don't have an a=crypto line in the answer.
1779 VerifyNoCryptoParams(answer->description(), true);
1780
1781 // Now set the local description, which should work, even without a=crypto.
1782 SetLocalDescriptionWithoutError(answer);
1783}
1784
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001785// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1786// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001787TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001788 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001789 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001790 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001791 SetFactoryDtlsSrtp();
1792
1793 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001794 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001795 ASSERT_TRUE(offer != NULL);
1796 VerifyFingerprintStatus(offer->description(), true);
1797 // Check that we don't have an a=crypto line in the offer.
1798 VerifyNoCryptoParams(offer->description(), true);
1799
1800 // Now set the local description, which should work, even without a=crypto.
1801 SetLocalDescriptionWithoutError(offer);
1802
1803 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001804 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001805 JsepSessionDescription* answer =
1806 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1807 ASSERT_TRUE(answer != NULL);
1808 VerifyFingerprintStatus(answer->description(), true);
1809 VerifyNoCryptoParams(answer->description(), true);
1810
1811 // SetRemoteDescription will take the ownership of the answer.
1812 SetRemoteDescriptionWithoutError(answer);
1813}
1814
1815// Test that if we support DTLS and the other side didn't offer a fingerprint,
1816// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001817TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001818 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001819 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001821 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001822 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 JsepSessionDescription* offer = CreateRemoteOffer(
1824 options, cricket::SEC_REQUIRED);
1825 ASSERT_TRUE(offer != NULL);
1826 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001827 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001829 // SetRemoteDescription will take the ownership of the offer.
1830 SetRemoteDescriptionOfferExpectError(
1831 kSdpWithoutDtlsFingerprint, offer);
1832
1833 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1834 // SetLocalDescription will take the ownership of the offer.
1835 SetLocalDescriptionOfferExpectError(
1836 kSdpWithoutDtlsFingerprint, offer);
1837}
1838
1839// Test that we return a failure when applying a local answer that doesn't have
1840// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001841TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001842 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001843 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001844 SessionDescriptionInterface* offer = NULL;
1845 SessionDescriptionInterface* answer = NULL;
1846 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1847
1848 // SetRemoteDescription and SetLocalDescription will take the ownership of
1849 // the offer and answer.
1850 SetRemoteDescriptionWithoutError(offer);
1851 SetLocalDescriptionAnswerExpectError(
1852 kSdpWithoutDtlsFingerprint, answer);
1853}
1854
1855// Test that we return a failure when applying a remote answer that doesn't have
1856// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001857TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001858 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001859 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001860 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001861 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001862 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001863 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1864 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001865 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001866 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001867
1868 // SetRemoteDescription and SetLocalDescription will take the ownership of
1869 // the offer and answer.
1870 SetLocalDescriptionWithoutError(offer);
1871 SetRemoteDescriptionAnswerExpectError(
1872 kSdpWithoutDtlsFingerprint, answer);
1873}
1874
1875// Test that we create a local offer without SDES or DTLS and accept a remote
1876// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001877TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001878 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001879 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001880 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001881
1882 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001883 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001884 ASSERT_TRUE(offer != NULL);
1885 VerifyFingerprintStatus(offer->description(), false);
1886 // Check that we don't have an a=crypto line in the offer.
1887 VerifyNoCryptoParams(offer->description(), false);
1888
1889 // Now set the local description, which should work, even without a=crypto.
1890 SetLocalDescriptionWithoutError(offer);
1891
1892 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001893 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001894 JsepSessionDescription* answer =
1895 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1896 ASSERT_TRUE(answer != NULL);
1897 VerifyFingerprintStatus(answer->description(), false);
1898 VerifyNoCryptoParams(answer->description(), false);
1899
1900 // SetRemoteDescription will take the ownership of the answer.
1901 SetRemoteDescriptionWithoutError(answer);
1902}
1903
1904// Test that we create a local answer without SDES or DTLS and accept a remote
1905// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001906TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001907 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001908 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001909
1910 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001911 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001912 JsepSessionDescription* offer =
1913 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1914 ASSERT_TRUE(offer != NULL);
1915 VerifyFingerprintStatus(offer->description(), false);
1916 VerifyNoCryptoParams(offer->description(), false);
1917
1918 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001919 SetRemoteDescriptionWithoutError(offer);
1920
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001921 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001922 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001923 ASSERT_TRUE(answer != NULL);
1924 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001925 // Check that we don't have an a=crypto line in the answer.
1926 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001928 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001929 SetLocalDescriptionWithoutError(answer);
1930}
1931
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001932// Test that we can create and set an answer correctly when different
1933// SSL roles have been negotiated for different transports.
1934// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1935TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1936 SendAudioVideoStream1();
1937 InitWithDtls(GetParam());
1938 SetFactoryDtlsSrtp();
1939
1940 SessionDescriptionInterface* offer = CreateOffer();
1941 SetLocalDescriptionWithoutError(offer);
1942
1943 cricket::MediaSessionOptions options;
1944 options.recv_video = true;
1945
1946 // First, negotiate different SSL roles.
1947 SessionDescriptionInterface* answer =
1948 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1949 TransportInfo* audio_transport_info =
1950 answer->description()->GetTransportInfoByName("audio");
1951 audio_transport_info->description.connection_role =
1952 cricket::CONNECTIONROLE_ACTIVE;
1953 TransportInfo* video_transport_info =
1954 answer->description()->GetTransportInfoByName("video");
1955 video_transport_info->description.connection_role =
1956 cricket::CONNECTIONROLE_PASSIVE;
1957 SetRemoteDescriptionWithoutError(answer);
1958
1959 // Now create an offer in the reverse direction, and ensure the initial
1960 // offerer responds with an answer with correct SSL roles.
1961 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1962 kSessionVersion,
1963 session_->remote_description());
1964 SetRemoteDescriptionWithoutError(offer);
1965
htaa2a49d92016-03-04 02:51:39 -08001966 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001967 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1968 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1969 audio_transport_info->description.connection_role);
1970 video_transport_info = answer->description()->GetTransportInfoByName("video");
1971 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1972 video_transport_info->description.connection_role);
1973 SetLocalDescriptionWithoutError(answer);
1974
1975 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1976 // audio is transferred over to video in the answer that completes the BUNDLE
1977 // negotiation.
1978 options.bundle_enabled = true;
1979 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1980 kSessionVersion,
1981 session_->remote_description());
1982 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08001983 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001984 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1985 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1986 audio_transport_info->description.connection_role);
1987 video_transport_info = answer->description()->GetTransportInfoByName("video");
1988 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1989 video_transport_info->description.connection_role);
1990 SetLocalDescriptionWithoutError(answer);
1991}
1992
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001993TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001994 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001995 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001997 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 SetLocalDescriptionWithoutError(offer);
1999
2000 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002001 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 SetLocalDescriptionWithoutError(offer2);
2003}
2004
2005TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002006 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002007 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002009 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010 SetRemoteDescriptionWithoutError(offer);
2011
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002012 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013 SetRemoteDescriptionWithoutError(offer2);
2014}
2015
2016TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002017 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002018 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002019 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002021 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002022 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2023 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024}
2025
2026TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002027 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002028 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002029 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002031 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002032 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002033 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034}
2035
2036TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002037 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002038 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002040 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041
htaa2a49d92016-03-04 02:51:39 -08002042 JsepSessionDescription* pranswer =
2043 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002045 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046
deadbeefab9b2d12015-10-14 11:33:11 -07002047 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002048 JsepSessionDescription* pranswer2 =
2049 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002050 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2051
deadbeefd59daf82015-10-14 15:02:44 -07002052 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053
deadbeefab9b2d12015-10-14 11:33:11 -07002054 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002055 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002056 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057}
2058
2059TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002060 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002061 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002062 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002063 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064
2065 JsepSessionDescription* pranswer =
2066 CreateRemoteAnswer(session_->local_description());
2067 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2068
2069 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002070 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002071
deadbeefab9b2d12015-10-14 11:33:11 -07002072 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073 JsepSessionDescription* pranswer2 =
2074 CreateRemoteAnswer(session_->local_description());
2075 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2076
2077 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002078 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079
deadbeefab9b2d12015-10-14 11:33:11 -07002080 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002081 SessionDescriptionInterface* answer =
2082 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002083 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084}
2085
2086TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002087 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002088 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002089 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2090
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091 SessionDescriptionInterface* answer =
2092 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002093 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2094 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095}
2096
2097TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002098 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002099 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002100 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2101
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102 SessionDescriptionInterface* answer =
2103 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002104 SetRemoteDescriptionAnswerExpectError(
2105 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106}
2107
2108TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002109 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002110 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111
2112 cricket::Candidate candidate;
2113 candidate.set_component(1);
2114 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2115
deadbeefd59daf82015-10-14 15:02:44 -07002116 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2118
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002119 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002121
2122 // Fail since we have not set a remote description.
2123 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124
2125 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2126 session_->local_description());
2127 SetRemoteDescriptionWithoutError(answer);
2128
deadbeefd59daf82015-10-14 15:02:44 -07002129 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2130 candidate.set_component(2);
2131 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2132 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2133
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 // Verifying the candidates are copied properly from internal vector.
2135 const SessionDescriptionInterface* remote_desc =
2136 session_->remote_description();
2137 ASSERT_TRUE(remote_desc != NULL);
2138 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2139 const IceCandidateCollection* candidates =
2140 remote_desc->candidates(kMediaContentIndex0);
2141 ASSERT_EQ(2u, candidates->count());
2142 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2143 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2144 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2145 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2146
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002147 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2148 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 candidate.set_component(2);
2150 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2151 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002152 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153
2154 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2155 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2156}
2157
2158// Test that a remote candidate is added to the remote session description and
2159// that it is retained if the remote session description is changed.
2160TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002161 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002162 cricket::Candidate candidate1;
2163 candidate1.set_component(1);
2164 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2165 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002166 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167 CreateAndSetRemoteOfferAndLocalAnswer();
2168
2169 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2170 const SessionDescriptionInterface* remote_desc =
2171 session_->remote_description();
2172 ASSERT_TRUE(remote_desc != NULL);
2173 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2174 const IceCandidateCollection* candidates =
2175 remote_desc->candidates(kMediaContentIndex0);
2176 ASSERT_EQ(1u, candidates->count());
2177 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2178
2179 // Update the RemoteSessionDescription with a new session description and
2180 // a candidate and check that the new remote session description contains both
2181 // candidates.
2182 SessionDescriptionInterface* offer = CreateRemoteOffer();
2183 cricket::Candidate candidate2;
2184 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2185 candidate2);
2186 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2187 SetRemoteDescriptionWithoutError(offer);
2188
2189 remote_desc = session_->remote_description();
2190 ASSERT_TRUE(remote_desc != NULL);
2191 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2192 candidates = remote_desc->candidates(kMediaContentIndex0);
2193 ASSERT_EQ(2u, candidates->count());
2194 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2195 // Username and password have be updated with the TransportInfo of the
2196 // SessionDescription, won't be equal to the original one.
2197 candidate2.set_username(candidates->at(0)->candidate().username());
2198 candidate2.set_password(candidates->at(0)->candidate().password());
2199 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2200 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2201 // No need to verify the username and password.
2202 candidate1.set_username(candidates->at(1)->candidate().username());
2203 candidate1.set_password(candidates->at(1)->candidate().password());
2204 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2205
2206 // Test that the candidate is ignored if we can add the same candidate again.
2207 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2208}
2209
2210// Test that local candidates are added to the local session description and
2211// that they are retained if the local session description is changed.
2212TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002213 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002214 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002215 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002216 CreateAndSetRemoteOfferAndLocalAnswer();
2217
2218 const SessionDescriptionInterface* local_desc = session_->local_description();
2219 const IceCandidateCollection* candidates =
2220 local_desc->candidates(kMediaContentIndex0);
2221 ASSERT_TRUE(candidates != NULL);
2222 EXPECT_EQ(0u, candidates->count());
2223
2224 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2225
2226 local_desc = session_->local_description();
2227 candidates = local_desc->candidates(kMediaContentIndex0);
2228 ASSERT_TRUE(candidates != NULL);
2229 EXPECT_LT(0u, candidates->count());
2230 candidates = local_desc->candidates(1);
2231 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002232 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233
2234 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002235 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002236 CreateAndSetRemoteOfferAndLocalAnswer();
2237
2238 local_desc = session_->local_description();
2239 candidates = local_desc->candidates(kMediaContentIndex0);
2240 ASSERT_TRUE(candidates != NULL);
2241 EXPECT_LT(0u, candidates->count());
2242 candidates = local_desc->candidates(1);
2243 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002244 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002245}
2246
2247// Test that we can set a remote session description with remote candidates.
2248TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002249 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250
2251 cricket::Candidate candidate1;
2252 candidate1.set_component(1);
2253 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2254 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002255 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002256 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257
2258 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2259 SetRemoteDescriptionWithoutError(offer);
2260
2261 const SessionDescriptionInterface* remote_desc =
2262 session_->remote_description();
2263 ASSERT_TRUE(remote_desc != NULL);
2264 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2265 const IceCandidateCollection* candidates =
2266 remote_desc->candidates(kMediaContentIndex0);
2267 ASSERT_EQ(1u, candidates->count());
2268 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2269
htaa2a49d92016-03-04 02:51:39 -08002270 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002271 SetLocalDescriptionWithoutError(answer);
2272}
2273
2274// Test that offers and answers contains ice candidates when Ice candidates have
2275// been gathered.
2276TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002277 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002278 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002279 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280 // Ice is started but candidates are not provided until SetLocalDescription
2281 // is called.
2282 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2283 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2284 CreateAndSetRemoteOfferAndLocalAnswer();
2285 // Wait until at least one local candidate has been collected.
2286 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2287 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002289 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2290
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2292 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002293
2294 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2295 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002296 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2298 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002299 SetLocalDescriptionWithoutError(answer);
2300}
2301
2302// Verifies TransportProxy and media channels are created with content names
2303// present in the SessionDescription.
2304TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002305 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002306 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002307 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002308
2309 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002310 // "video". Goal is to modify these content names and verify transport
2311 // channels
2312 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002313 // present in SDP.
2314 std::string sdp;
2315 EXPECT_TRUE(offer->ToString(&sdp));
2316 const std::string kAudioMid = "a=mid:audio";
2317 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2318 const std::string kVideoMid = "a=mid:video";
2319 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2320
2321 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002322 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323 kAudioMidReplaceStr.c_str(),
2324 kAudioMidReplaceStr.length(),
2325 &sdp);
2326 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002327 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328 kVideoMidReplaceStr.c_str(),
2329 kVideoMidReplaceStr.length(),
2330 &sdp);
2331
2332 SessionDescriptionInterface* modified_offer =
2333 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2334
2335 SetRemoteDescriptionWithoutError(modified_offer);
2336
htaa2a49d92016-03-04 02:51:39 -08002337 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338 SetLocalDescriptionWithoutError(answer);
2339
deadbeefcbecd352015-09-23 11:50:27 -07002340 cricket::TransportChannel* voice_transport_channel =
2341 session_->voice_rtp_transport_channel();
2342 EXPECT_TRUE(voice_transport_channel != NULL);
2343 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2344 cricket::TransportChannel* video_transport_channel =
2345 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002346 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002347 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2349 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2350}
2351
2352// Test that an offer contains the correct media content descriptions based on
2353// the send streams when no constraints have been set.
2354TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002355 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002356 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2357
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358 ASSERT_TRUE(offer != NULL);
2359 const cricket::ContentInfo* content =
2360 cricket::GetFirstAudioContent(offer->description());
2361 EXPECT_TRUE(content != NULL);
2362 content = cricket::GetFirstVideoContent(offer->description());
2363 EXPECT_TRUE(content == NULL);
2364}
2365
2366// Test that an offer contains the correct media content descriptions based on
2367// the send streams when no constraints have been set.
2368TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002369 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002371 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002372 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2373
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374 const cricket::ContentInfo* content =
2375 cricket::GetFirstAudioContent(offer->description());
2376 EXPECT_TRUE(content != NULL);
2377 content = cricket::GetFirstVideoContent(offer->description());
2378 EXPECT_TRUE(content == NULL);
2379
2380 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002381 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002382 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002383 content = cricket::GetFirstAudioContent(offer->description());
2384 EXPECT_TRUE(content != NULL);
2385 content = cricket::GetFirstVideoContent(offer->description());
2386 EXPECT_TRUE(content != NULL);
2387}
2388
2389// Test that an offer contains no media content descriptions if
2390// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2391TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002392 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002393 PeerConnectionInterface::RTCOfferAnswerOptions options;
2394 options.offer_to_receive_audio = 0;
2395 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002397 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002398 CreateOffer(options));
2399
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400 ASSERT_TRUE(offer != NULL);
2401 const cricket::ContentInfo* content =
2402 cricket::GetFirstAudioContent(offer->description());
2403 EXPECT_TRUE(content == NULL);
2404 content = cricket::GetFirstVideoContent(offer->description());
2405 EXPECT_TRUE(content == NULL);
2406}
2407
2408// Test that an offer contains only audio media content descriptions if
2409// kOfferToReceiveAudio constraints are set to true.
2410TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002411 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002412 PeerConnectionInterface::RTCOfferAnswerOptions options;
2413 options.offer_to_receive_audio =
2414 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2415
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002416 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002417 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418
2419 const cricket::ContentInfo* content =
2420 cricket::GetFirstAudioContent(offer->description());
2421 EXPECT_TRUE(content != NULL);
2422 content = cricket::GetFirstVideoContent(offer->description());
2423 EXPECT_TRUE(content == NULL);
2424}
2425
2426// Test that an offer contains audio and video media content descriptions if
2427// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2428TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002429 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002431 PeerConnectionInterface::RTCOfferAnswerOptions options;
2432 options.offer_to_receive_audio =
2433 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2434 options.offer_to_receive_video =
2435 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2436
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002437 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002438 CreateOffer(options));
2439
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002440 const cricket::ContentInfo* content =
2441 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002442 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002443
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444 content = cricket::GetFirstVideoContent(offer->description());
2445 EXPECT_TRUE(content != NULL);
2446
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002447 // Sets constraints to false and verifies that audio/video contents are
2448 // removed.
2449 options.offer_to_receive_audio = 0;
2450 options.offer_to_receive_video = 0;
2451 offer.reset(CreateOffer(options));
2452
2453 content = cricket::GetFirstAudioContent(offer->description());
2454 EXPECT_TRUE(content == NULL);
2455 content = cricket::GetFirstVideoContent(offer->description());
2456 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002457}
2458
2459// Test that an answer can not be created if the last remote description is not
2460// an offer.
2461TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002462 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002463 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002464 SetLocalDescriptionWithoutError(offer);
2465 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2466 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002467 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002468}
2469
2470// Test that an answer contains the correct media content descriptions when no
2471// constraints have been set.
2472TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002473 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002474 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002475 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -08002477 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478 const cricket::ContentInfo* content =
2479 cricket::GetFirstAudioContent(answer->description());
2480 ASSERT_TRUE(content != NULL);
2481 EXPECT_FALSE(content->rejected);
2482
2483 content = cricket::GetFirstVideoContent(answer->description());
2484 ASSERT_TRUE(content != NULL);
2485 EXPECT_FALSE(content->rejected);
2486}
2487
2488// Test that an answer contains the correct media content descriptions when no
2489// constraints have been set and the offer only contain audio.
2490TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002491 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002492 // Create a remote offer with audio only.
2493 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002494
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002495 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002496 CreateRemoteOffer(options));
2497 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2498 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2499
2500 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -08002501 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 const cricket::ContentInfo* content =
2503 cricket::GetFirstAudioContent(answer->description());
2504 ASSERT_TRUE(content != NULL);
2505 EXPECT_FALSE(content->rejected);
2506
2507 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2508}
2509
2510// Test that an answer contains the correct media content descriptions when no
2511// constraints have been set.
2512TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002513 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002514 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002515 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516 SetRemoteDescriptionWithoutError(offer.release());
2517 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002518 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002519 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520 const cricket::ContentInfo* content =
2521 cricket::GetFirstAudioContent(answer->description());
2522 ASSERT_TRUE(content != NULL);
2523 EXPECT_FALSE(content->rejected);
2524
2525 content = cricket::GetFirstVideoContent(answer->description());
2526 ASSERT_TRUE(content != NULL);
2527 EXPECT_FALSE(content->rejected);
2528}
2529
2530// Test that an answer contains the correct media content descriptions when
2531// constraints have been set but no stream is sent.
2532TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002533 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002534 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002535 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002536 SetRemoteDescriptionWithoutError(offer.release());
2537
htaa2a49d92016-03-04 02:51:39 -08002538 cricket::MediaSessionOptions session_options;
2539 session_options.recv_audio = false;
2540 session_options.recv_video = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002541 rtc::scoped_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002542 CreateAnswer(session_options));
2543
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544 const cricket::ContentInfo* content =
2545 cricket::GetFirstAudioContent(answer->description());
2546 ASSERT_TRUE(content != NULL);
2547 EXPECT_TRUE(content->rejected);
2548
2549 content = cricket::GetFirstVideoContent(answer->description());
2550 ASSERT_TRUE(content != NULL);
2551 EXPECT_TRUE(content->rejected);
2552}
2553
2554// Test that an answer contains the correct media content descriptions when
2555// constraints have been set and streams are sent.
2556TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002557 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002559 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002560 SetRemoteDescriptionWithoutError(offer.release());
2561
htaa2a49d92016-03-04 02:51:39 -08002562 cricket::MediaSessionOptions options;
2563 options.recv_audio = false;
2564 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002565
2566 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002567 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002568 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002569
2570 // TODO(perkj): Should the direction be set to SEND_ONLY?
2571 const cricket::ContentInfo* content =
2572 cricket::GetFirstAudioContent(answer->description());
2573 ASSERT_TRUE(content != NULL);
2574 EXPECT_FALSE(content->rejected);
2575
2576 // TODO(perkj): Should the direction be set to SEND_ONLY?
2577 content = cricket::GetFirstVideoContent(answer->description());
2578 ASSERT_TRUE(content != NULL);
2579 EXPECT_FALSE(content->rejected);
2580}
2581
2582TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2583 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002584 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002585 PeerConnectionInterface::RTCOfferAnswerOptions options;
2586 options.offer_to_receive_audio =
2587 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2588 options.voice_activity_detection = false;
2589
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002590 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002591 CreateOffer(options));
2592
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593 const cricket::ContentInfo* content =
2594 cricket::GetFirstAudioContent(offer->description());
2595 EXPECT_TRUE(content != NULL);
2596 EXPECT_TRUE(VerifyNoCNCodecs(content));
2597}
2598
2599TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2600 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002601 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002602 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002603 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002604 SetRemoteDescriptionWithoutError(offer.release());
2605
htaa2a49d92016-03-04 02:51:39 -08002606 cricket::MediaSessionOptions options;
2607 options.vad_enabled = false;
2608 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002609 const cricket::ContentInfo* content =
2610 cricket::GetFirstAudioContent(answer->description());
2611 ASSERT_TRUE(content != NULL);
2612 EXPECT_TRUE(VerifyNoCNCodecs(content));
2613}
2614
2615// This test verifies the call setup when remote answer with audio only and
2616// later updates with video.
2617TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002618 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002619 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2620 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2621
deadbeefab9b2d12015-10-14 11:33:11 -07002622 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002623 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002624
2625 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2627
2628 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2629 // and answer;
2630 SetLocalDescriptionWithoutError(offer);
2631 SetRemoteDescriptionWithoutError(answer);
2632
2633 video_channel_ = media_engine_->GetVideoChannel(0);
2634 voice_channel_ = media_engine_->GetVoiceChannel(0);
2635
2636 ASSERT_TRUE(video_channel_ == NULL);
2637
2638 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2639 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2640 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2641
2642 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002643 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002644 CreateAndSetRemoteOfferAndLocalAnswer();
2645
2646 video_channel_ = media_engine_->GetVideoChannel(0);
2647 voice_channel_ = media_engine_->GetVoiceChannel(0);
2648
2649 ASSERT_TRUE(video_channel_ != NULL);
2650 ASSERT_TRUE(voice_channel_ != NULL);
2651
2652 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2653 ASSERT_EQ(1u, video_channel_->send_streams().size());
2654 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2655 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2656 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2657 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2658 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2659 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2660
2661 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002662 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002663 CreateAndSetRemoteOfferAndLocalAnswer();
2664
2665 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2666 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2667 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2668 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2669 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2670}
2671
2672// This test verifies the call setup when remote answer with video only and
2673// later updates with audio.
2674TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002675 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002676 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2677 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002678 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002679 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002680
2681 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002682 options.recv_audio = false;
2683 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002684 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2685 offer, options, cricket::SEC_ENABLED);
2686
2687 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2688 // and answer.
2689 SetLocalDescriptionWithoutError(offer);
2690 SetRemoteDescriptionWithoutError(answer);
2691
2692 video_channel_ = media_engine_->GetVideoChannel(0);
2693 voice_channel_ = media_engine_->GetVoiceChannel(0);
2694
2695 ASSERT_TRUE(voice_channel_ == NULL);
2696 ASSERT_TRUE(video_channel_ != NULL);
2697
2698 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2699 ASSERT_EQ(1u, video_channel_->send_streams().size());
2700 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2701
2702 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002703 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002704 CreateAndSetRemoteOfferAndLocalAnswer();
2705
2706 voice_channel_ = media_engine_->GetVoiceChannel(0);
2707 ASSERT_TRUE(voice_channel_ != NULL);
2708
2709 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2710 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2711 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2712 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2713
2714 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002715 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002716 CreateAndSetRemoteOfferAndLocalAnswer();
2717
2718 video_channel_ = media_engine_->GetVideoChannel(0);
2719 voice_channel_ = media_engine_->GetVoiceChannel(0);
2720
2721 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2722 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2723 ASSERT_EQ(1u, video_channel_->send_streams().size());
2724 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2725}
2726
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002727TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002728 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002729 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002730 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002731 VerifyCryptoParams(offer->description());
2732 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -08002733 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002734 VerifyCryptoParams(answer->description());
2735}
2736
2737TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002738 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002739 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002740 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002741 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002742 VerifyNoCryptoParams(offer->description(), false);
2743}
2744
2745TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002746 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002747 VerifyAnswerFromNonCryptoOffer();
2748}
2749
2750TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002751 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002752 VerifyAnswerFromCryptoOffer();
2753}
2754
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002755// This test verifies that setLocalDescription fails if
2756// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2757TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002758 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002759 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002760 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2761
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002762 std::string sdp;
2763 RemoveIceUfragPwdLines(offer.get(), &sdp);
2764 SessionDescriptionInterface* modified_offer =
2765 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002766 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002767}
2768
2769// This test verifies that setRemoteDescription fails if
2770// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2771TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002772 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002773 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002774 std::string sdp;
2775 RemoveIceUfragPwdLines(offer.get(), &sdp);
2776 SessionDescriptionInterface* modified_offer =
2777 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002778 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002779}
2780
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002781// This test verifies that setLocalDescription fails if local offer has
2782// too short ice ufrag and pwd strings.
2783TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002784 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002785 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002786 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002787 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2788 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002789 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002790 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002791 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002792
2793 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002794 offer.reset(CreateOffer());
2795 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2796 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002797}
2798
2799// This test verifies that setRemoteDescription fails if remote offer has
2800// too short ice ufrag and pwd strings.
2801TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002802 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002803 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002804 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2805 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002806 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002807 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002808 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002809
deadbeef0ed85b22016-02-23 17:24:52 -08002810 offer.reset(CreateRemoteOffer());
2811 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2812 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002813}
2814
Honghai Zhang04e91462015-12-11 14:26:22 -08002815// Test that if the remote offer indicates the peer requested ICE restart (via
2816// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2817TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002818 Init();
honghaiz503726c2015-07-31 12:37:38 -07002819
2820 // Create the first offer.
deadbeef0ed85b22016-02-23 17:24:52 -08002821 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2822 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002823 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2824 0, "", "", "relay", 0, "");
2825 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2826 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002827 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2828 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002829 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2830
2831 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002832 offer.reset(CreateRemoteOffer());
2833 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002834 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2835 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2836 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002837 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2838 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002839 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2840
2841 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002842 offer.reset(CreateRemoteOffer());
2843 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002844 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2845 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2846 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002847 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2848 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002849 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2850
2851 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002852 offer.reset(CreateRemoteOffer());
2853 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2854 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002855 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2856}
2857
Honghai Zhang04e91462015-12-11 14:26:22 -08002858// Test that if the remote answer indicates the peer requested ICE restart (via
2859// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2860TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2861 Init();
2862 SessionDescriptionInterface* offer = CreateOffer();
2863 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002864
2865 // Create the first answer.
deadbeef0ed85b22016-02-23 17:24:52 -08002866 scoped_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
2867 answer->set_type(JsepSessionDescription::kPrAnswer);
2868 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002869 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2870 0, "", "", "relay", 0, "");
2871 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2872 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002873 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2874 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002875 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2876
2877 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002878 answer.reset(CreateRemoteAnswer(offer));
2879 answer->set_type(JsepSessionDescription::kPrAnswer);
2880 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002881 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2882 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2883 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002884 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2885 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002886 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2887
2888 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002889 answer.reset(CreateRemoteAnswer(offer));
2890 answer->set_type(JsepSessionDescription::kPrAnswer);
2891 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002892 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2893 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2894 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002895 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2896 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002897 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2898
2899 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002900 answer.reset(CreateRemoteAnswer(offer));
2901 answer->set_type(JsepSessionDescription::kPrAnswer);
2902 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2903 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002904 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2905}
2906
Donald Curtisd4f769d2015-05-28 09:48:21 -07002907// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002908// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002909TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2910 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2911
2912 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002913 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002914
2915 PeerConnectionInterface::RTCOfferAnswerOptions options;
2916 options.use_rtp_mux = true;
2917
2918 SessionDescriptionInterface* offer = CreateRemoteOffer();
2919 SetRemoteDescriptionWithoutError(offer);
2920
htaa2a49d92016-03-04 02:51:39 -08002921 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002922 SetLocalDescriptionWithoutError(answer);
2923
deadbeefcbecd352015-09-23 11:50:27 -07002924 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2925 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002926
deadbeefcbecd352015-09-23 11:50:27 -07002927 cricket::BaseChannel* voice_channel = session_->voice_channel();
2928 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002929
2930 // Checks if one of the transport channels contains a connection using a given
2931 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002932 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002933 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002934 session_->GetChannelTransportStats(voice_channel, &stats);
2935 for (auto& kv : stats.transport_stats) {
2936 for (auto& chan_stat : kv.second.channel_stats) {
2937 for (auto& conn_info : chan_stat.connection_infos) {
2938 if (conn_info.remote_candidate.address().port() == port) {
2939 return true;
2940 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002941 }
2942 }
2943 }
2944 return false;
2945 };
2946
2947 EXPECT_FALSE(connection_with_remote_port(5000));
2948 EXPECT_FALSE(connection_with_remote_port(5001));
2949 EXPECT_FALSE(connection_with_remote_port(6000));
2950
2951 // The way the *_WAIT checks work is they only wait if the condition fails,
2952 // which does not help in the case where state is not changing. This is
2953 // problematic in this test since we want to verify that adding a video
2954 // candidate does _not_ change state. So we interleave candidates and assume
2955 // that messages are executed in the order they were posted.
2956
2957 // First audio candidate.
2958 cricket::Candidate candidate0;
2959 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2960 candidate0.set_component(1);
2961 candidate0.set_protocol("udp");
2962 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2963 candidate0);
2964 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2965
2966 // Video candidate.
2967 cricket::Candidate candidate1;
2968 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2969 candidate1.set_component(1);
2970 candidate1.set_protocol("udp");
2971 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2972 candidate1);
2973 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2974
2975 // Second audio candidate.
2976 cricket::Candidate candidate2;
2977 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2978 candidate2.set_component(1);
2979 candidate2.set_protocol("udp");
2980 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2981 candidate2);
2982 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2983
2984 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2985 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2986
2987 // No need here for a _WAIT check since we are checking that state hasn't
2988 // changed: if this is false we would be doing waits for nothing and if this
2989 // is true then there will be no messages processed anyways.
2990 EXPECT_FALSE(connection_with_remote_port(6000));
2991}
2992
deadbeefcbecd352015-09-23 11:50:27 -07002993// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002994TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2995 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002996 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002997
2998 PeerConnectionInterface::RTCOfferAnswerOptions options;
2999 options.use_rtp_mux = true;
3000
3001 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003002 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003003
deadbeefcbecd352015-09-23 11:50:27 -07003004 EXPECT_NE(session_->voice_rtp_transport_channel(),
3005 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003006
deadbeefab9b2d12015-10-14 11:33:11 -07003007 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003008 SessionDescriptionInterface* answer =
3009 CreateRemoteAnswer(session_->local_description());
3010 SetRemoteDescriptionWithoutError(answer);
3011
deadbeefcbecd352015-09-23 11:50:27 -07003012 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3013 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003014}
3015
deadbeefcbecd352015-09-23 11:50:27 -07003016// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003017TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3018 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003019 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003020
Donald Curtis0e209b02015-03-24 09:29:54 -07003021 PeerConnectionInterface::RTCOfferAnswerOptions options;
3022 options.use_rtp_mux = true;
3023
3024 SessionDescriptionInterface* offer = CreateOffer(options);
3025 SetLocalDescriptionWithoutError(offer);
3026
deadbeefcbecd352015-09-23 11:50:27 -07003027 EXPECT_NE(session_->voice_rtp_transport_channel(),
3028 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003029
deadbeefab9b2d12015-10-14 11:33:11 -07003030 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003031
3032 // Remove BUNDLE from the answer.
3033 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3034 CreateRemoteAnswer(session_->local_description()));
3035 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3036 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3037 JsepSessionDescription* modified_answer =
3038 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3039 modified_answer->Initialize(answer_copy, "1", "1");
3040 SetRemoteDescriptionWithoutError(modified_answer); //
3041
deadbeefcbecd352015-09-23 11:50:27 -07003042 EXPECT_NE(session_->voice_rtp_transport_channel(),
3043 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003044}
3045
3046// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3047TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3048 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003049 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003050
3051 PeerConnectionInterface::RTCOfferAnswerOptions options;
3052 options.use_rtp_mux = true;
3053
3054 SessionDescriptionInterface* offer = CreateOffer(options);
3055 SetLocalDescriptionWithoutError(offer);
3056
deadbeefcbecd352015-09-23 11:50:27 -07003057 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3058 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003059
deadbeefab9b2d12015-10-14 11:33:11 -07003060 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003061 SessionDescriptionInterface* answer =
3062 CreateRemoteAnswer(session_->local_description());
3063 SetRemoteDescriptionWithoutError(answer);
3064
deadbeefcbecd352015-09-23 11:50:27 -07003065 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3066 session_->video_rtp_transport_channel());
3067}
3068
3069// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3070// audio content in the answer.
3071TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3072 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003073 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003074
3075 PeerConnectionInterface::RTCOfferAnswerOptions options;
3076 options.use_rtp_mux = true;
3077
3078 SessionDescriptionInterface* offer = CreateOffer(options);
3079 SetLocalDescriptionWithoutError(offer);
3080
3081 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3082 session_->video_rtp_transport_channel());
3083
deadbeefab9b2d12015-10-14 11:33:11 -07003084 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003085 cricket::MediaSessionOptions recv_options;
3086 recv_options.recv_audio = false;
3087 recv_options.recv_video = true;
3088 SessionDescriptionInterface* answer =
3089 CreateRemoteAnswer(session_->local_description(), recv_options);
3090 SetRemoteDescriptionWithoutError(answer);
3091
deadbeefd59daf82015-10-14 15:02:44 -07003092 EXPECT_TRUE(nullptr == session_->voice_channel());
3093 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003094
deadbeefd59daf82015-10-14 15:02:44 -07003095 session_->Close();
3096 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3097 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3098 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3099 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003100}
3101
3102// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3103TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3104 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003105 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003106
Donald Curtis0e209b02015-03-24 09:29:54 -07003107 PeerConnectionInterface::RTCOfferAnswerOptions options;
3108 options.use_rtp_mux = true;
3109
3110 SessionDescriptionInterface* offer = CreateOffer(options);
3111 SetLocalDescriptionWithoutError(offer);
3112
deadbeefcbecd352015-09-23 11:50:27 -07003113 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3114 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003115
deadbeefab9b2d12015-10-14 11:33:11 -07003116 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003117
3118 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003119 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003120 CreateRemoteAnswer(session_->local_description()));
3121 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3122 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3123 JsepSessionDescription* modified_answer =
3124 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3125 modified_answer->Initialize(answer_copy, "1", "1");
3126 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003127
deadbeefcbecd352015-09-23 11:50:27 -07003128 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3129 session_->video_rtp_transport_channel());
3130}
3131
3132// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3133TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3134 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003135 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003136
3137 SessionDescriptionInterface* offer = CreateRemoteOffer();
3138 SetRemoteDescriptionWithoutError(offer);
3139
3140 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3141 session_->video_rtp_transport_channel());
3142
deadbeefab9b2d12015-10-14 11:33:11 -07003143 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003144 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003145 SetLocalDescriptionWithoutError(answer);
3146
3147 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3148 session_->video_rtp_transport_channel());
3149}
3150
3151// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3152TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3153 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003154 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003155
3156 // Remove BUNDLE from the offer.
3157 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3158 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3159 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3160 JsepSessionDescription* modified_offer =
3161 new JsepSessionDescription(JsepSessionDescription::kOffer);
3162 modified_offer->Initialize(offer_copy, "1", "1");
3163
3164 // Expect an error when applying the remote description
3165 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3166 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003167}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003168
Peter Thatcher4eddf182015-04-30 10:55:59 -07003169// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003170TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3171 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003172 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003173
Donald Curtis0e209b02015-03-24 09:29:54 -07003174 PeerConnectionInterface::RTCOfferAnswerOptions options;
3175 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003176
Donald Curtis0e209b02015-03-24 09:29:54 -07003177 SessionDescriptionInterface* offer = CreateOffer(options);
3178 SetLocalDescriptionWithoutError(offer);
3179
deadbeefcbecd352015-09-23 11:50:27 -07003180 EXPECT_NE(session_->voice_rtp_transport_channel(),
3181 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003182
deadbeefab9b2d12015-10-14 11:33:11 -07003183 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003184 SessionDescriptionInterface* answer =
3185 CreateRemoteAnswer(session_->local_description());
3186 SetRemoteDescriptionWithoutError(answer);
3187
3188 // This should lead to an audio-only call but isn't implemented
3189 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003190 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3191 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003192}
3193
deadbeefcbecd352015-09-23 11:50:27 -07003194// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003195TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3196 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003197 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003198 PeerConnectionInterface::RTCOfferAnswerOptions options;
3199 options.use_rtp_mux = true;
3200
3201 SessionDescriptionInterface* offer = CreateOffer(options);
3202 SetLocalDescriptionWithoutError(offer);
3203
deadbeefcbecd352015-09-23 11:50:27 -07003204 EXPECT_NE(session_->voice_rtp_transport_channel(),
3205 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003206
deadbeefab9b2d12015-10-14 11:33:11 -07003207 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003208
3209 // Remove BUNDLE from the answer.
3210 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3211 CreateRemoteAnswer(session_->local_description()));
3212 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3213 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3214 JsepSessionDescription* modified_answer =
3215 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3216 modified_answer->Initialize(answer_copy, "1", "1");
3217 SetRemoteDescriptionWithoutError(modified_answer); //
3218
deadbeefcbecd352015-09-23 11:50:27 -07003219 EXPECT_NE(session_->voice_rtp_transport_channel(),
3220 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003221}
3222
Peter Thatcher4eddf182015-04-30 10:55:59 -07003223// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3224TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3225 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003226 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003227
3228 PeerConnectionInterface::RTCOfferAnswerOptions options;
3229 options.use_rtp_mux = true;
3230
3231 SessionDescriptionInterface* offer = CreateOffer(options);
3232 SetRemoteDescriptionWithoutError(offer);
3233
deadbeefcbecd352015-09-23 11:50:27 -07003234 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3235 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003236}
3237
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003238TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3239 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003240 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003241
3242 PeerConnectionInterface::RTCOfferAnswerOptions options;
3243 SessionDescriptionInterface* offer = CreateOffer(options);
3244 SetLocalDescriptionWithoutError(offer);
3245
deadbeefcbecd352015-09-23 11:50:27 -07003246 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3247 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003248
deadbeefab9b2d12015-10-14 11:33:11 -07003249 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003250 SessionDescriptionInterface* answer =
3251 CreateRemoteAnswer(session_->local_description());
3252 SetRemoteDescriptionWithoutError(answer);
3253
deadbeefcbecd352015-09-23 11:50:27 -07003254 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3255 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003256}
3257
3258TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3259 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003260 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003261
3262 PeerConnectionInterface::RTCOfferAnswerOptions options;
3263 SessionDescriptionInterface* offer = CreateOffer(options);
3264 SetLocalDescriptionWithoutError(offer);
3265
deadbeefcbecd352015-09-23 11:50:27 -07003266 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3267 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003268
deadbeefab9b2d12015-10-14 11:33:11 -07003269 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003270 SessionDescriptionInterface* answer =
3271 CreateRemoteAnswer(session_->local_description());
3272 SetRemoteDescriptionWithoutError(answer);
3273
deadbeefcbecd352015-09-23 11:50:27 -07003274 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3275 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003276}
3277
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003278// This test verifies that SetLocalDescription and SetRemoteDescription fails
3279// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3280TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003281 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003282 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003283
3284 PeerConnectionInterface::RTCOfferAnswerOptions options;
3285 options.use_rtp_mux = true;
3286
3287 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003288 std::string offer_str;
3289 offer->ToString(&offer_str);
3290 // Disable rtcp-mux
3291 const std::string rtcp_mux = "rtcp-mux";
3292 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003293 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003294 xrtcp_mux.c_str(), xrtcp_mux.length(),
3295 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003296 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003297 new JsepSessionDescription(JsepSessionDescription::kOffer);
3298 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003299 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003300 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003301 new JsepSessionDescription(JsepSessionDescription::kOffer);
3302 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003303 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003304 // Trying unmodified SDP.
3305 SetLocalDescriptionWithoutError(offer);
3306}
3307
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003308TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003309 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003310 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003311 CreateAndSetRemoteOfferAndLocalAnswer();
3312 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3313 ASSERT_TRUE(channel != NULL);
3314 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003315 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003316 double volume;
3317 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3318 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003319 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003320 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3321 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003322 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003323 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3324 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003325}
3326
3327TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003328 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003329 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003330 CreateAndSetRemoteOfferAndLocalAnswer();
3331 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3332 ASSERT_TRUE(channel != NULL);
3333 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003334 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003335 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3336
3337 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003338 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003339
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003340 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003341 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003342 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003343 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003344 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003345
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003346 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003347 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003348 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003349 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003350 EXPECT_TRUE(renderer->sink() == NULL);
3351}
3352
3353TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003354 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003355 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003356 CreateAndSetRemoteOfferAndLocalAnswer();
3357 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3358 ASSERT_TRUE(channel != NULL);
3359 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003360 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003361
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003362 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003363 cricket::AudioOptions options;
3364 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3365 EXPECT_TRUE(renderer->sink() != NULL);
3366
3367 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3368 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3369 // SetSink(NULL) callback afterwards.
3370 renderer.reset();
3371
3372 // This will trigger SetSink(NULL) if no OnClose() callback.
3373 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003374}
3375
3376TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003377 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003378 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003379 CreateAndSetRemoteOfferAndLocalAnswer();
3380 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3381 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003382 ASSERT_LT(0u, channel->sinks().size());
3383 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003384 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003385 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003386 cricket::FakeVideoRenderer renderer;
3387 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003388 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003389 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003390 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003391}
3392
3393TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003394 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003395 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003396 CreateAndSetRemoteOfferAndLocalAnswer();
3397 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3398 ASSERT_TRUE(channel != NULL);
3399 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003400 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003401 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3402 cricket::VideoOptions* options = NULL;
3403 session_->SetVideoSend(send_ssrc, false, options);
3404 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3405 session_->SetVideoSend(send_ssrc, true, options);
3406 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3407}
3408
3409TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3410 TestCanInsertDtmf(false);
3411}
3412
3413TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3414 TestCanInsertDtmf(true);
3415}
3416
3417TEST_F(WebRtcSessionTest, InsertDtmf) {
3418 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003419 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003420 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003421 CreateAndSetRemoteOfferAndLocalAnswer();
3422 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3423 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3424
3425 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003426 const int expected_duration = 90;
3427 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3428 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3429 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3430
3431 // Verify
3432 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003433 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003434 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003435 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003436 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003437 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003439 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003440}
3441
deadbeefd59daf82015-10-14 15:02:44 -07003442// This test verifies the |initial_offerer| flag when session initiates the
3443// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003444TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003445 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003446 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003447 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003448 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3449 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003450 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003451 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003452 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003453}
3454
deadbeefd59daf82015-10-14 15:02:44 -07003455// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003456TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003457 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003458 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459 SessionDescriptionInterface* offer = CreateRemoteOffer();
3460 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003461 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003462
deadbeefd59daf82015-10-14 15:02:44 -07003463 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003464 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003465 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003466}
3467
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003468// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3469TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003470 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003471 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003472 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003473 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003474 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003475 CreateRemoteAnswer(session_->local_description()));
3476
3477 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3478 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003479 JsepSessionDescription* modified_answer =
3480 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003481
3482 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3483 answer->session_id(),
3484 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003485 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003486
wu@webrtc.org4e393072014-04-07 17:04:35 +00003487 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003488 std::string sdp;
3489 EXPECT_TRUE(answer->ToString(&sdp));
3490 const std::string kAudioMid = "a=mid:audio";
3491 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003492 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003493 kAudioMidReplaceStr.c_str(),
3494 kAudioMidReplaceStr.length(),
3495 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003496 SessionDescriptionInterface* modified_answer1 =
3497 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003498 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003499
wu@webrtc.org4e393072014-04-07 17:04:35 +00003500 // Different media types.
3501 EXPECT_TRUE(answer->ToString(&sdp));
3502 const std::string kAudioMline = "m=audio";
3503 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003504 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003505 kAudioMlineReplaceStr.c_str(),
3506 kAudioMlineReplaceStr.length(),
3507 &sdp);
3508 SessionDescriptionInterface* modified_answer2 =
3509 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3510 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3511
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003512 SetRemoteDescriptionWithoutError(answer.release());
3513}
3514
3515// Verifying remote offer and local answer have matching m-lines as per
3516// RFC 3264.
3517TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003518 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003519 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003520 SessionDescriptionInterface* offer = CreateRemoteOffer();
3521 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003522 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003523
3524 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3525 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003526 JsepSessionDescription* modified_answer =
3527 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003528
3529 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3530 answer->session_id(),
3531 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003532 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003533 SetLocalDescriptionWithoutError(answer);
3534}
3535
3536// This test verifies that WebRtcSession does not start candidate allocation
3537// before SetLocalDescription is called.
3538TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003539 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003540 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003541 SessionDescriptionInterface* offer = CreateRemoteOffer();
3542 cricket::Candidate candidate;
3543 candidate.set_component(1);
3544 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3545 candidate);
3546 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3547 cricket::Candidate candidate1;
3548 candidate1.set_component(1);
3549 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3550 candidate1);
3551 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3552 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003553 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3554 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003555
3556 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003557 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003558 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3559 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3560
htaa2a49d92016-03-04 02:51:39 -08003561 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003562 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003563 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3564}
3565
3566// This test verifies that crypto parameter is updated in local session
3567// description as per security policy set in MediaSessionDescriptionFactory.
3568TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003569 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003570 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003571 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003572
3573 // Making sure SetLocalDescription correctly sets crypto value in
3574 // SessionDescription object after de-serialization of sdp string. The value
3575 // will be set as per MediaSessionDescriptionFactory.
3576 std::string offer_str;
3577 offer->ToString(&offer_str);
3578 SessionDescriptionInterface* jsep_offer_str =
3579 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3580 SetLocalDescriptionWithoutError(jsep_offer_str);
3581 EXPECT_TRUE(session_->voice_channel()->secure_required());
3582 EXPECT_TRUE(session_->video_channel()->secure_required());
3583}
3584
3585// This test verifies the crypto parameter when security is disabled.
3586TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003587 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003588 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003589 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003590 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003591
3592 // Making sure SetLocalDescription correctly sets crypto value in
3593 // SessionDescription object after de-serialization of sdp string. The value
3594 // will be set as per MediaSessionDescriptionFactory.
3595 std::string offer_str;
3596 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003597 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003598 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3599 SetLocalDescriptionWithoutError(jsep_offer_str);
3600 EXPECT_FALSE(session_->voice_channel()->secure_required());
3601 EXPECT_FALSE(session_->video_channel()->secure_required());
3602}
3603
3604// This test verifies that an answer contains new ufrag and password if an offer
3605// with new ufrag and password is received.
3606TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003607 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003608 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003609 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003610 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003611 CreateRemoteOffer(options));
3612 SetRemoteDescriptionWithoutError(offer.release());
3613
deadbeefab9b2d12015-10-14 11:33:11 -07003614 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003615 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003616 SetLocalDescriptionWithoutError(answer.release());
3617
3618 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003619 for (const cricket::ContentInfo& content :
3620 session_->local_description()->description()->contents()) {
3621 options.transport_options[content.name].ice_restart = true;
3622 }
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003623 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003624 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003625 SetRemoteDescriptionWithoutError(updated_offer1.release());
3626
htaa2a49d92016-03-04 02:51:39 -08003627 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003628
deadbeef0ed85b22016-02-23 17:24:52 -08003629 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3630 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003631
deadbeef0ed85b22016-02-23 17:24:52 -08003632 // Even a second answer (created before the description is set) should have
3633 // a new ufrag/password.
htaa2a49d92016-03-04 02:51:39 -08003634 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003635
3636 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3637 session_->local_description()->description()));
3638
3639 SetLocalDescriptionWithoutError(updated_answer2.release());
3640}
3641
3642// This test verifies that an answer contains new ufrag and password if an offer
3643// that changes either the ufrag or password (but not both) is received.
3644// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3645// a=ice-pwd attributes compared to the previous SDP from the peer, it
3646// indicates that ICE is restarting for this media stream."
3647TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3648 Init();
3649 cricket::MediaSessionOptions options;
3650 options.recv_audio = true;
3651 options.recv_video = true;
3652 // Create an offer with audio and video.
3653 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3654 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3655 SetRemoteDescriptionWithoutError(offer.release());
3656
3657 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003658 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003659 SetLocalDescriptionWithoutError(answer.release());
3660
3661 // Receive an offer with a new ufrag but stale password.
3662 rtc::scoped_ptr<JsepSessionDescription> ufrag_changed_offer(
3663 CreateRemoteOffer(options, session_->remote_description()));
3664 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3665 "original_password12345");
3666 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3667
htaa2a49d92016-03-04 02:51:39 -08003668 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003669 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3670 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003671 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003672
3673 // Receive an offer with a new password but stale ufrag.
3674 rtc::scoped_ptr<JsepSessionDescription> password_changed_offer(
3675 CreateRemoteOffer(options, session_->remote_description()));
3676 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3677 "modified_password12345");
3678 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3679
htaa2a49d92016-03-04 02:51:39 -08003680 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003681 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3682 session_->local_description()->description()));
3683 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003684}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003685
wu@webrtc.org91053e72013-08-10 07:18:04 +00003686// This test verifies that an answer contains old ufrag and password if an offer
3687// with old ufrag and password is received.
3688TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003689 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003690 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003691 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003692 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003693 CreateRemoteOffer(options));
3694 SetRemoteDescriptionWithoutError(offer.release());
3695
deadbeefab9b2d12015-10-14 11:33:11 -07003696 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003697 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003698 SetLocalDescriptionWithoutError(answer.release());
3699
3700 // Receive an offer without changed ufrag or password.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003701 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003702 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003703 SetRemoteDescriptionWithoutError(updated_offer2.release());
3704
htaa2a49d92016-03-04 02:51:39 -08003705 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003706
deadbeef0ed85b22016-02-23 17:24:52 -08003707 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3708 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003709
3710 SetLocalDescriptionWithoutError(updated_answer2.release());
3711}
3712
deadbeef0ed85b22016-02-23 17:24:52 -08003713// This test verifies that if an offer does an ICE restart on some, but not all
3714// media sections, the answer will change the ufrag/password in the correct
3715// media sections.
3716TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3717 Init();
3718 cricket::MediaSessionOptions options;
3719 options.recv_video = true;
3720 options.recv_audio = true;
3721 options.bundle_enabled = false;
3722 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3723
3724 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3725 "aaaaaaaaaaaaaaaaaaaaaa");
3726 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3727 "bbbbbbbbbbbbbbbbbbbbbb");
3728 SetRemoteDescriptionWithoutError(offer.release());
3729
3730 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003731 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003732 SetLocalDescriptionWithoutError(answer.release());
3733
3734 // Receive an offer with new ufrag and password, but only for the video media
3735 // section.
3736 rtc::scoped_ptr<JsepSessionDescription> updated_offer(
3737 CreateRemoteOffer(options, session_->remote_description()));
3738 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3739 "cccccccccccccccccccccc");
3740 SetRemoteDescriptionWithoutError(updated_offer.release());
3741
htaa2a49d92016-03-04 02:51:39 -08003742 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003743
3744 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3745 session_->local_description()->description(),
3746 cricket::MEDIA_TYPE_AUDIO));
3747
3748 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3749 session_->local_description()->description(),
3750 cricket::MEDIA_TYPE_VIDEO));
3751
3752 SetLocalDescriptionWithoutError(updated_answer.release());
3753}
3754
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003755TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003756 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003757 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003758 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003759 const std::string session_id_orig = offer->session_id();
3760 const std::string session_version_orig = offer->session_version();
3761 SetLocalDescriptionWithoutError(offer);
3762
3763 video_channel_ = media_engine_->GetVideoChannel(0);
3764 video_channel_->set_fail_set_send_codecs(true);
3765
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003766 SessionDescriptionInterface* answer =
3767 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003768 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003769
3770 // Test that after a content error, setting any description will
3771 // result in an error.
3772 video_channel_->set_fail_set_send_codecs(false);
3773 answer = CreateRemoteAnswer(session_->local_description());
3774 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3775 offer = CreateRemoteOffer();
3776 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003777}
3778
3779// Runs the loopback call test with BUNDLE and STUN disabled.
3780TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3781 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003782 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003783 cricket::PORTALLOCATOR_DISABLE_STUN |
3784 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003785 TestLoopbackCall();
3786}
3787
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003788TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003789 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003790 cricket::PORTALLOCATOR_DISABLE_STUN |
3791 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3792 cricket::PORTALLOCATOR_DISABLE_RELAY);
3793
3794 // best connection is IPv6 since it has higher network preference.
3795 LoopbackNetworkConfiguration config;
3796 config.test_ipv6_network_ = true;
3797 config.best_connection_after_initial_ice_converged_ =
3798 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3799
3800 TestLoopbackCall(config);
3801}
3802
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003803// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003804TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003805 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3806 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003807 TestLoopbackCall();
3808}
3809
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003810TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003811 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003812 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003813 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003814 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003815 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3816}
3817
Henrik Boström87713d02015-08-25 09:53:21 +02003818TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003819 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003820
htaa2a49d92016-03-04 02:51:39 -08003821 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003822 options_.disable_sctp_data_channels = false;
3823
Henrik Boström87713d02015-08-25 09:53:21 +02003824 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003825
3826 SetLocalDescriptionWithDataChannel();
3827 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3828}
3829
Henrik Boström87713d02015-08-25 09:53:21 +02003830TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003831 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003832
Henrik Boström87713d02015-08-25 09:53:21 +02003833 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003834
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003835 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003836 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003837 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3838}
3839
Henrik Boström87713d02015-08-25 09:53:21 +02003840TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003841 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003842 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003843 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003844
3845 // Create remote offer with SCTP.
3846 cricket::MediaSessionOptions options;
3847 options.data_channel_type = cricket::DCT_SCTP;
3848 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003849 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003850 SetRemoteDescriptionWithoutError(offer);
3851
3852 // Verifies the answer contains SCTP.
htaa2a49d92016-03-04 02:51:39 -08003853 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003854 EXPECT_TRUE(answer != NULL);
3855 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3856 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003857}
3858
Henrik Boström87713d02015-08-25 09:53:21 +02003859TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003860 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003861 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003862
3863 SetLocalDescriptionWithDataChannel();
3864 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3865}
3866
Henrik Boström87713d02015-08-25 09:53:21 +02003867TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003868 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003869
Henrik Boström87713d02015-08-25 09:53:21 +02003870 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003871
3872 SetLocalDescriptionWithDataChannel();
3873 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3874}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003875
Henrik Boström87713d02015-08-25 09:53:21 +02003876TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003877 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003878 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003879 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003880
3881 SetLocalDescriptionWithDataChannel();
3882 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3883}
3884
Henrik Boström87713d02015-08-25 09:53:21 +02003885TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003886 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003887 const int new_send_port = 9998;
3888 const int new_recv_port = 7775;
3889
Henrik Boström87713d02015-08-25 09:53:21 +02003890 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003891 SetFactoryDtlsSrtp();
3892
3893 // By default, don't actually add the codecs to desc_factory_; they don't
3894 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3895 // let the session description get parsed. That'll get the proper codecs
3896 // into the stream.
3897 cricket::MediaSessionOptions options;
3898 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3899 "stream1", new_send_port, options);
3900
3901 // SetRemoteDescription will take the ownership of the offer.
3902 SetRemoteDescriptionWithoutError(offer);
3903
htaa2a49d92016-03-04 02:51:39 -08003904 SessionDescriptionInterface* answer =
3905 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003906 ASSERT_TRUE(answer != NULL);
3907
3908 // Now set the local description, which'll take ownership of the answer.
3909 SetLocalDescriptionWithoutError(answer);
3910
3911 // TEST PLAN: Set the port number to something new, set it in the SDP,
3912 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003913 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003914 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003915
3916 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3917 int portnum = -1;
3918 ASSERT_TRUE(ch != NULL);
3919 ASSERT_EQ(1UL, ch->send_codecs().size());
3920 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003921 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003922 ch->send_codecs()[0].name.c_str()));
3923 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3924 &portnum));
3925 EXPECT_EQ(new_send_port, portnum);
3926
3927 ASSERT_EQ(1UL, ch->recv_codecs().size());
3928 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003929 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003930 ch->recv_codecs()[0].name.c_str()));
3931 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3932 &portnum));
3933 EXPECT_EQ(new_recv_port, portnum);
3934}
3935
deadbeefab9b2d12015-10-14 11:33:11 -07003936// Verifies that when a session's DataChannel receives an OPEN message,
3937// WebRtcSession signals the DataChannel creation request with the expected
3938// config.
3939TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3940 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3941
3942 InitWithDtls(GetParam());
3943
3944 SetLocalDescriptionWithDataChannel();
3945 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3946
3947 webrtc::DataChannelInit config;
3948 config.id = 1;
3949 rtc::Buffer payload;
3950 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3951 cricket::ReceiveDataParams params;
3952 params.ssrc = config.id;
3953 params.type = cricket::DMT_CONTROL;
3954
3955 cricket::DataChannel* data_channel = session_->data_channel();
3956 data_channel->SignalDataReceived(data_channel, params, payload);
3957
3958 EXPECT_EQ("a", last_data_channel_label_);
3959 EXPECT_EQ(config.id, last_data_channel_config_.id);
3960 EXPECT_FALSE(last_data_channel_config_.negotiated);
3961 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3962 last_data_channel_config_.open_handshake_role);
3963}
3964
3965TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003966 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3967 FakeDtlsIdentityStore::GenerateCertificate();
3968
htaa2a49d92016-03-04 02:51:39 -08003969 configuration_.certificates.push_back(certificate);
3970 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02003971 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3972
3973 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3974}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003975
Henrik Boström87713d02015-08-25 09:53:21 +02003976// Verifies that CreateOffer succeeds when CreateOffer is called before async
3977// identity generation is finished (even if a certificate is provided this is
3978// an async op).
3979TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3980 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3981 InitWithDtls(GetParam());
3982
Henrik Boströmd8281982015-08-27 10:12:24 +02003983 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003984 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003985 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3986
wu@webrtc.org91053e72013-08-10 07:18:04 +00003987 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003988 VerifyNoCryptoParams(offer->description(), true);
3989 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003990}
3991
3992// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003993// identity generation is finished (even if a certificate is provided this is
3994// an async op).
3995TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003996 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003997 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003998 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003999
4000 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004001 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00004002 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004003 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004004 ASSERT_TRUE(offer.get() != NULL);
4005 SetRemoteDescriptionWithoutError(offer.release());
4006
htaa2a49d92016-03-04 02:51:39 -08004007 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004008 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004009 VerifyNoCryptoParams(answer->description(), true);
4010 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004011}
4012
4013// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004014// identity generation is finished (even if a certificate is provided this is
4015// an async op).
4016TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004017 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004018 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004019
Henrik Boströmd8281982015-08-27 10:12:24 +02004020 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004021
4022 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004023 EXPECT_TRUE(offer != NULL);
4024}
4025
4026// Verifies that CreateOffer fails when CreateOffer is called after async
4027// identity generation fails.
4028TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004029 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004030 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004031
Henrik Boströmd8281982015-08-27 10:12:24 +02004032 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004033
4034 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004035 EXPECT_TRUE(offer == NULL);
4036}
4037
4038// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4039// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004040TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004041 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004042 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004043 VerifyMultipleAsyncCreateDescription(GetParam(),
4044 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004045}
4046
4047// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4048// before async identity generation fails.
4049TEST_F(WebRtcSessionTest,
4050 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004051 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004052 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4053 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004054}
4055
4056// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4057// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004058TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004059 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004060 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004061 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004062 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004063}
4064
4065// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4066// before async identity generation fails.
4067TEST_F(WebRtcSessionTest,
4068 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004069 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004070 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4071 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004072}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004073
4074// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4075// offer has no SDES crypto but only DTLS fingerprint.
4076TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4077 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004078 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004079 // Create a remote offer with secured transport disabled.
4080 cricket::MediaSessionOptions options;
4081 JsepSessionDescription* offer(CreateRemoteOffer(
4082 options, cricket::SEC_DISABLED));
4083 // Adds a DTLS fingerprint to the remote offer.
4084 cricket::SessionDescription* sdp = offer->description();
4085 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4086 ASSERT_TRUE(audio != NULL);
4087 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4088 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004089 rtc::SSLFingerprint::CreateFromRfc4572(
4090 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004091 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004092 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004093}
4094
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004095TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004096 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004097 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004098 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004099 SessionDescriptionInterface* offer = CreateOffer();
4100
4101 SetLocalDescriptionWithoutError(offer);
4102
4103 voice_channel_ = media_engine_->GetVoiceChannel(0);
4104
4105 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004106 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004107 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004108}
4109
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004110// Tests that we can renegotiate new media content with ICE candidates in the
4111// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004112TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004113 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004114 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004115 SetFactoryDtlsSrtp();
4116
deadbeefab9b2d12015-10-14 11:33:11 -07004117 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004118 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004119 SetLocalDescriptionWithoutError(offer);
4120
4121 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4122 SetRemoteDescriptionWithoutError(answer);
4123
4124 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004125 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004126 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4127
4128 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004129 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004130 candidate1.set_component(1);
4131 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4132 candidate1);
4133 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4134 SetRemoteDescriptionWithoutError(offer);
4135
htaa2a49d92016-03-04 02:51:39 -08004136 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004137 SetLocalDescriptionWithoutError(answer);
4138}
4139
4140// Tests that we can renegotiate new media content with ICE candidates separated
4141// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004142TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004143 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004144 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004145 SetFactoryDtlsSrtp();
4146
deadbeefab9b2d12015-10-14 11:33:11 -07004147 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004148 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004149 SetLocalDescriptionWithoutError(offer);
4150
4151 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4152 SetRemoteDescriptionWithoutError(answer);
4153
4154 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004155 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004156 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4157 SetRemoteDescriptionWithoutError(offer);
4158
4159 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004160 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004161 candidate1.set_component(1);
4162 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4163 candidate1);
4164 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4165
htaa2a49d92016-03-04 02:51:39 -08004166 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004167 SetLocalDescriptionWithoutError(answer);
4168}
honghaiz7f777492016-02-02 21:54:01 -08004169
4170// Flaky on Win and Mac only. See webrtc:4943
4171#if defined(WEBRTC_WIN) || defined(WEBRTC_MAC)
4172#define MAYBE_TestRtxRemovedByCreateAnswer DISABLED_TestRtxRemovedByCreateAnswer
4173#else
4174#define MAYBE_TestRtxRemovedByCreateAnswer TestRtxRemovedByCreateAnswer
4175#endif
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004176// Tests that RTX codec is removed from the answer when it isn't supported
4177// by local side.
honghaiz7f777492016-02-02 21:54:01 -08004178TEST_F(WebRtcSessionTest, MAYBE_TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004179 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004180 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004181 std::string offer_sdp(kSdpWithRtx);
4182
4183 SessionDescriptionInterface* offer =
4184 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4185 EXPECT_TRUE(offer->ToString(&offer_sdp));
4186
4187 // Offer SDP contains the RTX codec.
4188 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4189 SetRemoteDescriptionWithoutError(offer);
4190
htaa2a49d92016-03-04 02:51:39 -08004191 SessionDescriptionInterface* answer = CreateAnswer();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004192 std::string answer_sdp;
4193 answer->ToString(&answer_sdp);
4194 // Answer SDP removes the unsupported RTX codec.
4195 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4196 SetLocalDescriptionWithoutError(answer);
4197}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004198
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004199// This verifies that the voice channel after bundle has both options from video
4200// and voice channels.
4201TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4202 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004203 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004204
4205 PeerConnectionInterface::RTCOfferAnswerOptions options;
4206 options.use_rtp_mux = true;
4207
4208 SessionDescriptionInterface* offer = CreateOffer(options);
4209 SetLocalDescriptionWithoutError(offer);
4210
4211 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4212 rtc::Socket::Option::OPT_SNDBUF, 4000);
4213
4214 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4215 rtc::Socket::Option::OPT_RCVBUF, 8000);
4216
4217 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004218 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004219 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4220 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004221 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004222 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4223
deadbeefcbecd352015-09-23 11:50:27 -07004224 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004225 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4226 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004227 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004228 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4229
deadbeefcbecd352015-09-23 11:50:27 -07004230 EXPECT_NE(session_->voice_rtp_transport_channel(),
4231 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004232
deadbeefab9b2d12015-10-14 11:33:11 -07004233 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004234 SessionDescriptionInterface* answer =
4235 CreateRemoteAnswer(session_->local_description());
4236 SetRemoteDescriptionWithoutError(answer);
4237
deadbeefcbecd352015-09-23 11:50:27 -07004238 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004239 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4240 EXPECT_EQ(4000, option_val);
4241
deadbeefcbecd352015-09-23 11:50:27 -07004242 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004243 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4244 EXPECT_EQ(8000, option_val);
4245}
4246
tommi0f620f42015-07-09 03:25:02 -07004247// Test creating a session, request multiple offers, destroy the session
4248// and make sure we got success/failure callbacks for all of the requests.
4249// Background: crbug.com/507307
4250TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4251 Init();
4252
4253 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4254 PeerConnectionInterface::RTCOfferAnswerOptions options;
4255 options.offer_to_receive_audio =
4256 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004257 cricket::MediaSessionOptions session_options;
4258 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004259
4260 for (auto& o : observers) {
4261 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004262 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004263 }
4264
4265 session_.reset();
4266
tommi0f620f42015-07-09 03:25:02 -07004267 for (auto& o : observers) {
4268 // We expect to have received a notification now even if the session was
4269 // terminated. The offer creation may or may not have succeeded, but we
4270 // must have received a notification which, so the only invalid state
4271 // is kInit.
4272 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4273 }
4274}
4275
stefanc1aeaf02015-10-15 07:26:07 -07004276TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4277 TestPacketOptions();
4278}
4279
deadbeef057ecf02016-01-20 14:30:43 -08004280// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4281// is destroyed.
4282TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4283 Init();
4284 session_.reset();
4285 EXPECT_TRUE(session_destroyed_);
4286}
4287
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004288// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4289// currently fails because upon disconnection and reconnection OnIceComplete is
4290// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004291
deadbeefcbecd352015-09-23 11:50:27 -07004292INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4293 WebRtcSessionTest,
4294 testing::Values(ALREADY_GENERATED,
4295 DTLS_IDENTITY_STORE));