blob: c0fff5251301b58a09508ef03e31f96289f9c57d [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
honghaiz84430da2016-03-11 13:28:09 -0800192 // Some local candidates are removed.
193 void OnIceCandidatesRemoved(
194 const std::vector<cricket::Candidate>& candidates) {
195 num_candidates_removed_ += candidates.size();
196 }
197
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 bool oncandidatesready_;
199 std::vector<cricket::Candidate> mline_0_candidates_;
200 std::vector<cricket::Candidate> mline_1_candidates_;
201 PeerConnectionInterface::IceConnectionState ice_connection_state_;
202 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
honghaiz84430da2016-03-11 13:28:09 -0800203 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204};
205
206class WebRtcSessionForTest : public webrtc::WebRtcSession {
207 public:
stefanc1aeaf02015-10-15 07:26:07 -0700208 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000209 rtc::Thread* signaling_thread,
210 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700212 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700213 : WebRtcSession(media_controller,
214 signaling_thread,
215 worker_thread,
216 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 RegisterIceObserver(ice_observer);
218 }
219 virtual ~WebRtcSessionForTest() {}
220
deadbeefcbecd352015-09-23 11:50:27 -0700221 // Note that these methods are only safe to use if the signaling thread
222 // is the same as the worker thread
223 cricket::TransportChannel* voice_rtp_transport_channel() {
224 return rtp_transport_channel(voice_channel());
225 }
226
227 cricket::TransportChannel* voice_rtcp_transport_channel() {
228 return rtcp_transport_channel(voice_channel());
229 }
230
231 cricket::TransportChannel* video_rtp_transport_channel() {
232 return rtp_transport_channel(video_channel());
233 }
234
235 cricket::TransportChannel* video_rtcp_transport_channel() {
236 return rtcp_transport_channel(video_channel());
237 }
238
239 cricket::TransportChannel* data_rtp_transport_channel() {
240 return rtp_transport_channel(data_channel());
241 }
242
243 cricket::TransportChannel* data_rtcp_transport_channel() {
244 return rtcp_transport_channel(data_channel());
245 }
246
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 using webrtc::WebRtcSession::SetAudioPlayout;
248 using webrtc::WebRtcSession::SetAudioSend;
249 using webrtc::WebRtcSession::SetCaptureDevice;
250 using webrtc::WebRtcSession::SetVideoPlayout;
251 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700252
253 private:
254 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
255 if (!ch) {
256 return nullptr;
257 }
258 return ch->transport_channel();
259 }
260
261 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
262 if (!ch) {
263 return nullptr;
264 }
265 return ch->rtcp_transport_channel();
266 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267};
268
wu@webrtc.org91053e72013-08-10 07:18:04 +0000269class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000270 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000272 enum State {
273 kInit,
274 kFailed,
275 kSucceeded,
276 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000277 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000278
279 // CreateSessionDescriptionObserver implementation.
280 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000281 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000282 state_ = kSucceeded;
283 }
284 virtual void OnFailure(const std::string& error) {
285 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286 }
287
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000288 SessionDescriptionInterface* description() { return description_.get(); }
289
290 SessionDescriptionInterface* ReleaseDescription() {
291 return description_.release();
292 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293
wu@webrtc.org91053e72013-08-10 07:18:04 +0000294 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295
wu@webrtc.org91053e72013-08-10 07:18:04 +0000296 protected:
297 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298
299 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000300 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000301 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302};
303
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800304class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000305 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800306 FakeAudioSource() : sink_(NULL) {}
307 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000308 if (sink_)
309 sink_->OnClose();
310 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000311
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000312 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000313
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800314 const cricket::AudioSource::Sink* sink() const { return sink_; }
315
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000316 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800317 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000318};
319
Henrik Boström87713d02015-08-25 09:53:21 +0200320class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700321 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
322 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323 protected:
324 // TODO Investigate why ChannelManager crashes, if it's created
325 // after stun_server.
326 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700327 : media_engine_(new cricket::FakeMediaEngine()),
328 data_engine_(new cricket::FakeDataEngine()),
329 channel_manager_(
330 new cricket::ChannelManager(media_engine_,
331 data_engine_,
stefanc1aeaf02015-10-15 07:26:07 -0700332 rtc::Thread::Current())),
333 fake_call_(webrtc::Call::Config()),
334 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800335 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
336 rtc::Thread::Current(),
stefanc1aeaf02015-10-15 07:26:07 -0700337 channel_manager_.get())),
338 tdesc_factory_(new cricket::TransportDescriptionFactory()),
339 desc_factory_(
340 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
341 tdesc_factory_.get())),
342 pss_(new rtc::PhysicalSocketServer),
343 vss_(new rtc::VirtualSocketServer(pss_.get())),
344 fss_(new rtc::FirewallSocketServer(vss_.get())),
345 ss_scope_(fss_.get()),
346 stun_socket_addr_(
347 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
348 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
349 stun_socket_addr_)),
350 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
351 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000352 cricket::ServerAddresses stun_servers;
353 stun_servers.insert(stun_socket_addr_);
354 allocator_.reset(new cricket::BasicPortAllocator(
355 &network_manager_,
356 stun_servers,
357 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000358 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700359 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 EXPECT_TRUE(channel_manager_->Init());
361 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000362 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 }
364
365 void AddInterface(const SocketAddress& addr) {
366 network_manager_.AddInterface(addr);
367 }
honghaiz84430da2016-03-11 13:28:09 -0800368 void RemoveInterface(const SocketAddress& addr) {
369 network_manager_.RemoveInterface(addr);
370 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371
Henrik Boström87713d02015-08-25 09:53:21 +0200372 // If |dtls_identity_store| != null or |rtc_configuration| contains
373 // |certificates| then DTLS will be enabled unless explicitly disabled by
374 // |rtc_configuration| options. When DTLS is enabled a certificate will be
375 // used if provided, otherwise one will be generated using the
376 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000377 void Init(
htaa2a49d92016-03-04 02:51:39 -0800378 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 ASSERT_TRUE(session_.get() == NULL);
380 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700381 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700382 allocator_.get(), &observer_));
383 session_->SignalDataChannelOpenMessage.connect(
384 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800385 session_->GetOnDestroyedSignal()->connect(
386 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387
388 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
389 observer_.ice_connection_state_);
390 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
391 observer_.ice_gathering_state_);
392
htaa2a49d92016-03-04 02:51:39 -0800393 EXPECT_TRUE(session_->Initialize(options_, std::move(dtls_identity_store),
394 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700395 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000396 }
397
deadbeefab9b2d12015-10-14 11:33:11 -0700398 void OnDataChannelOpenMessage(const std::string& label,
399 const InternalDataChannelInit& config) {
400 last_data_channel_label_ = label;
401 last_data_channel_config_ = config;
402 }
403
deadbeef057ecf02016-01-20 14:30:43 -0800404 void OnSessionDestroyed() { session_destroyed_ = true; }
405
htaa2a49d92016-03-04 02:51:39 -0800406 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000407
408 void InitWithIceTransport(
409 PeerConnectionInterface::IceTransportsType ice_transport_type) {
htaa2a49d92016-03-04 02:51:39 -0800410 configuration_.type = ice_transport_type;
411 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000412 }
413
414 void InitWithBundlePolicy(
415 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800416 configuration_.bundle_policy = bundle_policy;
417 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700418 }
419
420 void InitWithRtcpMuxPolicy(
421 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
422 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800423 configuration_.rtcp_mux_policy = rtcp_mux_policy;
424 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000425 }
426
Henrik Boström87713d02015-08-25 09:53:21 +0200427 // Successfully init with DTLS; with a certificate generated and supplied or
428 // with a store that generates it for us.
429 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
430 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
Henrik Boström87713d02015-08-25 09:53:21 +0200431 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800432 configuration_.certificates.push_back(
Henrik Boström87713d02015-08-25 09:53:21 +0200433 FakeDtlsIdentityStore::GenerateCertificate());
434 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
435 dtls_identity_store.reset(new FakeDtlsIdentityStore());
436 dtls_identity_store->set_should_fail(false);
437 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700438 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200439 }
htaa2a49d92016-03-04 02:51:39 -0800440 Init(std::move(dtls_identity_store));
Henrik Boström87713d02015-08-25 09:53:21 +0200441 }
442
443 // Init with DTLS with a store that will fail to generate a certificate.
444 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200445 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
446 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200447 dtls_identity_store->set_should_fail(true);
htaa2a49d92016-03-04 02:51:39 -0800448 Init(std::move(dtls_identity_store));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000449 }
450
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451 void InitWithDtmfCodec() {
452 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000453 const cricket::AudioCodec kTelephoneEventCodec(
454 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455 std::vector<cricket::AudioCodec> codecs;
456 codecs.push_back(kTelephoneEventCodec);
457 media_engine_->SetAudioCodecs(codecs);
458 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000459 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460 }
461
deadbeefab9b2d12015-10-14 11:33:11 -0700462 void SendAudioVideoStream1() {
463 send_stream_1_ = true;
464 send_stream_2_ = false;
465 send_audio_ = true;
466 send_video_ = true;
467 }
468
469 void SendAudioVideoStream2() {
470 send_stream_1_ = false;
471 send_stream_2_ = true;
472 send_audio_ = true;
473 send_video_ = true;
474 }
475
476 void SendAudioVideoStream1And2() {
477 send_stream_1_ = true;
478 send_stream_2_ = true;
479 send_audio_ = true;
480 send_video_ = true;
481 }
482
483 void SendNothing() {
484 send_stream_1_ = false;
485 send_stream_2_ = false;
486 send_audio_ = false;
487 send_video_ = false;
488 }
489
490 void SendAudioOnlyStream2() {
491 send_stream_1_ = false;
492 send_stream_2_ = true;
493 send_audio_ = true;
494 send_video_ = false;
495 }
496
497 void SendVideoOnlyStream2() {
498 send_stream_1_ = false;
499 send_stream_2_ = true;
500 send_audio_ = false;
501 send_video_ = true;
502 }
503
504 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
505 if (send_stream_1_ && send_audio_) {
506 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
507 kStream1);
508 }
509 if (send_stream_1_ && send_video_) {
510 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
511 kStream1);
512 }
513 if (send_stream_2_ && send_audio_) {
514 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
515 kStream2);
516 }
517 if (send_stream_2_ && send_video_) {
518 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
519 kStream2);
520 }
521 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
522 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
523 data_channel_->label(),
524 data_channel_->label());
525 }
526 }
527
528 void GetOptionsForOffer(
529 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
530 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800531 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700532
deadbeefc80741f2015-10-22 13:14:45 -0700533 AddStreamsToOptions(session_options);
534 if (rtc_options.offer_to_receive_audio ==
535 RTCOfferAnswerOptions::kUndefined) {
536 session_options->recv_audio =
537 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
538 }
539 if (rtc_options.offer_to_receive_video ==
540 RTCOfferAnswerOptions::kUndefined) {
541 session_options->recv_video =
542 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
543 }
544 session_options->bundle_enabled =
545 session_options->bundle_enabled &&
546 (session_options->has_audio() || session_options->has_video() ||
547 session_options->has_data());
548
deadbeefab9b2d12015-10-14 11:33:11 -0700549 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
550 session_options->data_channel_type = cricket::DCT_SCTP;
551 }
552 }
553
htaa2a49d92016-03-04 02:51:39 -0800554 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
555 // ParseConstraintsForAnswer is used to set some defaults.
556 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700557
deadbeefc80741f2015-10-22 13:14:45 -0700558 AddStreamsToOptions(session_options);
559 session_options->bundle_enabled =
560 session_options->bundle_enabled &&
561 (session_options->has_audio() || session_options->has_video() ||
562 session_options->has_data());
563
deadbeefab9b2d12015-10-14 11:33:11 -0700564 if (session_->data_channel_type() == cricket::DCT_SCTP) {
565 session_options->data_channel_type = cricket::DCT_SCTP;
566 }
567 }
568
569 // Creates a local offer and applies it. Starts ICE.
570 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 // to decide which streams to create.
572 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000573 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000574 SetLocalDescriptionWithoutError(offer);
575 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
576 observer_.ice_gathering_state_,
577 kIceCandidatesTimeout);
578 }
579
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000580 SessionDescriptionInterface* CreateOffer() {
581 PeerConnectionInterface::RTCOfferAnswerOptions options;
582 options.offer_to_receive_audio =
583 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
584
585 return CreateOffer(options);
586 }
587
wu@webrtc.org91053e72013-08-10 07:18:04 +0000588 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800589 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000590 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000591 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700592 cricket::MediaSessionOptions session_options;
593 GetOptionsForOffer(options, &session_options);
594 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000595 EXPECT_TRUE_WAIT(
596 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000597 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000598 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000599 }
600
601 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800602 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000603 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000604 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800605 cricket::MediaSessionOptions session_options = options;
606 GetOptionsForAnswer(&session_options);
607 // Overwrite recv_audio and recv_video with passed-in values.
608 session_options.recv_video = options.recv_video;
609 session_options.recv_audio = options.recv_audio;
610 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000611 EXPECT_TRUE_WAIT(
612 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000613 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000614 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000615 }
616
htaa2a49d92016-03-04 02:51:39 -0800617 SessionDescriptionInterface* CreateAnswer() {
618 cricket::MediaSessionOptions options;
619 options.recv_video = true;
620 options.recv_audio = true;
621 return CreateAnswer(options);
622 }
623
wu@webrtc.org364f2042013-11-20 21:49:41 +0000624 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000625 return (session_->voice_channel() != NULL &&
626 session_->video_channel() != NULL);
627 }
628
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000629 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
630 ASSERT_TRUE(session_.get() != NULL);
631 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
632 ASSERT_TRUE(content != NULL);
633 const cricket::AudioContentDescription* audio_content =
634 static_cast<const cricket::AudioContentDescription*>(
635 content->description);
636 ASSERT_TRUE(audio_content != NULL);
637 ASSERT_EQ(1U, audio_content->cryptos().size());
638 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
639 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
640 audio_content->cryptos()[0].cipher_suite);
641 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
642 audio_content->protocol());
643
644 content = cricket::GetFirstVideoContent(sdp);
645 ASSERT_TRUE(content != NULL);
646 const cricket::VideoContentDescription* video_content =
647 static_cast<const cricket::VideoContentDescription*>(
648 content->description);
649 ASSERT_TRUE(video_content != NULL);
650 ASSERT_EQ(1U, video_content->cryptos().size());
651 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
652 video_content->cryptos()[0].cipher_suite);
653 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
654 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
655 video_content->protocol());
656 }
657
658 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
659 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
660 ASSERT_TRUE(content != NULL);
661 const cricket::AudioContentDescription* audio_content =
662 static_cast<const cricket::AudioContentDescription*>(
663 content->description);
664 ASSERT_TRUE(audio_content != NULL);
665 ASSERT_EQ(0U, audio_content->cryptos().size());
666
667 content = cricket::GetFirstVideoContent(sdp);
668 ASSERT_TRUE(content != NULL);
669 const cricket::VideoContentDescription* video_content =
670 static_cast<const cricket::VideoContentDescription*>(
671 content->description);
672 ASSERT_TRUE(video_content != NULL);
673 ASSERT_EQ(0U, video_content->cryptos().size());
674
675 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700676 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000677 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700678 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679 video_content->protocol());
680 } else {
681 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
682 audio_content->protocol());
683 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
684 video_content->protocol());
685 }
686 }
687
688 // Set the internal fake description factories to do DTLS-SRTP.
689 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000690 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000692 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200693 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800694 tdesc_factory_->set_certificate(
695 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
696 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
698 }
699
700 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
701 bool expected) {
702 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
703 ASSERT_TRUE(audio != NULL);
704 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 const TransportInfo* video = sdp->GetTransportInfoByName("video");
706 ASSERT_TRUE(video != NULL);
707 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 }
709
710 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000711 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000713 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000714 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000716 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000718 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
719 offer);
htaa2a49d92016-03-04 02:51:39 -0800720 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 // Answer should be NULL as no crypto params in offer.
722 ASSERT_TRUE(answer == NULL);
723 }
724
725 void VerifyAnswerFromCryptoOffer() {
726 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000727 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728 options.bundle_enabled = true;
729 scoped_ptr<JsepSessionDescription> offer(
730 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
731 ASSERT_TRUE(offer.get() != NULL);
732 VerifyCryptoParams(offer->description());
733 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -0800734 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735 ASSERT_TRUE(answer.get() != NULL);
736 VerifyCryptoParams(answer->description());
737 }
738
deadbeef0ed85b22016-02-23 17:24:52 -0800739 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
740 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800742 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 }
744
745 const cricket::ContentInfos& contents = desc1->contents();
746 cricket::ContentInfos::const_iterator it = contents.begin();
747
748 for (; it != contents.end(); ++it) {
749 const cricket::TransportDescription* transport_desc1 =
750 desc1->GetTransportDescriptionByName(it->name);
751 const cricket::TransportDescription* transport_desc2 =
752 desc2->GetTransportDescriptionByName(it->name);
753 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800754 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755 }
756 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
757 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800758 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 }
760 }
deadbeef0ed85b22016-02-23 17:24:52 -0800761 return true;
762 }
763
764 // Compares ufrag/password only for the specified |media_type|.
765 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
766 const cricket::SessionDescription* desc2,
767 cricket::MediaType media_type) {
768 if (desc1->contents().size() != desc2->contents().size()) {
769 return false;
770 }
771
772 const cricket::ContentInfo* cinfo =
773 cricket::GetFirstMediaContent(desc1->contents(), media_type);
774 const cricket::TransportDescription* transport_desc1 =
775 desc1->GetTransportDescriptionByName(cinfo->name);
776 const cricket::TransportDescription* transport_desc2 =
777 desc2->GetTransportDescriptionByName(cinfo->name);
778 if (!transport_desc1 || !transport_desc2) {
779 return false;
780 }
781 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
782 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
783 return false;
784 }
785 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000787
788 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
789 std::string *sdp) {
790 const cricket::SessionDescription* desc = current_desc->description();
791 EXPECT_TRUE(current_desc->ToString(sdp));
792
793 const cricket::ContentInfos& contents = desc->contents();
794 cricket::ContentInfos::const_iterator it = contents.begin();
795 // Replace ufrag and pwd lines with empty strings.
796 for (; it != contents.end(); ++it) {
797 const cricket::TransportDescription* transport_desc =
798 desc->GetTransportDescriptionByName(it->name);
799 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
800 + "\r\n";
801 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
802 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000803 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000804 "", 0,
805 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000806 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000807 "", 0,
808 sdp);
809 }
810 }
811
deadbeef0ed85b22016-02-23 17:24:52 -0800812 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
813 const std::string& ufrag,
814 const std::string& pwd) {
815 cricket::SessionDescription* desc = current_desc->description();
816 for (TransportInfo& transport_info : desc->transport_infos()) {
817 cricket::TransportDescription& transport_desc =
818 transport_info.description;
819 transport_desc.ice_ufrag = ufrag;
820 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000821 }
822 }
823
deadbeef0ed85b22016-02-23 17:24:52 -0800824 // Sets ufrag/pwd for specified |media_type|.
825 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
826 cricket::MediaType media_type,
827 const std::string& ufrag,
828 const std::string& pwd) {
829 cricket::SessionDescription* desc = current_desc->description();
830 const cricket::ContentInfo* cinfo =
831 cricket::GetFirstMediaContent(desc->contents(), media_type);
832 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
833 cricket::TransportDescription* transport_desc =
834 &transport_info->description;
835 transport_desc->ice_ufrag = ufrag;
836 transport_desc->ice_pwd = pwd;
837 }
838
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 // Creates a remote offer and and applies it as a remote description,
840 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700841 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 // to decide which local and remote streams to create.
843 void CreateAndSetRemoteOfferAndLocalAnswer() {
844 SessionDescriptionInterface* offer = CreateRemoteOffer();
845 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800846 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 SetLocalDescriptionWithoutError(answer);
848 }
849 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
850 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700851 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 }
853 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700854 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 SetLocalDescriptionWithoutError(desc);
856 EXPECT_EQ(expected_state, session_->state());
857 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000858 void SetLocalDescriptionExpectError(const std::string& action,
859 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 SessionDescriptionInterface* desc) {
861 std::string error;
862 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000863 std::string sdp_type = "local ";
864 sdp_type.append(action);
865 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 EXPECT_NE(std::string::npos, error.find(expected_error));
867 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000868 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
869 SessionDescriptionInterface* desc) {
870 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
871 expected_error, desc);
872 }
873 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
874 SessionDescriptionInterface* desc) {
875 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
876 expected_error, desc);
877 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
879 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
880 }
881 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700882 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 SetRemoteDescriptionWithoutError(desc);
884 EXPECT_EQ(expected_state, session_->state());
885 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000886 void SetRemoteDescriptionExpectError(const std::string& action,
887 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 SessionDescriptionInterface* desc) {
889 std::string error;
890 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000891 std::string sdp_type = "remote ";
892 sdp_type.append(action);
893 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 EXPECT_NE(std::string::npos, error.find(expected_error));
895 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000896 void SetRemoteDescriptionOfferExpectError(
897 const std::string& expected_error, SessionDescriptionInterface* desc) {
898 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
899 expected_error, desc);
900 }
901 void SetRemoteDescriptionPranswerExpectError(
902 const std::string& expected_error, SessionDescriptionInterface* desc) {
903 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
904 expected_error, desc);
905 }
906 void SetRemoteDescriptionAnswerExpectError(
907 const std::string& expected_error, SessionDescriptionInterface* desc) {
908 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
909 expected_error, desc);
910 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911
912 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
913 SessionDescriptionInterface** nocrypto_answer) {
914 // Create a SDP without Crypto.
915 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000916 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 options.bundle_enabled = true;
918 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
919 ASSERT_TRUE(*offer != NULL);
920 VerifyCryptoParams((*offer)->description());
921
922 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
923 cricket::SEC_DISABLED);
924 EXPECT_TRUE(*nocrypto_answer != NULL);
925 }
926
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000927 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
928 SessionDescriptionInterface** nodtls_answer) {
929 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000930 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000931 options.bundle_enabled = true;
932
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000933 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000934 CreateRemoteOffer(options, cricket::SEC_ENABLED));
935
936 *nodtls_answer =
937 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
938 EXPECT_TRUE(*nodtls_answer != NULL);
939 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
940 VerifyCryptoParams((*nodtls_answer)->description());
941
942 SetFactoryDtlsSrtp();
943 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
944 ASSERT_TRUE(*offer != NULL);
945 VerifyFingerprintStatus((*offer)->description(), true);
946 VerifyCryptoParams((*offer)->description());
947 }
948
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 JsepSessionDescription* CreateRemoteOfferWithVersion(
950 cricket::MediaSessionOptions options,
951 cricket::SecurePolicy secure_policy,
952 const std::string& session_version,
953 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000954 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 const cricket::SessionDescription* cricket_desc = NULL;
956 if (current_desc) {
957 cricket_desc = current_desc->description();
958 session_id = current_desc->session_id();
959 }
960
961 desc_factory_->set_secure(secure_policy);
962 JsepSessionDescription* offer(
963 new JsepSessionDescription(JsepSessionDescription::kOffer));
964 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
965 session_id, session_version)) {
966 delete offer;
967 offer = NULL;
968 }
969 return offer;
970 }
971 JsepSessionDescription* CreateRemoteOffer(
972 cricket::MediaSessionOptions options) {
973 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
974 kSessionVersion, NULL);
975 }
976 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000977 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
978 return CreateRemoteOfferWithVersion(
979 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 }
981 JsepSessionDescription* CreateRemoteOffer(
982 cricket::MediaSessionOptions options,
983 const SessionDescriptionInterface* current_desc) {
984 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
985 kSessionVersion, current_desc);
986 }
987
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000988 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
989 const char* sctp_stream_name, int new_port,
990 cricket::MediaSessionOptions options) {
991 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000992 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
993 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000994 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
995 }
996
997 // Takes ownership of offer_basis (and deletes it).
998 JsepSessionDescription* ChangeSDPSctpPort(
999 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1000 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1001 // SessionDescription from the mutated string.
1002 const char* default_port_str = "5000";
1003 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001004 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001005 std::string offer_str;
1006 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001007 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001008 new_port_str, strlen(new_port_str),
1009 &offer_str);
1010 JsepSessionDescription* offer = new JsepSessionDescription(
1011 offer_basis->type());
1012 delete offer_basis;
1013 offer->Initialize(offer_str, NULL);
1014 return offer;
1015 }
1016
deadbeefab9b2d12015-10-14 11:33:11 -07001017 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018 // before this function to decide which streams to create.
1019 JsepSessionDescription* CreateRemoteOffer() {
1020 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001021 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 return CreateRemoteOffer(options, session_->remote_description());
1023 }
1024
1025 JsepSessionDescription* CreateRemoteAnswer(
1026 const SessionDescriptionInterface* offer,
1027 cricket::MediaSessionOptions options,
1028 cricket::SecurePolicy policy) {
1029 desc_factory_->set_secure(policy);
1030 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001031 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 JsepSessionDescription* answer(
1033 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1034 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1035 options, NULL),
1036 session_id, kSessionVersion)) {
1037 delete answer;
1038 answer = NULL;
1039 }
1040 return answer;
1041 }
1042
1043 JsepSessionDescription* CreateRemoteAnswer(
1044 const SessionDescriptionInterface* offer,
1045 cricket::MediaSessionOptions options) {
1046 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1047 }
1048
deadbeefab9b2d12015-10-14 11:33:11 -07001049 // Creates an answer session description.
1050 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001051 // to decide which streams to create.
1052 JsepSessionDescription* CreateRemoteAnswer(
1053 const SessionDescriptionInterface* offer) {
1054 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001055 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1057 }
1058
1059 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001060 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001061 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001062 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001063
1064 PeerConnectionInterface::RTCOfferAnswerOptions options;
1065 options.use_rtp_mux = bundle;
1066
1067 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1069 // and answer.
1070 SetLocalDescriptionWithoutError(offer);
1071
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001072 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001073 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 std::string sdp;
1075 EXPECT_TRUE(answer->ToString(&sdp));
1076
1077 size_t expected_candidate_num = 2;
1078 if (!rtcp_mux) {
1079 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1080 // for rtp and rtcp.
1081 expected_candidate_num = 4;
1082 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 const std::string kRtcpMux = "a=rtcp-mux";
1084 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001085 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001086 kXRtcpMux.c_str(), kXRtcpMux.length(),
1087 &sdp);
1088 }
1089
1090 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1091 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001092
1093 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001094 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001095 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1096 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001097 if (bundle) {
1098 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1099 } else {
1100 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 }
1102 }
1103 // Tests that we can only send DTMF when the dtmf codec is supported.
1104 void TestCanInsertDtmf(bool can) {
1105 if (can) {
1106 InitWithDtmfCodec();
1107 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001108 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001109 }
deadbeefab9b2d12015-10-14 11:33:11 -07001110 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 CreateAndSetRemoteOfferAndLocalAnswer();
1112 EXPECT_FALSE(session_->CanInsertDtmf(""));
1113 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1114 }
1115
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001116 // Helper class to configure loopback network and verify Best
1117 // Connection using right IP protocol for TestLoopbackCall
1118 // method. LoopbackNetworkManager applies firewall rules to block
1119 // all ping traffic once ICE completed, and remove them to observe
1120 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1121 // verifies the best connection is using the right IP protocol after
1122 // initial ICE convergences.
1123
1124 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001125 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001126 LoopbackNetworkConfiguration()
1127 : test_ipv6_network_(false),
1128 test_extra_ipv4_network_(false),
1129 best_connection_after_initial_ice_converged_(1, 0) {}
1130
1131 // Used to track the expected best connection count in each IP protocol.
1132 struct ExpectedBestConnection {
1133 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1134 : ipv4_count_(ipv4_count),
1135 ipv6_count_(ipv6_count) {}
1136
1137 int ipv4_count_;
1138 int ipv6_count_;
1139 };
1140
1141 bool test_ipv6_network_;
1142 bool test_extra_ipv4_network_;
1143 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1144
1145 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001146 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001147 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1148 }
1149
1150 private:
jbauchac8869e2015-07-03 01:36:14 -07001151 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001152 const ExpectedBestConnection& expected) const {
1153 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001154 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1155 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001156 expected.ipv4_count_);
1157 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001158 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1159 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001160 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001161 // This is used in the loopback call so there is only single host to host
1162 // candidate pair.
1163 EXPECT_EQ(metrics_observer->GetEnumCounter(
1164 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1165 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001166 0);
1167 EXPECT_EQ(metrics_observer->GetEnumCounter(
1168 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1169 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001170 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001171 }
1172 };
1173
1174 class LoopbackNetworkManager {
1175 public:
1176 LoopbackNetworkManager(WebRtcSessionTest* session,
1177 const LoopbackNetworkConfiguration& config)
1178 : config_(config) {
1179 session->AddInterface(
1180 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1181 if (config_.test_extra_ipv4_network_) {
1182 session->AddInterface(
1183 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1184 }
1185 if (config_.test_ipv6_network_) {
1186 session->AddInterface(
1187 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1188 }
1189 }
1190
1191 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1192 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1193 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1194 if (config_.test_extra_ipv4_network_) {
1195 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1196 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1197 }
1198 if (config_.test_ipv6_network_) {
1199 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1200 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1201 }
1202 }
1203
1204 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1205
1206 private:
1207 LoopbackNetworkConfiguration config_;
1208 };
1209
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001210 // The method sets up a call from the session to itself, in a loopback
1211 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001212 // disconnection, and then a permanent disconnection.
1213 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001214 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1215 // While running the call, this method also checks if the session goes through
1216 // the correct sequence of ICE states when a connection is established,
1217 // broken, and re-established.
1218 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001219 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1220 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001221 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001222
stefanc1aeaf02015-10-15 07:26:07 -07001223 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001224 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001225 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001226 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001227
1228 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1229 observer_.ice_gathering_state_);
1230 SetLocalDescriptionWithoutError(offer);
1231 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1232 observer_.ice_connection_state_);
1233 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001234 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1236 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001237 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001238
1239 std::string sdp;
1240 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001241 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1242 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001243 ASSERT_TRUE(desc != NULL);
1244 SetRemoteDescriptionWithoutError(desc);
1245
1246 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001247 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001248
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001249 // The ice connection state is "Connected" too briefly to catch in a test.
1250 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001251 observer_.ice_connection_state_, kIceCandidatesTimeout);
1252 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001253
stefanc1aeaf02015-10-15 07:26:07 -07001254 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1255 LoopbackNetworkManager loopback_network_manager(this, config);
1256 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001257 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258 // Adding firewall rule to block ping requests, which should cause
1259 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001260
1261 loopback_network_manager.ApplyFirewallRules(fss_.get());
1262
1263 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1265 observer_.ice_connection_state_,
1266 kIceCandidatesTimeout);
1267
jbauchac8869e2015-07-03 01:36:14 -07001268 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001269
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001271 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001273 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001274 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 observer_.ice_connection_state_,
1276 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001277
1278 // Now we block ping requests and wait until the ICE connection transitions
1279 // to the Failed state. This will take at least 30 seconds because it must
1280 // wait for the Port to timeout.
1281 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001282
1283 loopback_network_manager.ApplyFirewallRules(fss_.get());
1284 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001285 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001286 observer_.ice_connection_state_,
1287 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 }
1289
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001290 void TestLoopbackCall() {
1291 LoopbackNetworkConfiguration config;
1292 TestLoopbackCall(config);
1293 }
1294
stefanc1aeaf02015-10-15 07:26:07 -07001295 void TestPacketOptions() {
1296 media_controller_.reset(
1297 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1298 LoopbackNetworkConfiguration config;
1299 LoopbackNetworkManager loopback_network_manager(this, config);
1300
1301 SetupLoopbackCall();
1302
1303 uint8_t test_packet[15] = {0};
1304 rtc::PacketOptions options;
1305 options.packet_id = 10;
1306 media_engine_->GetVideoChannel(0)
1307 ->SendRtp(test_packet, sizeof(test_packet), options);
1308
1309 const int kPacketTimeout = 2000;
1310 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1311 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1312 }
1313
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1315 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001316 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1317 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1318
1319 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1321 codecs.push_back(kCNCodec1);
1322 codecs.push_back(kCNCodec2);
1323 media_engine_->SetAudioCodecs(codecs);
1324 desc_factory_->set_audio_codecs(codecs);
1325 }
1326
1327 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1328 const cricket::ContentDescription* description = content->description;
1329 ASSERT(description != NULL);
1330 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001331 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001332 ASSERT(audio_content_desc != NULL);
1333 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1334 if (audio_content_desc->codecs()[i].name == "CN")
1335 return false;
1336 }
1337 return true;
1338 }
1339
deadbeefab9b2d12015-10-14 11:33:11 -07001340 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001341 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001342 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001343 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1344 data_channel_ = DataChannel::Create(
1345 session_.get(), session_->data_channel_type(), "datachannel", dci);
1346 }
1347
1348 void SetLocalDescriptionWithDataChannel() {
1349 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001350 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001351 SetLocalDescriptionWithoutError(offer);
1352 }
1353
wu@webrtc.org91053e72013-08-10 07:18:04 +00001354 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001355 RTCCertificateGenerationMethod cert_gen_method,
1356 CreateSessionDescriptionRequest::Type type) {
1357 InitWithDtls(cert_gen_method);
1358 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1359 }
1360
1361 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1362 CreateSessionDescriptionRequest::Type type) {
1363 InitWithDtlsIdentityGenFail();
1364 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1365 }
1366
1367 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001368 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001369 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001370 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001371 if (type == CreateSessionDescriptionRequest::kAnswer) {
1372 cricket::MediaSessionOptions options;
1373 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001374 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001375 ASSERT_TRUE(offer.get() != NULL);
1376 SetRemoteDescriptionWithoutError(offer.release());
1377 }
1378
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001379 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001380 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001381 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001382 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001383 observers[kNumber];
1384 for (int i = 0; i < kNumber; ++i) {
1385 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1386 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001387 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001388 } else {
htaa2a49d92016-03-04 02:51:39 -08001389 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001390 }
1391 }
1392
1393 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1394 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1395 WebRtcSessionCreateSDPObserverForTest::kFailed;
1396
1397 for (int i = 0; i < kNumber; ++i) {
1398 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1399 if (success) {
1400 EXPECT_TRUE(observers[i]->description() != NULL);
1401 } else {
1402 EXPECT_TRUE(observers[i]->description() == NULL);
1403 }
1404 }
1405 }
1406
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001407 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001408 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001409 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001410 turn_server.credentials = credentials;
1411 turn_server.ports.push_back(
1412 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1413 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001414 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001415 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001416 }
1417
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001418 cricket::FakeMediaEngine* media_engine_;
1419 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001420 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001421 cricket::FakeCall fake_call_;
1422 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001423 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001424 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1425 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1426 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1427 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1428 rtc::SocketServerScope ss_scope_;
1429 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001430 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001431 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001432 rtc::FakeNetworkManager network_manager_;
1433 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001434 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001435 PeerConnectionInterface::RTCConfiguration configuration_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001436 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001437 MockIceObserver observer_;
1438 cricket::FakeVideoMediaChannel* video_channel_;
1439 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001440 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001441 // The following flags affect options created for CreateOffer/CreateAnswer.
1442 bool send_stream_1_ = false;
1443 bool send_stream_2_ = false;
1444 bool send_audio_ = false;
1445 bool send_video_ = false;
1446 rtc::scoped_refptr<DataChannel> data_channel_;
1447 // Last values received from data channel creation signal.
1448 std::string last_data_channel_label_;
1449 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001450 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451};
1452
Henrik Boström87713d02015-08-25 09:53:21 +02001453TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1454 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001455 // SDES is disabled when DTLS is on.
1456 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001457}
1458
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001459TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001460 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001461 // SDES is required if DTLS is off.
1462 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001463}
1464
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1466 TestSessionCandidatesWithBundleRtcpMux(false, false);
1467}
1468
1469// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1470// with rtcp-mux and/or bundle.
1471TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1472 TestSessionCandidatesWithBundleRtcpMux(false, true);
1473}
1474
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1476 TestSessionCandidatesWithBundleRtcpMux(true, true);
1477}
1478
1479TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001480 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1481 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001482 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001483 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001484 InitiateCall();
1485 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1486 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1487 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1488}
1489
minyuec8930ba2016-01-22 06:17:46 -08001490// Crashes on Win only. See webrtc:5411.
1491#if defined(WEBRTC_WIN)
1492#define MAYBE_TestStunError DISABLED_TestStunError
1493#else
1494#define MAYBE_TestStunError TestStunError
1495#endif
1496TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001497 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1498 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001499 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001500 rtc::FP_UDP,
1501 rtc::FD_ANY,
1502 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001503 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001504 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001505 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001506 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1508 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1509 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1510}
1511
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001512// Test session delivers no candidates gathered when constraint set to "none".
1513TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1514 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001515 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001516 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001517 InitiateCall();
1518 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1519 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1520 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1521}
1522
1523// Test session delivers only relay candidates gathered when constaint set to
1524// "relay".
1525TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1526 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1527 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001528 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001529 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001530 InitiateCall();
1531 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1532 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1533 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1534 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1535 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1536 observer_.mline_0_candidates_[i].type());
1537 }
1538 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1539 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1540 observer_.mline_1_candidates_[i].type());
1541 }
1542}
1543
1544// Test session delivers all candidates gathered when constaint set to "all".
1545TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1546 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001547 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001548 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001549 InitiateCall();
1550 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1551 // Host + STUN. By default allocator is disabled to gather relay candidates.
1552 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1553 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1554}
1555
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001556TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001557 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001558 SessionDescriptionInterface* offer = NULL;
1559 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1560 std::string unknown_action;
1561 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1562 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1563}
1564
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565// Test creating offers and receive answers and make sure the
1566// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001567TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001568 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001569 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001570 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 const std::string session_id_orig = offer->session_id();
1572 const std::string session_version_orig = offer->session_version();
1573 SetLocalDescriptionWithoutError(offer);
1574
deadbeefab9b2d12015-10-14 11:33:11 -07001575 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 SessionDescriptionInterface* answer =
1577 CreateRemoteAnswer(session_->local_description());
1578 SetRemoteDescriptionWithoutError(answer);
1579
1580 video_channel_ = media_engine_->GetVideoChannel(0);
1581 voice_channel_ = media_engine_->GetVoiceChannel(0);
1582
1583 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1584 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1585
1586 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1587 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1588
1589 ASSERT_EQ(1u, video_channel_->send_streams().size());
1590 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1591 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1592 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1593
1594 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001595 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001596 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597
1598 // Verify the session id is the same and the session version is
1599 // increased.
1600 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001601 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1602 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603
1604 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001605 EXPECT_EQ(0u, video_channel_->send_streams().size());
1606 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607
deadbeefab9b2d12015-10-14 11:33:11 -07001608 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001609 answer = CreateRemoteAnswer(session_->local_description());
1610 SetRemoteDescriptionWithoutError(answer);
1611
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 // Make sure the receive streams have not changed.
1613 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1614 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1615 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1616 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1617}
1618
1619// Test receiving offers and creating answers and make sure the
1620// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001621TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001622 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001623 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001624 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001625 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 SetRemoteDescriptionWithoutError(offer);
1627
deadbeefab9b2d12015-10-14 11:33:11 -07001628 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001629 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001630 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 SetLocalDescriptionWithoutError(answer);
1632
1633 const std::string session_id_orig = answer->session_id();
1634 const std::string session_version_orig = answer->session_version();
1635
1636 video_channel_ = media_engine_->GetVideoChannel(0);
1637 voice_channel_ = media_engine_->GetVoiceChannel(0);
1638
htaa2a49d92016-03-04 02:51:39 -08001639 ASSERT_TRUE(video_channel_);
1640 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1642 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1643
1644 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1645 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1646
1647 ASSERT_EQ(1u, video_channel_->send_streams().size());
1648 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1649 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1650 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1651
deadbeefab9b2d12015-10-14 11:33:11 -07001652 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001653 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 SetRemoteDescriptionWithoutError(offer);
1655
1656 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001657 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001658 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659
1660 // Verify the session id is the same and the session version is
1661 // increased.
1662 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001663 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1664 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 SetLocalDescriptionWithoutError(answer);
1666
1667 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1668 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1669 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1670 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1671 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1672 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1673
1674 // Make sure we have no send streams.
1675 EXPECT_EQ(0u, video_channel_->send_streams().size());
1676 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1677}
1678
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001679TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001680 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001681 media_engine_->set_fail_create_channel(true);
1682
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001683 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001684 ASSERT_TRUE(offer != NULL);
1685 // SetRemoteDescription and SetLocalDescription will take the ownership of
1686 // the offer.
1687 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001688 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001689 ASSERT_TRUE(offer != NULL);
1690 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1691}
1692
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001693//
1694// Tests for creating/setting SDP under different SDES/DTLS polices:
1695//
1696// --DTLS off and SDES on
1697// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1698// set local/remote offer/answer with crypto --> success
1699// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1700// failure
1701// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1702// failure
1703// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1704// failure
1705//
1706// --DTLS on and SDES off
1707// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1708// set local/remote offer/answer with DTLS fingerprint --> success
1709// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1710// fingerprint --> failure
1711// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1712// --> failure
1713// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1714// --> failure
1715//
1716// --Encryption disabled: DTLS off and SDES off
1717// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1718// answer without SDES or DTLS --> success
1719// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1720// answer without SDES or DTLS --> success
1721//
1722
1723// Test that we return a failure when applying a remote/local offer that doesn't
1724// have cryptos enabled when DTLS is off.
1725TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001726 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001728 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729 JsepSessionDescription* offer = CreateRemoteOffer(
1730 options, cricket::SEC_DISABLED);
1731 ASSERT_TRUE(offer != NULL);
1732 VerifyNoCryptoParams(offer->description(), false);
1733 // SetRemoteDescription and SetLocalDescription will take the ownership of
1734 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001735 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1737 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001738 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739}
1740
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001741// Test that we return a failure when applying a local answer that doesn't have
1742// cryptos enabled when DTLS is off.
1743TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001744 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 SessionDescriptionInterface* offer = NULL;
1746 SessionDescriptionInterface* answer = NULL;
1747 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1748 // SetRemoteDescription and SetLocalDescription will take the ownership of
1749 // the offer.
1750 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001751 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752}
1753
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001754// Test we will return fail when apply an remote answer that doesn't have
1755// crypto enabled when DTLS is off.
1756TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001757 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 SessionDescriptionInterface* offer = NULL;
1759 SessionDescriptionInterface* answer = NULL;
1760 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1761 // SetRemoteDescription and SetLocalDescription will take the ownership of
1762 // the offer.
1763 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001764 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765}
1766
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001767// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1768// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001769TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001770 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001771 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001772 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773 SetFactoryDtlsSrtp();
1774 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001775 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001776 JsepSessionDescription* offer =
1777 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 ASSERT_TRUE(offer != NULL);
1779 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001780 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781
1782 // SetRemoteDescription will take the ownership of the offer.
1783 SetRemoteDescriptionWithoutError(offer);
1784
1785 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001786 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 ASSERT_TRUE(answer != NULL);
1788 VerifyFingerprintStatus(answer->description(), true);
1789 // Check that we don't have an a=crypto line in the answer.
1790 VerifyNoCryptoParams(answer->description(), true);
1791
1792 // Now set the local description, which should work, even without a=crypto.
1793 SetLocalDescriptionWithoutError(answer);
1794}
1795
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001796// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1797// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001798TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001799 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001800 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001801 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001802 SetFactoryDtlsSrtp();
1803
1804 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001805 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001806 ASSERT_TRUE(offer != NULL);
1807 VerifyFingerprintStatus(offer->description(), true);
1808 // Check that we don't have an a=crypto line in the offer.
1809 VerifyNoCryptoParams(offer->description(), true);
1810
1811 // Now set the local description, which should work, even without a=crypto.
1812 SetLocalDescriptionWithoutError(offer);
1813
1814 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001815 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001816 JsepSessionDescription* answer =
1817 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1818 ASSERT_TRUE(answer != NULL);
1819 VerifyFingerprintStatus(answer->description(), true);
1820 VerifyNoCryptoParams(answer->description(), true);
1821
1822 // SetRemoteDescription will take the ownership of the answer.
1823 SetRemoteDescriptionWithoutError(answer);
1824}
1825
1826// Test that if we support DTLS and the other side didn't offer a fingerprint,
1827// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001828TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001829 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001830 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001832 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001833 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001834 JsepSessionDescription* offer = CreateRemoteOffer(
1835 options, cricket::SEC_REQUIRED);
1836 ASSERT_TRUE(offer != NULL);
1837 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001838 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001840 // SetRemoteDescription will take the ownership of the offer.
1841 SetRemoteDescriptionOfferExpectError(
1842 kSdpWithoutDtlsFingerprint, offer);
1843
1844 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1845 // SetLocalDescription will take the ownership of the offer.
1846 SetLocalDescriptionOfferExpectError(
1847 kSdpWithoutDtlsFingerprint, offer);
1848}
1849
1850// Test that we return a failure when applying a local answer that doesn't have
1851// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001852TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001853 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001854 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001855 SessionDescriptionInterface* offer = NULL;
1856 SessionDescriptionInterface* answer = NULL;
1857 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1858
1859 // SetRemoteDescription and SetLocalDescription will take the ownership of
1860 // the offer and answer.
1861 SetRemoteDescriptionWithoutError(offer);
1862 SetLocalDescriptionAnswerExpectError(
1863 kSdpWithoutDtlsFingerprint, answer);
1864}
1865
1866// Test that we return a failure when applying a remote answer that doesn't have
1867// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001868TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001869 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001870 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001871 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001872 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001873 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001874 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1875 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001876 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001877 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001878
1879 // SetRemoteDescription and SetLocalDescription will take the ownership of
1880 // the offer and answer.
1881 SetLocalDescriptionWithoutError(offer);
1882 SetRemoteDescriptionAnswerExpectError(
1883 kSdpWithoutDtlsFingerprint, answer);
1884}
1885
1886// Test that we create a local offer without SDES or DTLS and accept a remote
1887// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001888TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001889 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001890 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001891 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001892
1893 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001894 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001895 ASSERT_TRUE(offer != NULL);
1896 VerifyFingerprintStatus(offer->description(), false);
1897 // Check that we don't have an a=crypto line in the offer.
1898 VerifyNoCryptoParams(offer->description(), false);
1899
1900 // Now set the local description, which should work, even without a=crypto.
1901 SetLocalDescriptionWithoutError(offer);
1902
1903 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001904 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001905 JsepSessionDescription* answer =
1906 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1907 ASSERT_TRUE(answer != NULL);
1908 VerifyFingerprintStatus(answer->description(), false);
1909 VerifyNoCryptoParams(answer->description(), false);
1910
1911 // SetRemoteDescription will take the ownership of the answer.
1912 SetRemoteDescriptionWithoutError(answer);
1913}
1914
1915// Test that we create a local answer without SDES or DTLS and accept a remote
1916// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001917TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001918 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001919 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001920
1921 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001922 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001923 JsepSessionDescription* offer =
1924 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1925 ASSERT_TRUE(offer != NULL);
1926 VerifyFingerprintStatus(offer->description(), false);
1927 VerifyNoCryptoParams(offer->description(), false);
1928
1929 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930 SetRemoteDescriptionWithoutError(offer);
1931
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001932 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001933 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001934 ASSERT_TRUE(answer != NULL);
1935 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001936 // Check that we don't have an a=crypto line in the answer.
1937 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001938
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001939 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001940 SetLocalDescriptionWithoutError(answer);
1941}
1942
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001943// Test that we can create and set an answer correctly when different
1944// SSL roles have been negotiated for different transports.
1945// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1946TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1947 SendAudioVideoStream1();
1948 InitWithDtls(GetParam());
1949 SetFactoryDtlsSrtp();
1950
1951 SessionDescriptionInterface* offer = CreateOffer();
1952 SetLocalDescriptionWithoutError(offer);
1953
1954 cricket::MediaSessionOptions options;
1955 options.recv_video = true;
1956
1957 // First, negotiate different SSL roles.
1958 SessionDescriptionInterface* answer =
1959 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1960 TransportInfo* audio_transport_info =
1961 answer->description()->GetTransportInfoByName("audio");
1962 audio_transport_info->description.connection_role =
1963 cricket::CONNECTIONROLE_ACTIVE;
1964 TransportInfo* video_transport_info =
1965 answer->description()->GetTransportInfoByName("video");
1966 video_transport_info->description.connection_role =
1967 cricket::CONNECTIONROLE_PASSIVE;
1968 SetRemoteDescriptionWithoutError(answer);
1969
1970 // Now create an offer in the reverse direction, and ensure the initial
1971 // offerer responds with an answer with correct SSL roles.
1972 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1973 kSessionVersion,
1974 session_->remote_description());
1975 SetRemoteDescriptionWithoutError(offer);
1976
htaa2a49d92016-03-04 02:51:39 -08001977 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001978 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1979 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1980 audio_transport_info->description.connection_role);
1981 video_transport_info = answer->description()->GetTransportInfoByName("video");
1982 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1983 video_transport_info->description.connection_role);
1984 SetLocalDescriptionWithoutError(answer);
1985
1986 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1987 // audio is transferred over to video in the answer that completes the BUNDLE
1988 // negotiation.
1989 options.bundle_enabled = true;
1990 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1991 kSessionVersion,
1992 session_->remote_description());
1993 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08001994 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001995 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1996 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1997 audio_transport_info->description.connection_role);
1998 video_transport_info = answer->description()->GetTransportInfoByName("video");
1999 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2000 video_transport_info->description.connection_role);
2001 SetLocalDescriptionWithoutError(answer);
2002}
2003
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002005 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002006 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002007 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002008 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009 SetLocalDescriptionWithoutError(offer);
2010
2011 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002012 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013 SetLocalDescriptionWithoutError(offer2);
2014}
2015
2016TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002017 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002018 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002020 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002021 SetRemoteDescriptionWithoutError(offer);
2022
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002023 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024 SetRemoteDescriptionWithoutError(offer2);
2025}
2026
2027TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002028 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002029 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002030 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002032 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002033 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2034 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035}
2036
2037TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002038 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002039 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002040 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002042 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002043 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002044 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045}
2046
2047TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002048 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002049 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002050 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002051 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052
htaa2a49d92016-03-04 02:51:39 -08002053 JsepSessionDescription* pranswer =
2054 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002056 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057
deadbeefab9b2d12015-10-14 11:33:11 -07002058 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002059 JsepSessionDescription* pranswer2 =
2060 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2062
deadbeefd59daf82015-10-14 15:02:44 -07002063 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064
deadbeefab9b2d12015-10-14 11:33:11 -07002065 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002066 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002067 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068}
2069
2070TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002071 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002072 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002073 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002074 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075
2076 JsepSessionDescription* pranswer =
2077 CreateRemoteAnswer(session_->local_description());
2078 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2079
2080 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002081 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082
deadbeefab9b2d12015-10-14 11:33:11 -07002083 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084 JsepSessionDescription* pranswer2 =
2085 CreateRemoteAnswer(session_->local_description());
2086 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2087
2088 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002089 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090
deadbeefab9b2d12015-10-14 11:33:11 -07002091 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092 SessionDescriptionInterface* answer =
2093 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002094 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095}
2096
2097TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
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 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2105 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106}
2107
2108TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002109 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002110 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002111 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2112
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002113 SessionDescriptionInterface* answer =
2114 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002115 SetRemoteDescriptionAnswerExpectError(
2116 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117}
2118
honghaiz84430da2016-03-11 13:28:09 -08002119// Tests that the remote candidates are added and removed successfully.
2120TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002121 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002122 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123
honghaiz84430da2016-03-11 13:28:09 -08002124 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2125 "", "", "host", 0, "");
2126 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2128
deadbeefd59daf82015-10-14 15:02:44 -07002129 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2131
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002132 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002134
2135 // Fail since we have not set a remote description.
2136 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137
2138 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2139 session_->local_description());
2140 SetRemoteDescriptionWithoutError(answer);
2141
deadbeefd59daf82015-10-14 15:02:44 -07002142 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2143 candidate.set_component(2);
honghaiz84430da2016-03-11 13:28:09 -08002144 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002145 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2146 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2147
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148 // Verifying the candidates are copied properly from internal vector.
2149 const SessionDescriptionInterface* remote_desc =
2150 session_->remote_description();
2151 ASSERT_TRUE(remote_desc != NULL);
2152 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2153 const IceCandidateCollection* candidates =
2154 remote_desc->candidates(kMediaContentIndex0);
2155 ASSERT_EQ(2u, candidates->count());
2156 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2157 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2158 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2159 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2160
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002161 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2162 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 candidate.set_component(2);
2164 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2165 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002166 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167
2168 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2169 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
honghaiz84430da2016-03-11 13:28:09 -08002170
2171 // Remove candidate1 and candidate2
2172 std::vector<cricket::Candidate> remote_candidates;
2173 remote_candidates.push_back(ice_candidate1.candidate());
2174 remote_candidates.push_back(ice_candidate2.candidate());
2175 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2176 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177}
2178
honghaiz84430da2016-03-11 13:28:09 -08002179// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180// that it is retained if the remote session description is changed.
2181TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002182 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183 cricket::Candidate candidate1;
2184 candidate1.set_component(1);
2185 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2186 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002187 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002188 CreateAndSetRemoteOfferAndLocalAnswer();
2189
2190 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2191 const SessionDescriptionInterface* remote_desc =
2192 session_->remote_description();
2193 ASSERT_TRUE(remote_desc != NULL);
2194 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2195 const IceCandidateCollection* candidates =
2196 remote_desc->candidates(kMediaContentIndex0);
2197 ASSERT_EQ(1u, candidates->count());
2198 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2199
2200 // Update the RemoteSessionDescription with a new session description and
2201 // a candidate and check that the new remote session description contains both
2202 // candidates.
2203 SessionDescriptionInterface* offer = CreateRemoteOffer();
2204 cricket::Candidate candidate2;
2205 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2206 candidate2);
2207 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2208 SetRemoteDescriptionWithoutError(offer);
2209
2210 remote_desc = session_->remote_description();
2211 ASSERT_TRUE(remote_desc != NULL);
2212 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2213 candidates = remote_desc->candidates(kMediaContentIndex0);
2214 ASSERT_EQ(2u, candidates->count());
2215 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2216 // Username and password have be updated with the TransportInfo of the
2217 // SessionDescription, won't be equal to the original one.
2218 candidate2.set_username(candidates->at(0)->candidate().username());
2219 candidate2.set_password(candidates->at(0)->candidate().password());
2220 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2221 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2222 // No need to verify the username and password.
2223 candidate1.set_username(candidates->at(1)->candidate().username());
2224 candidate1.set_password(candidates->at(1)->candidate().password());
2225 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2226
2227 // Test that the candidate is ignored if we can add the same candidate again.
2228 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2229}
2230
2231// Test that local candidates are added to the local session description and
honghaiz84430da2016-03-11 13:28:09 -08002232// that they are retained if the local session description is changed. And if
2233// continual gathering is enabled, they are removed from the local session
2234// description when the network is down.
2235TEST_F(WebRtcSessionTest,
2236 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002237 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002238 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002239 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002240 CreateAndSetRemoteOfferAndLocalAnswer();
2241
2242 const SessionDescriptionInterface* local_desc = session_->local_description();
2243 const IceCandidateCollection* candidates =
2244 local_desc->candidates(kMediaContentIndex0);
2245 ASSERT_TRUE(candidates != NULL);
2246 EXPECT_EQ(0u, candidates->count());
2247
2248 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2249
2250 local_desc = session_->local_description();
2251 candidates = local_desc->candidates(kMediaContentIndex0);
2252 ASSERT_TRUE(candidates != NULL);
2253 EXPECT_LT(0u, candidates->count());
2254 candidates = local_desc->candidates(1);
2255 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002256 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257
2258 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002259 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260 CreateAndSetRemoteOfferAndLocalAnswer();
2261
2262 local_desc = session_->local_description();
2263 candidates = local_desc->candidates(kMediaContentIndex0);
2264 ASSERT_TRUE(candidates != NULL);
2265 EXPECT_LT(0u, candidates->count());
2266 candidates = local_desc->candidates(1);
2267 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002268 EXPECT_EQ(0u, candidates->count());
honghaiz84430da2016-03-11 13:28:09 -08002269
2270 candidates = local_desc->candidates(kMediaContentIndex0);
2271 size_t num_local_candidates = candidates->count();
2272 // Enable Continual Gathering
2273 session_->SetIceConfig(cricket::IceConfig(-1, -1, true, false, -1));
2274 // Bring down the network interface to trigger candidate removals.
2275 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2276 // Verify that all local candidates are removed.
2277 EXPECT_EQ(0, observer_.num_candidates_removed_);
2278 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2279 kIceCandidatesTimeout);
2280 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2281}
2282
2283// Tests that if continual gathering is disabled, local candidates won't be
2284// removed when the interface is turned down.
2285TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2286 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2287 Init();
2288 SendAudioVideoStream1();
2289 CreateAndSetRemoteOfferAndLocalAnswer();
2290
2291 const SessionDescriptionInterface* local_desc = session_->local_description();
2292 const IceCandidateCollection* candidates =
2293 local_desc->candidates(kMediaContentIndex0);
2294 ASSERT_TRUE(candidates != NULL);
2295 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2296
2297 size_t num_local_candidates = candidates->count();
2298 EXPECT_LT(0u, num_local_candidates);
2299 // By default, Continual Gathering is disabled.
2300 // Bring down the network interface.
2301 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2302 // Verify that the local candidates are not removed.
2303 rtc::Thread::Current()->ProcessMessages(1000);
2304 EXPECT_EQ(0, observer_.num_candidates_removed_);
2305 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306}
2307
2308// Test that we can set a remote session description with remote candidates.
2309TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002310 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311
2312 cricket::Candidate candidate1;
2313 candidate1.set_component(1);
2314 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2315 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002316 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002317 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318
2319 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2320 SetRemoteDescriptionWithoutError(offer);
2321
2322 const SessionDescriptionInterface* remote_desc =
2323 session_->remote_description();
2324 ASSERT_TRUE(remote_desc != NULL);
2325 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2326 const IceCandidateCollection* candidates =
2327 remote_desc->candidates(kMediaContentIndex0);
2328 ASSERT_EQ(1u, candidates->count());
2329 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2330
htaa2a49d92016-03-04 02:51:39 -08002331 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332 SetLocalDescriptionWithoutError(answer);
2333}
2334
2335// Test that offers and answers contains ice candidates when Ice candidates have
2336// been gathered.
2337TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002338 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002339 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002340 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341 // Ice is started but candidates are not provided until SetLocalDescription
2342 // is called.
2343 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2344 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2345 CreateAndSetRemoteOfferAndLocalAnswer();
2346 // Wait until at least one local candidate has been collected.
2347 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2348 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002350 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2351
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2353 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354
2355 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2356 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002357 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2359 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360 SetLocalDescriptionWithoutError(answer);
2361}
2362
2363// Verifies TransportProxy and media channels are created with content names
2364// present in the SessionDescription.
2365TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002366 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002367 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002368 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369
2370 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002371 // "video". Goal is to modify these content names and verify transport
2372 // channels
2373 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374 // present in SDP.
2375 std::string sdp;
2376 EXPECT_TRUE(offer->ToString(&sdp));
2377 const std::string kAudioMid = "a=mid:audio";
2378 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2379 const std::string kVideoMid = "a=mid:video";
2380 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2381
2382 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002383 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384 kAudioMidReplaceStr.c_str(),
2385 kAudioMidReplaceStr.length(),
2386 &sdp);
2387 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002388 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389 kVideoMidReplaceStr.c_str(),
2390 kVideoMidReplaceStr.length(),
2391 &sdp);
2392
2393 SessionDescriptionInterface* modified_offer =
2394 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2395
2396 SetRemoteDescriptionWithoutError(modified_offer);
2397
htaa2a49d92016-03-04 02:51:39 -08002398 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399 SetLocalDescriptionWithoutError(answer);
2400
deadbeefcbecd352015-09-23 11:50:27 -07002401 cricket::TransportChannel* voice_transport_channel =
2402 session_->voice_rtp_transport_channel();
2403 EXPECT_TRUE(voice_transport_channel != NULL);
2404 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2405 cricket::TransportChannel* video_transport_channel =
2406 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002407 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002408 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2410 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2411}
2412
2413// Test that an offer contains the correct media content descriptions based on
2414// the send streams when no constraints have been set.
2415TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002416 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002417 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2418
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419 ASSERT_TRUE(offer != NULL);
2420 const cricket::ContentInfo* content =
2421 cricket::GetFirstAudioContent(offer->description());
2422 EXPECT_TRUE(content != NULL);
2423 content = cricket::GetFirstVideoContent(offer->description());
2424 EXPECT_TRUE(content == NULL);
2425}
2426
2427// Test that an offer contains the correct media content descriptions based on
2428// the send streams when no constraints have been set.
2429TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002430 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002432 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002433 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2434
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435 const cricket::ContentInfo* content =
2436 cricket::GetFirstAudioContent(offer->description());
2437 EXPECT_TRUE(content != NULL);
2438 content = cricket::GetFirstVideoContent(offer->description());
2439 EXPECT_TRUE(content == NULL);
2440
2441 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002442 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002443 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444 content = cricket::GetFirstAudioContent(offer->description());
2445 EXPECT_TRUE(content != NULL);
2446 content = cricket::GetFirstVideoContent(offer->description());
2447 EXPECT_TRUE(content != NULL);
2448}
2449
2450// Test that an offer contains no media content descriptions if
2451// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2452TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002453 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002454 PeerConnectionInterface::RTCOfferAnswerOptions options;
2455 options.offer_to_receive_audio = 0;
2456 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002457
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002458 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002459 CreateOffer(options));
2460
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002461 ASSERT_TRUE(offer != NULL);
2462 const cricket::ContentInfo* content =
2463 cricket::GetFirstAudioContent(offer->description());
2464 EXPECT_TRUE(content == NULL);
2465 content = cricket::GetFirstVideoContent(offer->description());
2466 EXPECT_TRUE(content == NULL);
2467}
2468
2469// Test that an offer contains only audio media content descriptions if
2470// kOfferToReceiveAudio constraints are set to true.
2471TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002472 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002473 PeerConnectionInterface::RTCOfferAnswerOptions options;
2474 options.offer_to_receive_audio =
2475 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2476
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002477 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002478 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002479
2480 const cricket::ContentInfo* content =
2481 cricket::GetFirstAudioContent(offer->description());
2482 EXPECT_TRUE(content != NULL);
2483 content = cricket::GetFirstVideoContent(offer->description());
2484 EXPECT_TRUE(content == NULL);
2485}
2486
2487// Test that an offer contains audio and video media content descriptions if
2488// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2489TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002490 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002491 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002492 PeerConnectionInterface::RTCOfferAnswerOptions options;
2493 options.offer_to_receive_audio =
2494 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2495 options.offer_to_receive_video =
2496 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2497
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002498 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002499 CreateOffer(options));
2500
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002501 const cricket::ContentInfo* content =
2502 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002503 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002504
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002505 content = cricket::GetFirstVideoContent(offer->description());
2506 EXPECT_TRUE(content != NULL);
2507
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002508 // Sets constraints to false and verifies that audio/video contents are
2509 // removed.
2510 options.offer_to_receive_audio = 0;
2511 options.offer_to_receive_video = 0;
2512 offer.reset(CreateOffer(options));
2513
2514 content = cricket::GetFirstAudioContent(offer->description());
2515 EXPECT_TRUE(content == NULL);
2516 content = cricket::GetFirstVideoContent(offer->description());
2517 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002518}
2519
2520// Test that an answer can not be created if the last remote description is not
2521// an offer.
2522TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002523 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002524 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525 SetLocalDescriptionWithoutError(offer);
2526 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2527 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002528 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002529}
2530
2531// Test that an answer contains the correct media content descriptions when no
2532// constraints have been set.
2533TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002534 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002535 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002536 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002537 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -08002538 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539 const cricket::ContentInfo* content =
2540 cricket::GetFirstAudioContent(answer->description());
2541 ASSERT_TRUE(content != NULL);
2542 EXPECT_FALSE(content->rejected);
2543
2544 content = cricket::GetFirstVideoContent(answer->description());
2545 ASSERT_TRUE(content != NULL);
2546 EXPECT_FALSE(content->rejected);
2547}
2548
2549// Test that an answer contains the correct media content descriptions when no
2550// constraints have been set and the offer only contain audio.
2551TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002552 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002553 // Create a remote offer with audio only.
2554 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002555
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002556 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002557 CreateRemoteOffer(options));
2558 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2559 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2560
2561 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -08002562 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002563 const cricket::ContentInfo* content =
2564 cricket::GetFirstAudioContent(answer->description());
2565 ASSERT_TRUE(content != NULL);
2566 EXPECT_FALSE(content->rejected);
2567
2568 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2569}
2570
2571// Test that an answer contains the correct media content descriptions when no
2572// constraints have been set.
2573TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002574 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002575 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002576 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002577 SetRemoteDescriptionWithoutError(offer.release());
2578 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002579 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002580 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581 const cricket::ContentInfo* content =
2582 cricket::GetFirstAudioContent(answer->description());
2583 ASSERT_TRUE(content != NULL);
2584 EXPECT_FALSE(content->rejected);
2585
2586 content = cricket::GetFirstVideoContent(answer->description());
2587 ASSERT_TRUE(content != NULL);
2588 EXPECT_FALSE(content->rejected);
2589}
2590
2591// Test that an answer contains the correct media content descriptions when
2592// constraints have been set but no stream is sent.
2593TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002594 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002595 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002596 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002597 SetRemoteDescriptionWithoutError(offer.release());
2598
htaa2a49d92016-03-04 02:51:39 -08002599 cricket::MediaSessionOptions session_options;
2600 session_options.recv_audio = false;
2601 session_options.recv_video = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002602 rtc::scoped_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002603 CreateAnswer(session_options));
2604
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002605 const cricket::ContentInfo* content =
2606 cricket::GetFirstAudioContent(answer->description());
2607 ASSERT_TRUE(content != NULL);
2608 EXPECT_TRUE(content->rejected);
2609
2610 content = cricket::GetFirstVideoContent(answer->description());
2611 ASSERT_TRUE(content != NULL);
2612 EXPECT_TRUE(content->rejected);
2613}
2614
2615// Test that an answer contains the correct media content descriptions when
2616// constraints have been set and streams are sent.
2617TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002618 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002619 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002620 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002621 SetRemoteDescriptionWithoutError(offer.release());
2622
htaa2a49d92016-03-04 02:51:39 -08002623 cricket::MediaSessionOptions options;
2624 options.recv_audio = false;
2625 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626
2627 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002628 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002629 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002630
2631 // TODO(perkj): Should the direction be set to SEND_ONLY?
2632 const cricket::ContentInfo* content =
2633 cricket::GetFirstAudioContent(answer->description());
2634 ASSERT_TRUE(content != NULL);
2635 EXPECT_FALSE(content->rejected);
2636
2637 // TODO(perkj): Should the direction be set to SEND_ONLY?
2638 content = cricket::GetFirstVideoContent(answer->description());
2639 ASSERT_TRUE(content != NULL);
2640 EXPECT_FALSE(content->rejected);
2641}
2642
2643TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2644 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002645 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002646 PeerConnectionInterface::RTCOfferAnswerOptions options;
2647 options.offer_to_receive_audio =
2648 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2649 options.voice_activity_detection = false;
2650
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002651 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002652 CreateOffer(options));
2653
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654 const cricket::ContentInfo* content =
2655 cricket::GetFirstAudioContent(offer->description());
2656 EXPECT_TRUE(content != NULL);
2657 EXPECT_TRUE(VerifyNoCNCodecs(content));
2658}
2659
2660TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2661 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002662 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002663 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002664 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002665 SetRemoteDescriptionWithoutError(offer.release());
2666
htaa2a49d92016-03-04 02:51:39 -08002667 cricket::MediaSessionOptions options;
2668 options.vad_enabled = false;
2669 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002670 const cricket::ContentInfo* content =
2671 cricket::GetFirstAudioContent(answer->description());
2672 ASSERT_TRUE(content != NULL);
2673 EXPECT_TRUE(VerifyNoCNCodecs(content));
2674}
2675
2676// This test verifies the call setup when remote answer with audio only and
2677// later updates with video.
2678TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002679 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002680 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2681 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2682
deadbeefab9b2d12015-10-14 11:33:11 -07002683 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002684 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002685
2686 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002687 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2688
2689 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2690 // and answer;
2691 SetLocalDescriptionWithoutError(offer);
2692 SetRemoteDescriptionWithoutError(answer);
2693
2694 video_channel_ = media_engine_->GetVideoChannel(0);
2695 voice_channel_ = media_engine_->GetVoiceChannel(0);
2696
2697 ASSERT_TRUE(video_channel_ == NULL);
2698
2699 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2700 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2701 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2702
2703 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002704 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002705 CreateAndSetRemoteOfferAndLocalAnswer();
2706
2707 video_channel_ = media_engine_->GetVideoChannel(0);
2708 voice_channel_ = media_engine_->GetVoiceChannel(0);
2709
2710 ASSERT_TRUE(video_channel_ != NULL);
2711 ASSERT_TRUE(voice_channel_ != NULL);
2712
2713 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2714 ASSERT_EQ(1u, video_channel_->send_streams().size());
2715 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2716 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2717 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2718 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2719 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2720 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2721
2722 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002723 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002724 CreateAndSetRemoteOfferAndLocalAnswer();
2725
2726 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2727 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2728 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2729 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2730 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2731}
2732
2733// This test verifies the call setup when remote answer with video only and
2734// later updates with audio.
2735TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002736 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002737 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2738 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002739 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002740 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002741
2742 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002743 options.recv_audio = false;
2744 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002745 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2746 offer, options, cricket::SEC_ENABLED);
2747
2748 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2749 // and answer.
2750 SetLocalDescriptionWithoutError(offer);
2751 SetRemoteDescriptionWithoutError(answer);
2752
2753 video_channel_ = media_engine_->GetVideoChannel(0);
2754 voice_channel_ = media_engine_->GetVoiceChannel(0);
2755
2756 ASSERT_TRUE(voice_channel_ == NULL);
2757 ASSERT_TRUE(video_channel_ != NULL);
2758
2759 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2760 ASSERT_EQ(1u, video_channel_->send_streams().size());
2761 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2762
2763 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002764 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002765 CreateAndSetRemoteOfferAndLocalAnswer();
2766
2767 voice_channel_ = media_engine_->GetVoiceChannel(0);
2768 ASSERT_TRUE(voice_channel_ != NULL);
2769
2770 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2771 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2772 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2773 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2774
2775 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002776 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002777 CreateAndSetRemoteOfferAndLocalAnswer();
2778
2779 video_channel_ = media_engine_->GetVideoChannel(0);
2780 voice_channel_ = media_engine_->GetVoiceChannel(0);
2781
2782 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2783 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2784 ASSERT_EQ(1u, video_channel_->send_streams().size());
2785 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2786}
2787
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002788TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002789 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002790 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002791 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002792 VerifyCryptoParams(offer->description());
2793 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -08002794 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002795 VerifyCryptoParams(answer->description());
2796}
2797
2798TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002799 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002800 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002801 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002802 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002803 VerifyNoCryptoParams(offer->description(), false);
2804}
2805
2806TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002807 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002808 VerifyAnswerFromNonCryptoOffer();
2809}
2810
2811TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002812 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002813 VerifyAnswerFromCryptoOffer();
2814}
2815
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002816// This test verifies that setLocalDescription fails if
2817// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2818TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002819 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002820 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002821 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2822
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002823 std::string sdp;
2824 RemoveIceUfragPwdLines(offer.get(), &sdp);
2825 SessionDescriptionInterface* modified_offer =
2826 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002827 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002828}
2829
2830// This test verifies that setRemoteDescription fails if
2831// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2832TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002833 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002834 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002835 std::string sdp;
2836 RemoveIceUfragPwdLines(offer.get(), &sdp);
2837 SessionDescriptionInterface* modified_offer =
2838 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002839 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002840}
2841
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002842// This test verifies that setLocalDescription fails if local offer has
2843// too short ice ufrag and pwd strings.
2844TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002845 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002846 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002847 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002848 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2849 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002850 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002851 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002852 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002853
2854 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002855 offer.reset(CreateOffer());
2856 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2857 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002858}
2859
2860// This test verifies that setRemoteDescription fails if remote offer has
2861// too short ice ufrag and pwd strings.
2862TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002863 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002864 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002865 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2866 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002867 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002868 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002869 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002870
deadbeef0ed85b22016-02-23 17:24:52 -08002871 offer.reset(CreateRemoteOffer());
2872 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2873 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002874}
2875
Honghai Zhang04e91462015-12-11 14:26:22 -08002876// Test that if the remote offer indicates the peer requested ICE restart (via
2877// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2878TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002879 Init();
honghaiz503726c2015-07-31 12:37:38 -07002880
2881 // Create the first offer.
deadbeef0ed85b22016-02-23 17:24:52 -08002882 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2883 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002884 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2885 0, "", "", "relay", 0, "");
2886 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2887 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002888 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2889 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002890 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2891
2892 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002893 offer.reset(CreateRemoteOffer());
2894 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002895 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2896 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2897 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002898 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2899 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002900 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2901
2902 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002903 offer.reset(CreateRemoteOffer());
2904 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002905 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2906 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2907 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002908 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2909 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002910 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2911
2912 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002913 offer.reset(CreateRemoteOffer());
2914 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2915 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002916 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2917}
2918
Honghai Zhang04e91462015-12-11 14:26:22 -08002919// Test that if the remote answer indicates the peer requested ICE restart (via
2920// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2921TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2922 Init();
2923 SessionDescriptionInterface* offer = CreateOffer();
2924 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002925
2926 // Create the first answer.
deadbeef0ed85b22016-02-23 17:24:52 -08002927 scoped_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
2928 answer->set_type(JsepSessionDescription::kPrAnswer);
2929 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002930 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2931 0, "", "", "relay", 0, "");
2932 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2933 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002934 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2935 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002936 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2937
2938 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002939 answer.reset(CreateRemoteAnswer(offer));
2940 answer->set_type(JsepSessionDescription::kPrAnswer);
2941 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002942 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2943 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2944 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002945 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2946 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002947 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2948
2949 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002950 answer.reset(CreateRemoteAnswer(offer));
2951 answer->set_type(JsepSessionDescription::kPrAnswer);
2952 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002953 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2954 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2955 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002956 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2957 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002958 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2959
2960 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002961 answer.reset(CreateRemoteAnswer(offer));
2962 answer->set_type(JsepSessionDescription::kPrAnswer);
2963 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2964 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002965 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2966}
2967
Donald Curtisd4f769d2015-05-28 09:48:21 -07002968// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002969// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002970TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2971 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2972
2973 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002974 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002975
2976 PeerConnectionInterface::RTCOfferAnswerOptions options;
2977 options.use_rtp_mux = true;
2978
2979 SessionDescriptionInterface* offer = CreateRemoteOffer();
2980 SetRemoteDescriptionWithoutError(offer);
2981
htaa2a49d92016-03-04 02:51:39 -08002982 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002983 SetLocalDescriptionWithoutError(answer);
2984
deadbeefcbecd352015-09-23 11:50:27 -07002985 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2986 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002987
deadbeefcbecd352015-09-23 11:50:27 -07002988 cricket::BaseChannel* voice_channel = session_->voice_channel();
2989 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002990
2991 // Checks if one of the transport channels contains a connection using a given
2992 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002993 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002994 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002995 session_->GetChannelTransportStats(voice_channel, &stats);
2996 for (auto& kv : stats.transport_stats) {
2997 for (auto& chan_stat : kv.second.channel_stats) {
2998 for (auto& conn_info : chan_stat.connection_infos) {
2999 if (conn_info.remote_candidate.address().port() == port) {
3000 return true;
3001 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003002 }
3003 }
3004 }
3005 return false;
3006 };
3007
3008 EXPECT_FALSE(connection_with_remote_port(5000));
3009 EXPECT_FALSE(connection_with_remote_port(5001));
3010 EXPECT_FALSE(connection_with_remote_port(6000));
3011
3012 // The way the *_WAIT checks work is they only wait if the condition fails,
3013 // which does not help in the case where state is not changing. This is
3014 // problematic in this test since we want to verify that adding a video
3015 // candidate does _not_ change state. So we interleave candidates and assume
3016 // that messages are executed in the order they were posted.
3017
3018 // First audio candidate.
3019 cricket::Candidate candidate0;
3020 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3021 candidate0.set_component(1);
3022 candidate0.set_protocol("udp");
3023 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3024 candidate0);
3025 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3026
3027 // Video candidate.
3028 cricket::Candidate candidate1;
3029 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3030 candidate1.set_component(1);
3031 candidate1.set_protocol("udp");
3032 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3033 candidate1);
3034 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3035
3036 // Second audio candidate.
3037 cricket::Candidate candidate2;
3038 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3039 candidate2.set_component(1);
3040 candidate2.set_protocol("udp");
3041 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3042 candidate2);
3043 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3044
3045 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3046 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3047
3048 // No need here for a _WAIT check since we are checking that state hasn't
3049 // changed: if this is false we would be doing waits for nothing and if this
3050 // is true then there will be no messages processed anyways.
3051 EXPECT_FALSE(connection_with_remote_port(6000));
3052}
3053
deadbeefcbecd352015-09-23 11:50:27 -07003054// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003055TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3056 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003057 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003058
3059 PeerConnectionInterface::RTCOfferAnswerOptions options;
3060 options.use_rtp_mux = true;
3061
3062 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003063 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003064
deadbeefcbecd352015-09-23 11:50:27 -07003065 EXPECT_NE(session_->voice_rtp_transport_channel(),
3066 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003067
deadbeefab9b2d12015-10-14 11:33:11 -07003068 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003069 SessionDescriptionInterface* answer =
3070 CreateRemoteAnswer(session_->local_description());
3071 SetRemoteDescriptionWithoutError(answer);
3072
deadbeefcbecd352015-09-23 11:50:27 -07003073 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3074 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003075}
3076
deadbeefcbecd352015-09-23 11:50:27 -07003077// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003078TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3079 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003080 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003081
Donald Curtis0e209b02015-03-24 09:29:54 -07003082 PeerConnectionInterface::RTCOfferAnswerOptions options;
3083 options.use_rtp_mux = true;
3084
3085 SessionDescriptionInterface* offer = CreateOffer(options);
3086 SetLocalDescriptionWithoutError(offer);
3087
deadbeefcbecd352015-09-23 11:50:27 -07003088 EXPECT_NE(session_->voice_rtp_transport_channel(),
3089 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003090
deadbeefab9b2d12015-10-14 11:33:11 -07003091 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003092
3093 // Remove BUNDLE from the answer.
3094 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3095 CreateRemoteAnswer(session_->local_description()));
3096 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3097 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3098 JsepSessionDescription* modified_answer =
3099 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3100 modified_answer->Initialize(answer_copy, "1", "1");
3101 SetRemoteDescriptionWithoutError(modified_answer); //
3102
deadbeefcbecd352015-09-23 11:50:27 -07003103 EXPECT_NE(session_->voice_rtp_transport_channel(),
3104 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003105}
3106
3107// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3108TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3109 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003110 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003111
3112 PeerConnectionInterface::RTCOfferAnswerOptions options;
3113 options.use_rtp_mux = true;
3114
3115 SessionDescriptionInterface* offer = CreateOffer(options);
3116 SetLocalDescriptionWithoutError(offer);
3117
deadbeefcbecd352015-09-23 11:50:27 -07003118 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3119 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003120
deadbeefab9b2d12015-10-14 11:33:11 -07003121 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003122 SessionDescriptionInterface* answer =
3123 CreateRemoteAnswer(session_->local_description());
3124 SetRemoteDescriptionWithoutError(answer);
3125
deadbeefcbecd352015-09-23 11:50:27 -07003126 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3127 session_->video_rtp_transport_channel());
3128}
3129
3130// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3131// audio content in the answer.
3132TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3133 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003134 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003135
3136 PeerConnectionInterface::RTCOfferAnswerOptions options;
3137 options.use_rtp_mux = true;
3138
3139 SessionDescriptionInterface* offer = CreateOffer(options);
3140 SetLocalDescriptionWithoutError(offer);
3141
3142 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3143 session_->video_rtp_transport_channel());
3144
deadbeefab9b2d12015-10-14 11:33:11 -07003145 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003146 cricket::MediaSessionOptions recv_options;
3147 recv_options.recv_audio = false;
3148 recv_options.recv_video = true;
3149 SessionDescriptionInterface* answer =
3150 CreateRemoteAnswer(session_->local_description(), recv_options);
3151 SetRemoteDescriptionWithoutError(answer);
3152
deadbeefd59daf82015-10-14 15:02:44 -07003153 EXPECT_TRUE(nullptr == session_->voice_channel());
3154 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003155
deadbeefd59daf82015-10-14 15:02:44 -07003156 session_->Close();
3157 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3158 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3159 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3160 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003161}
3162
3163// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3164TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3165 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003166 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003167
Donald Curtis0e209b02015-03-24 09:29:54 -07003168 PeerConnectionInterface::RTCOfferAnswerOptions options;
3169 options.use_rtp_mux = true;
3170
3171 SessionDescriptionInterface* offer = CreateOffer(options);
3172 SetLocalDescriptionWithoutError(offer);
3173
deadbeefcbecd352015-09-23 11:50:27 -07003174 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3175 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003176
deadbeefab9b2d12015-10-14 11:33:11 -07003177 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003178
3179 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003180 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003181 CreateRemoteAnswer(session_->local_description()));
3182 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3183 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3184 JsepSessionDescription* modified_answer =
3185 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3186 modified_answer->Initialize(answer_copy, "1", "1");
3187 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003188
deadbeefcbecd352015-09-23 11:50:27 -07003189 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3190 session_->video_rtp_transport_channel());
3191}
3192
3193// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3194TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3195 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003196 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003197
3198 SessionDescriptionInterface* offer = CreateRemoteOffer();
3199 SetRemoteDescriptionWithoutError(offer);
3200
3201 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3202 session_->video_rtp_transport_channel());
3203
deadbeefab9b2d12015-10-14 11:33:11 -07003204 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003205 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003206 SetLocalDescriptionWithoutError(answer);
3207
3208 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3209 session_->video_rtp_transport_channel());
3210}
3211
3212// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3213TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3214 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003215 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003216
3217 // Remove BUNDLE from the offer.
3218 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3219 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3220 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3221 JsepSessionDescription* modified_offer =
3222 new JsepSessionDescription(JsepSessionDescription::kOffer);
3223 modified_offer->Initialize(offer_copy, "1", "1");
3224
3225 // Expect an error when applying the remote description
3226 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3227 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003228}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003229
Peter Thatcher4eddf182015-04-30 10:55:59 -07003230// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003231TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3232 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003233 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003234
Donald Curtis0e209b02015-03-24 09:29:54 -07003235 PeerConnectionInterface::RTCOfferAnswerOptions options;
3236 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003237
Donald Curtis0e209b02015-03-24 09:29:54 -07003238 SessionDescriptionInterface* offer = CreateOffer(options);
3239 SetLocalDescriptionWithoutError(offer);
3240
deadbeefcbecd352015-09-23 11:50:27 -07003241 EXPECT_NE(session_->voice_rtp_transport_channel(),
3242 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003243
deadbeefab9b2d12015-10-14 11:33:11 -07003244 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003245 SessionDescriptionInterface* answer =
3246 CreateRemoteAnswer(session_->local_description());
3247 SetRemoteDescriptionWithoutError(answer);
3248
3249 // This should lead to an audio-only call but isn't implemented
3250 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003251 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3252 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003253}
3254
deadbeefcbecd352015-09-23 11:50:27 -07003255// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003256TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3257 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003258 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003259 PeerConnectionInterface::RTCOfferAnswerOptions options;
3260 options.use_rtp_mux = true;
3261
3262 SessionDescriptionInterface* offer = CreateOffer(options);
3263 SetLocalDescriptionWithoutError(offer);
3264
deadbeefcbecd352015-09-23 11:50:27 -07003265 EXPECT_NE(session_->voice_rtp_transport_channel(),
3266 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003267
deadbeefab9b2d12015-10-14 11:33:11 -07003268 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003269
3270 // Remove BUNDLE from the answer.
3271 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3272 CreateRemoteAnswer(session_->local_description()));
3273 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3274 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3275 JsepSessionDescription* modified_answer =
3276 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3277 modified_answer->Initialize(answer_copy, "1", "1");
3278 SetRemoteDescriptionWithoutError(modified_answer); //
3279
deadbeefcbecd352015-09-23 11:50:27 -07003280 EXPECT_NE(session_->voice_rtp_transport_channel(),
3281 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003282}
3283
Peter Thatcher4eddf182015-04-30 10:55:59 -07003284// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3285TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3286 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003287 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003288
3289 PeerConnectionInterface::RTCOfferAnswerOptions options;
3290 options.use_rtp_mux = true;
3291
3292 SessionDescriptionInterface* offer = CreateOffer(options);
3293 SetRemoteDescriptionWithoutError(offer);
3294
deadbeefcbecd352015-09-23 11:50:27 -07003295 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3296 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003297}
3298
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003299TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3300 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003301 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003302
3303 PeerConnectionInterface::RTCOfferAnswerOptions options;
3304 SessionDescriptionInterface* offer = CreateOffer(options);
3305 SetLocalDescriptionWithoutError(offer);
3306
deadbeefcbecd352015-09-23 11:50:27 -07003307 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3308 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003309
deadbeefab9b2d12015-10-14 11:33:11 -07003310 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003311 SessionDescriptionInterface* answer =
3312 CreateRemoteAnswer(session_->local_description());
3313 SetRemoteDescriptionWithoutError(answer);
3314
deadbeefcbecd352015-09-23 11:50:27 -07003315 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3316 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003317}
3318
3319TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3320 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003321 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003322
3323 PeerConnectionInterface::RTCOfferAnswerOptions options;
3324 SessionDescriptionInterface* offer = CreateOffer(options);
3325 SetLocalDescriptionWithoutError(offer);
3326
deadbeefcbecd352015-09-23 11:50:27 -07003327 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3328 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003329
deadbeefab9b2d12015-10-14 11:33:11 -07003330 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003331 SessionDescriptionInterface* answer =
3332 CreateRemoteAnswer(session_->local_description());
3333 SetRemoteDescriptionWithoutError(answer);
3334
deadbeefcbecd352015-09-23 11:50:27 -07003335 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3336 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003337}
3338
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003339// This test verifies that SetLocalDescription and SetRemoteDescription fails
3340// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3341TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003342 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003343 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003344
3345 PeerConnectionInterface::RTCOfferAnswerOptions options;
3346 options.use_rtp_mux = true;
3347
3348 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003349 std::string offer_str;
3350 offer->ToString(&offer_str);
3351 // Disable rtcp-mux
3352 const std::string rtcp_mux = "rtcp-mux";
3353 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003354 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003355 xrtcp_mux.c_str(), xrtcp_mux.length(),
3356 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003357 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003358 new JsepSessionDescription(JsepSessionDescription::kOffer);
3359 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003360 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003361 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003362 new JsepSessionDescription(JsepSessionDescription::kOffer);
3363 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003364 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003365 // Trying unmodified SDP.
3366 SetLocalDescriptionWithoutError(offer);
3367}
3368
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003369TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003370 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003371 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003372 CreateAndSetRemoteOfferAndLocalAnswer();
3373 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3374 ASSERT_TRUE(channel != NULL);
3375 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003376 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003377 double volume;
3378 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3379 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003380 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003381 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3382 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003383 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003384 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3385 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003386}
3387
3388TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003389 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003390 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003391 CreateAndSetRemoteOfferAndLocalAnswer();
3392 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3393 ASSERT_TRUE(channel != NULL);
3394 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003395 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003396 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3397
3398 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003399 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003400
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003401 rtc::scoped_ptr<FakeAudioSource> source(new FakeAudioSource());
3402 session_->SetAudioSend(send_ssrc, false, options, source.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003403 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003404 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003405 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003406
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003407 // This will trigger SetSink(nullptr) to the |source|.
3408 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003409 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003410 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003411 EXPECT_TRUE(source->sink() == nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003412}
3413
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003414TEST_F(WebRtcSessionTest, AudioSourceForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003415 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003416 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003417 CreateAndSetRemoteOfferAndLocalAnswer();
3418 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3419 ASSERT_TRUE(channel != NULL);
3420 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003421 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003422
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003423 rtc::scoped_ptr<FakeAudioSource> source(new FakeAudioSource());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003424 cricket::AudioOptions options;
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003425 session_->SetAudioSend(send_ssrc, true, options, source.get());
3426 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003427
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003428 // Delete the |source| and it will trigger OnClose() to the sink, and this
3429 // will invalidate the |source_| pointer in the sink and prevent getting a
3430 // SetSink(nullptr) callback afterwards.
3431 source.reset();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003432
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003433 // This will trigger SetSink(nullptr) if no OnClose() callback.
3434 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003435}
3436
3437TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003438 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003439 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003440 CreateAndSetRemoteOfferAndLocalAnswer();
3441 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3442 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003443 ASSERT_LT(0u, channel->sinks().size());
3444 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003445 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003446 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003447 cricket::FakeVideoRenderer renderer;
3448 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003449 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003450 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003451 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003452}
3453
3454TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003455 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003456 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003457 CreateAndSetRemoteOfferAndLocalAnswer();
3458 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3459 ASSERT_TRUE(channel != NULL);
3460 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003461 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003462 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3463 cricket::VideoOptions* options = NULL;
3464 session_->SetVideoSend(send_ssrc, false, options);
3465 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3466 session_->SetVideoSend(send_ssrc, true, options);
3467 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3468}
3469
3470TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3471 TestCanInsertDtmf(false);
3472}
3473
3474TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3475 TestCanInsertDtmf(true);
3476}
3477
3478TEST_F(WebRtcSessionTest, InsertDtmf) {
3479 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003480 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003481 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003482 CreateAndSetRemoteOfferAndLocalAnswer();
3483 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3484 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3485
3486 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003487 const int expected_duration = 90;
3488 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3489 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3490 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3491
3492 // Verify
3493 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003494 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003496 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003497 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003498 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003499 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003500 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501}
3502
deadbeefd59daf82015-10-14 15:02:44 -07003503// This test verifies the |initial_offerer| flag when session initiates the
3504// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003505TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003506 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003507 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003508 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003509 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3510 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003511 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003512 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003513 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003514}
3515
deadbeefd59daf82015-10-14 15:02:44 -07003516// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003517TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003518 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003519 EXPECT_FALSE(session_->initial_offerer());
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
deadbeefd59daf82015-10-14 15:02:44 -07003524 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003525 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003526 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003527}
3528
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003529// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3530TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003531 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003532 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003533 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003534 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003535 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003536 CreateRemoteAnswer(session_->local_description()));
3537
3538 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3539 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003540 JsepSessionDescription* modified_answer =
3541 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003542
3543 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3544 answer->session_id(),
3545 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003546 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003547
wu@webrtc.org4e393072014-04-07 17:04:35 +00003548 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003549 std::string sdp;
3550 EXPECT_TRUE(answer->ToString(&sdp));
3551 const std::string kAudioMid = "a=mid:audio";
3552 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003553 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003554 kAudioMidReplaceStr.c_str(),
3555 kAudioMidReplaceStr.length(),
3556 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003557 SessionDescriptionInterface* modified_answer1 =
3558 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003559 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003560
wu@webrtc.org4e393072014-04-07 17:04:35 +00003561 // Different media types.
3562 EXPECT_TRUE(answer->ToString(&sdp));
3563 const std::string kAudioMline = "m=audio";
3564 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003565 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003566 kAudioMlineReplaceStr.c_str(),
3567 kAudioMlineReplaceStr.length(),
3568 &sdp);
3569 SessionDescriptionInterface* modified_answer2 =
3570 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3571 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3572
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003573 SetRemoteDescriptionWithoutError(answer.release());
3574}
3575
3576// Verifying remote offer and local answer have matching m-lines as per
3577// RFC 3264.
3578TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003579 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003580 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003581 SessionDescriptionInterface* offer = CreateRemoteOffer();
3582 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003583 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003584
3585 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3586 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003587 JsepSessionDescription* modified_answer =
3588 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003589
3590 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3591 answer->session_id(),
3592 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003593 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003594 SetLocalDescriptionWithoutError(answer);
3595}
3596
3597// This test verifies that WebRtcSession does not start candidate allocation
3598// before SetLocalDescription is called.
3599TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003600 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003601 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003602 SessionDescriptionInterface* offer = CreateRemoteOffer();
3603 cricket::Candidate candidate;
3604 candidate.set_component(1);
3605 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3606 candidate);
3607 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3608 cricket::Candidate candidate1;
3609 candidate1.set_component(1);
3610 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3611 candidate1);
3612 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3613 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003614 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3615 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003616
3617 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003618 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003619 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3620 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3621
htaa2a49d92016-03-04 02:51:39 -08003622 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003623 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003624 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3625}
3626
3627// This test verifies that crypto parameter is updated in local session
3628// description as per security policy set in MediaSessionDescriptionFactory.
3629TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003630 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003631 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003632 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003633
3634 // Making sure SetLocalDescription correctly sets crypto value in
3635 // SessionDescription object after de-serialization of sdp string. The value
3636 // will be set as per MediaSessionDescriptionFactory.
3637 std::string offer_str;
3638 offer->ToString(&offer_str);
3639 SessionDescriptionInterface* jsep_offer_str =
3640 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3641 SetLocalDescriptionWithoutError(jsep_offer_str);
3642 EXPECT_TRUE(session_->voice_channel()->secure_required());
3643 EXPECT_TRUE(session_->video_channel()->secure_required());
3644}
3645
3646// This test verifies the crypto parameter when security is disabled.
3647TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003648 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003649 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003650 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003651 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003652
3653 // Making sure SetLocalDescription correctly sets crypto value in
3654 // SessionDescription object after de-serialization of sdp string. The value
3655 // will be set as per MediaSessionDescriptionFactory.
3656 std::string offer_str;
3657 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003658 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003659 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3660 SetLocalDescriptionWithoutError(jsep_offer_str);
3661 EXPECT_FALSE(session_->voice_channel()->secure_required());
3662 EXPECT_FALSE(session_->video_channel()->secure_required());
3663}
3664
3665// This test verifies that an answer contains new ufrag and password if an offer
3666// with new ufrag and password is received.
3667TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003668 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003669 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003670 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003671 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003672 CreateRemoteOffer(options));
3673 SetRemoteDescriptionWithoutError(offer.release());
3674
deadbeefab9b2d12015-10-14 11:33:11 -07003675 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003676 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003677 SetLocalDescriptionWithoutError(answer.release());
3678
3679 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003680 for (const cricket::ContentInfo& content :
3681 session_->local_description()->description()->contents()) {
3682 options.transport_options[content.name].ice_restart = true;
3683 }
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003684 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003685 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003686 SetRemoteDescriptionWithoutError(updated_offer1.release());
3687
htaa2a49d92016-03-04 02:51:39 -08003688 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003689
deadbeef0ed85b22016-02-23 17:24:52 -08003690 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3691 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003692
deadbeef0ed85b22016-02-23 17:24:52 -08003693 // Even a second answer (created before the description is set) should have
3694 // a new ufrag/password.
htaa2a49d92016-03-04 02:51:39 -08003695 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003696
3697 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3698 session_->local_description()->description()));
3699
3700 SetLocalDescriptionWithoutError(updated_answer2.release());
3701}
3702
3703// This test verifies that an answer contains new ufrag and password if an offer
3704// that changes either the ufrag or password (but not both) is received.
3705// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3706// a=ice-pwd attributes compared to the previous SDP from the peer, it
3707// indicates that ICE is restarting for this media stream."
3708TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3709 Init();
3710 cricket::MediaSessionOptions options;
3711 options.recv_audio = true;
3712 options.recv_video = true;
3713 // Create an offer with audio and video.
3714 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3715 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3716 SetRemoteDescriptionWithoutError(offer.release());
3717
3718 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003719 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003720 SetLocalDescriptionWithoutError(answer.release());
3721
3722 // Receive an offer with a new ufrag but stale password.
3723 rtc::scoped_ptr<JsepSessionDescription> ufrag_changed_offer(
3724 CreateRemoteOffer(options, session_->remote_description()));
3725 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3726 "original_password12345");
3727 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3728
htaa2a49d92016-03-04 02:51:39 -08003729 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003730 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3731 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003732 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003733
3734 // Receive an offer with a new password but stale ufrag.
3735 rtc::scoped_ptr<JsepSessionDescription> password_changed_offer(
3736 CreateRemoteOffer(options, session_->remote_description()));
3737 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3738 "modified_password12345");
3739 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3740
htaa2a49d92016-03-04 02:51:39 -08003741 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003742 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3743 session_->local_description()->description()));
3744 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003745}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003746
wu@webrtc.org91053e72013-08-10 07:18:04 +00003747// This test verifies that an answer contains old ufrag and password if an offer
3748// with old ufrag and password is received.
3749TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003750 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003751 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003752 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003753 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003754 CreateRemoteOffer(options));
3755 SetRemoteDescriptionWithoutError(offer.release());
3756
deadbeefab9b2d12015-10-14 11:33:11 -07003757 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003758 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003759 SetLocalDescriptionWithoutError(answer.release());
3760
3761 // Receive an offer without changed ufrag or password.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003762 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003763 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003764 SetRemoteDescriptionWithoutError(updated_offer2.release());
3765
htaa2a49d92016-03-04 02:51:39 -08003766 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003767
deadbeef0ed85b22016-02-23 17:24:52 -08003768 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3769 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003770
3771 SetLocalDescriptionWithoutError(updated_answer2.release());
3772}
3773
deadbeef0ed85b22016-02-23 17:24:52 -08003774// This test verifies that if an offer does an ICE restart on some, but not all
3775// media sections, the answer will change the ufrag/password in the correct
3776// media sections.
3777TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3778 Init();
3779 cricket::MediaSessionOptions options;
3780 options.recv_video = true;
3781 options.recv_audio = true;
3782 options.bundle_enabled = false;
3783 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3784
3785 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3786 "aaaaaaaaaaaaaaaaaaaaaa");
3787 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3788 "bbbbbbbbbbbbbbbbbbbbbb");
3789 SetRemoteDescriptionWithoutError(offer.release());
3790
3791 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003792 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003793 SetLocalDescriptionWithoutError(answer.release());
3794
3795 // Receive an offer with new ufrag and password, but only for the video media
3796 // section.
3797 rtc::scoped_ptr<JsepSessionDescription> updated_offer(
3798 CreateRemoteOffer(options, session_->remote_description()));
3799 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3800 "cccccccccccccccccccccc");
3801 SetRemoteDescriptionWithoutError(updated_offer.release());
3802
htaa2a49d92016-03-04 02:51:39 -08003803 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003804
3805 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3806 session_->local_description()->description(),
3807 cricket::MEDIA_TYPE_AUDIO));
3808
3809 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3810 session_->local_description()->description(),
3811 cricket::MEDIA_TYPE_VIDEO));
3812
3813 SetLocalDescriptionWithoutError(updated_answer.release());
3814}
3815
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003816TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003817 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003818 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003819 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003820 const std::string session_id_orig = offer->session_id();
3821 const std::string session_version_orig = offer->session_version();
3822 SetLocalDescriptionWithoutError(offer);
3823
3824 video_channel_ = media_engine_->GetVideoChannel(0);
3825 video_channel_->set_fail_set_send_codecs(true);
3826
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003827 SessionDescriptionInterface* answer =
3828 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003829 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003830
3831 // Test that after a content error, setting any description will
3832 // result in an error.
3833 video_channel_->set_fail_set_send_codecs(false);
3834 answer = CreateRemoteAnswer(session_->local_description());
3835 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3836 offer = CreateRemoteOffer();
3837 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003838}
3839
3840// Runs the loopback call test with BUNDLE and STUN disabled.
3841TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3842 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003843 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003844 cricket::PORTALLOCATOR_DISABLE_STUN |
3845 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003846 TestLoopbackCall();
3847}
3848
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003849TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003850 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003851 cricket::PORTALLOCATOR_DISABLE_STUN |
3852 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3853 cricket::PORTALLOCATOR_DISABLE_RELAY);
3854
3855 // best connection is IPv6 since it has higher network preference.
3856 LoopbackNetworkConfiguration config;
3857 config.test_ipv6_network_ = true;
3858 config.best_connection_after_initial_ice_converged_ =
3859 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3860
3861 TestLoopbackCall(config);
3862}
3863
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003864// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003865TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003866 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3867 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003868 TestLoopbackCall();
3869}
3870
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003871TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003872 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003873 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003874 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003875 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003876 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3877}
3878
Henrik Boström87713d02015-08-25 09:53:21 +02003879TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003880 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003881
htaa2a49d92016-03-04 02:51:39 -08003882 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003883 options_.disable_sctp_data_channels = false;
3884
Henrik Boström87713d02015-08-25 09:53:21 +02003885 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003886
3887 SetLocalDescriptionWithDataChannel();
3888 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3889}
3890
Henrik Boström87713d02015-08-25 09:53:21 +02003891TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003892 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003893
Henrik Boström87713d02015-08-25 09:53:21 +02003894 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003895
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003896 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003897 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003898 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3899}
3900
Henrik Boström87713d02015-08-25 09:53:21 +02003901TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003902 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003903 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003904 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003905
3906 // Create remote offer with SCTP.
3907 cricket::MediaSessionOptions options;
3908 options.data_channel_type = cricket::DCT_SCTP;
3909 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003910 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003911 SetRemoteDescriptionWithoutError(offer);
3912
3913 // Verifies the answer contains SCTP.
htaa2a49d92016-03-04 02:51:39 -08003914 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003915 EXPECT_TRUE(answer != NULL);
3916 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3917 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003918}
3919
Henrik Boström87713d02015-08-25 09:53:21 +02003920TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003921 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003922 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003923
3924 SetLocalDescriptionWithDataChannel();
3925 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3926}
3927
Henrik Boström87713d02015-08-25 09:53:21 +02003928TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003929 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003930
Henrik Boström87713d02015-08-25 09:53:21 +02003931 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003932
3933 SetLocalDescriptionWithDataChannel();
3934 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3935}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003936
Henrik Boström87713d02015-08-25 09:53:21 +02003937TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003938 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003939 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003940 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003941
3942 SetLocalDescriptionWithDataChannel();
3943 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3944}
3945
Henrik Boström87713d02015-08-25 09:53:21 +02003946TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003947 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003948 const int new_send_port = 9998;
3949 const int new_recv_port = 7775;
3950
Henrik Boström87713d02015-08-25 09:53:21 +02003951 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003952 SetFactoryDtlsSrtp();
3953
3954 // By default, don't actually add the codecs to desc_factory_; they don't
3955 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3956 // let the session description get parsed. That'll get the proper codecs
3957 // into the stream.
3958 cricket::MediaSessionOptions options;
3959 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3960 "stream1", new_send_port, options);
3961
3962 // SetRemoteDescription will take the ownership of the offer.
3963 SetRemoteDescriptionWithoutError(offer);
3964
htaa2a49d92016-03-04 02:51:39 -08003965 SessionDescriptionInterface* answer =
3966 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003967 ASSERT_TRUE(answer != NULL);
3968
3969 // Now set the local description, which'll take ownership of the answer.
3970 SetLocalDescriptionWithoutError(answer);
3971
3972 // TEST PLAN: Set the port number to something new, set it in the SDP,
3973 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003974 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003975 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003976
3977 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3978 int portnum = -1;
3979 ASSERT_TRUE(ch != NULL);
3980 ASSERT_EQ(1UL, ch->send_codecs().size());
3981 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003982 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003983 ch->send_codecs()[0].name.c_str()));
3984 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3985 &portnum));
3986 EXPECT_EQ(new_send_port, portnum);
3987
3988 ASSERT_EQ(1UL, ch->recv_codecs().size());
3989 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003990 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003991 ch->recv_codecs()[0].name.c_str()));
3992 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3993 &portnum));
3994 EXPECT_EQ(new_recv_port, portnum);
3995}
3996
deadbeefab9b2d12015-10-14 11:33:11 -07003997// Verifies that when a session's DataChannel receives an OPEN message,
3998// WebRtcSession signals the DataChannel creation request with the expected
3999// config.
4000TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
4001 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4002
4003 InitWithDtls(GetParam());
4004
4005 SetLocalDescriptionWithDataChannel();
4006 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4007
4008 webrtc::DataChannelInit config;
4009 config.id = 1;
4010 rtc::Buffer payload;
4011 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4012 cricket::ReceiveDataParams params;
4013 params.ssrc = config.id;
4014 params.type = cricket::DMT_CONTROL;
4015
4016 cricket::DataChannel* data_channel = session_->data_channel();
4017 data_channel->SignalDataReceived(data_channel, params, payload);
4018
4019 EXPECT_EQ("a", last_data_channel_label_);
4020 EXPECT_EQ(config.id, last_data_channel_config_.id);
4021 EXPECT_FALSE(last_data_channel_config_.negotiated);
4022 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4023 last_data_channel_config_.open_handshake_role);
4024}
4025
4026TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004027 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
4028 FakeDtlsIdentityStore::GenerateCertificate();
4029
htaa2a49d92016-03-04 02:51:39 -08004030 configuration_.certificates.push_back(certificate);
4031 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004032 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4033
4034 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4035}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004036
Henrik Boström87713d02015-08-25 09:53:21 +02004037// Verifies that CreateOffer succeeds when CreateOffer is called before async
4038// identity generation is finished (even if a certificate is provided this is
4039// an async op).
4040TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4041 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4042 InitWithDtls(GetParam());
4043
Henrik Boströmd8281982015-08-27 10:12:24 +02004044 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004045 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004046 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
4047
wu@webrtc.org91053e72013-08-10 07:18:04 +00004048 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004049 VerifyNoCryptoParams(offer->description(), true);
4050 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004051}
4052
4053// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004054// identity generation is finished (even if a certificate is provided this is
4055// an async op).
4056TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004057 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004058 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004059 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004060
4061 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004062 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00004063 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004064 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004065 ASSERT_TRUE(offer.get() != NULL);
4066 SetRemoteDescriptionWithoutError(offer.release());
4067
htaa2a49d92016-03-04 02:51:39 -08004068 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004069 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004070 VerifyNoCryptoParams(answer->description(), true);
4071 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004072}
4073
4074// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004075// identity generation is finished (even if a certificate is provided this is
4076// an async op).
4077TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004078 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004079 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004080
Henrik Boströmd8281982015-08-27 10:12:24 +02004081 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004082
4083 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004084 EXPECT_TRUE(offer != NULL);
4085}
4086
4087// Verifies that CreateOffer fails when CreateOffer is called after async
4088// identity generation fails.
4089TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004090 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004091 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004092
Henrik Boströmd8281982015-08-27 10:12:24 +02004093 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004094
4095 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004096 EXPECT_TRUE(offer == NULL);
4097}
4098
4099// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4100// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004101TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004102 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004103 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004104 VerifyMultipleAsyncCreateDescription(GetParam(),
4105 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004106}
4107
4108// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4109// before async identity generation fails.
4110TEST_F(WebRtcSessionTest,
4111 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004112 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004113 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4114 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004115}
4116
4117// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4118// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004119TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004120 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004121 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004122 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004123 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004124}
4125
4126// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4127// before async identity generation fails.
4128TEST_F(WebRtcSessionTest,
4129 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004130 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004131 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4132 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004133}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004134
4135// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4136// offer has no SDES crypto but only DTLS fingerprint.
4137TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4138 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004139 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004140 // Create a remote offer with secured transport disabled.
4141 cricket::MediaSessionOptions options;
4142 JsepSessionDescription* offer(CreateRemoteOffer(
4143 options, cricket::SEC_DISABLED));
4144 // Adds a DTLS fingerprint to the remote offer.
4145 cricket::SessionDescription* sdp = offer->description();
4146 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4147 ASSERT_TRUE(audio != NULL);
4148 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4149 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004150 rtc::SSLFingerprint::CreateFromRfc4572(
4151 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004152 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004153 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004154}
4155
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004156TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004157 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004158 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004159 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004160 SessionDescriptionInterface* offer = CreateOffer();
4161
4162 SetLocalDescriptionWithoutError(offer);
4163
4164 voice_channel_ = media_engine_->GetVoiceChannel(0);
4165
4166 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004167 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004168 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004169}
4170
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004171// Tests that we can renegotiate new media content with ICE candidates in the
4172// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004173TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004174 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004175 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004176 SetFactoryDtlsSrtp();
4177
deadbeefab9b2d12015-10-14 11:33:11 -07004178 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004179 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004180 SetLocalDescriptionWithoutError(offer);
4181
4182 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4183 SetRemoteDescriptionWithoutError(answer);
4184
4185 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004186 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004187 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4188
4189 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004190 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004191 candidate1.set_component(1);
4192 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4193 candidate1);
4194 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4195 SetRemoteDescriptionWithoutError(offer);
4196
htaa2a49d92016-03-04 02:51:39 -08004197 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004198 SetLocalDescriptionWithoutError(answer);
4199}
4200
4201// Tests that we can renegotiate new media content with ICE candidates separated
4202// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004203TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004204 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004205 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004206 SetFactoryDtlsSrtp();
4207
deadbeefab9b2d12015-10-14 11:33:11 -07004208 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004209 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004210 SetLocalDescriptionWithoutError(offer);
4211
4212 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4213 SetRemoteDescriptionWithoutError(answer);
4214
4215 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004216 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004217 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4218 SetRemoteDescriptionWithoutError(offer);
4219
4220 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004221 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004222 candidate1.set_component(1);
4223 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4224 candidate1);
4225 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4226
htaa2a49d92016-03-04 02:51:39 -08004227 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004228 SetLocalDescriptionWithoutError(answer);
4229}
honghaiz7f777492016-02-02 21:54:01 -08004230
4231// Flaky on Win and Mac only. See webrtc:4943
4232#if defined(WEBRTC_WIN) || defined(WEBRTC_MAC)
4233#define MAYBE_TestRtxRemovedByCreateAnswer DISABLED_TestRtxRemovedByCreateAnswer
4234#else
4235#define MAYBE_TestRtxRemovedByCreateAnswer TestRtxRemovedByCreateAnswer
4236#endif
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004237// Tests that RTX codec is removed from the answer when it isn't supported
4238// by local side.
honghaiz7f777492016-02-02 21:54:01 -08004239TEST_F(WebRtcSessionTest, MAYBE_TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004240 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004241 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004242 std::string offer_sdp(kSdpWithRtx);
4243
4244 SessionDescriptionInterface* offer =
4245 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4246 EXPECT_TRUE(offer->ToString(&offer_sdp));
4247
4248 // Offer SDP contains the RTX codec.
4249 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4250 SetRemoteDescriptionWithoutError(offer);
4251
htaa2a49d92016-03-04 02:51:39 -08004252 SessionDescriptionInterface* answer = CreateAnswer();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004253 std::string answer_sdp;
4254 answer->ToString(&answer_sdp);
4255 // Answer SDP removes the unsupported RTX codec.
4256 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4257 SetLocalDescriptionWithoutError(answer);
4258}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004259
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004260// This verifies that the voice channel after bundle has both options from video
4261// and voice channels.
4262TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4263 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004264 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004265
4266 PeerConnectionInterface::RTCOfferAnswerOptions options;
4267 options.use_rtp_mux = true;
4268
4269 SessionDescriptionInterface* offer = CreateOffer(options);
4270 SetLocalDescriptionWithoutError(offer);
4271
4272 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4273 rtc::Socket::Option::OPT_SNDBUF, 4000);
4274
4275 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4276 rtc::Socket::Option::OPT_RCVBUF, 8000);
4277
4278 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004279 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004280 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4281 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004282 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004283 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4284
deadbeefcbecd352015-09-23 11:50:27 -07004285 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004286 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4287 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004288 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004289 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4290
deadbeefcbecd352015-09-23 11:50:27 -07004291 EXPECT_NE(session_->voice_rtp_transport_channel(),
4292 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004293
deadbeefab9b2d12015-10-14 11:33:11 -07004294 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004295 SessionDescriptionInterface* answer =
4296 CreateRemoteAnswer(session_->local_description());
4297 SetRemoteDescriptionWithoutError(answer);
4298
deadbeefcbecd352015-09-23 11:50:27 -07004299 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004300 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4301 EXPECT_EQ(4000, option_val);
4302
deadbeefcbecd352015-09-23 11:50:27 -07004303 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004304 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4305 EXPECT_EQ(8000, option_val);
4306}
4307
tommi0f620f42015-07-09 03:25:02 -07004308// Test creating a session, request multiple offers, destroy the session
4309// and make sure we got success/failure callbacks for all of the requests.
4310// Background: crbug.com/507307
4311TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4312 Init();
4313
4314 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4315 PeerConnectionInterface::RTCOfferAnswerOptions options;
4316 options.offer_to_receive_audio =
4317 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004318 cricket::MediaSessionOptions session_options;
4319 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004320
4321 for (auto& o : observers) {
4322 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004323 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004324 }
4325
4326 session_.reset();
4327
tommi0f620f42015-07-09 03:25:02 -07004328 for (auto& o : observers) {
4329 // We expect to have received a notification now even if the session was
4330 // terminated. The offer creation may or may not have succeeded, but we
4331 // must have received a notification which, so the only invalid state
4332 // is kInit.
4333 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4334 }
4335}
4336
stefanc1aeaf02015-10-15 07:26:07 -07004337TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4338 TestPacketOptions();
4339}
4340
deadbeef057ecf02016-01-20 14:30:43 -08004341// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4342// is destroyed.
4343TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4344 Init();
4345 session_.reset();
4346 EXPECT_TRUE(session_destroyed_);
4347}
4348
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004349// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4350// currently fails because upon disconnection and reconnection OnIceComplete is
4351// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004352
deadbeefcbecd352015-09-23 11:50:27 -07004353INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4354 WebRtcSessionTest,
4355 testing::Values(ALREADY_GENERATED,
4356 DTLS_IDENTITY_STORE));