blob: 1fe3a815925312c1ecb142bd4ae48a49c090691b [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kwiberg0eb15ed2015-12-17 03:04:15 -080011#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070012#include <vector>
13
Henrik Kjellander15583c12016-02-10 10:53:12 +010014#include "webrtc/api/audiotrack.h"
15#include "webrtc/api/fakemediacontroller.h"
16#include "webrtc/api/fakemetricsobserver.h"
17#include "webrtc/api/jsepicecandidate.h"
18#include "webrtc/api/jsepsessiondescription.h"
19#include "webrtc/api/peerconnection.h"
20#include "webrtc/api/sctputils.h"
21#include "webrtc/api/streamcollection.h"
22#include "webrtc/api/streamcollection.h"
23#include "webrtc/api/test/fakeconstraints.h"
24#include "webrtc/api/test/fakedtlsidentitystore.h"
25#include "webrtc/api/videotrack.h"
26#include "webrtc/api/webrtcsession.h"
27#include "webrtc/api/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000028#include "webrtc/base/fakenetwork.h"
29#include "webrtc/base/firewallsocketserver.h"
30#include "webrtc/base/gunit.h"
31#include "webrtc/base/logging.h"
32#include "webrtc/base/network.h"
33#include "webrtc/base/physicalsocketserver.h"
34#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020035#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000036#include "webrtc/base/sslstreamadapter.h"
37#include "webrtc/base/stringutils.h"
38#include "webrtc/base/thread.h"
39#include "webrtc/base/virtualsocketserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080040#include "webrtc/media/base/fakemediaengine.h"
41#include "webrtc/media/base/fakevideorenderer.h"
42#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010043#include "webrtc/media/engine/fakewebrtccall.h"
kjellandera96e2d72016-02-04 23:52:28 -080044#include "webrtc/p2p/base/stunserver.h"
45#include "webrtc/p2p/base/teststunserver.h"
46#include "webrtc/p2p/base/testturnserver.h"
47#include "webrtc/p2p/base/transportchannel.h"
48#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010049#include "webrtc/pc/channelmanager.h"
50#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051
52#define MAYBE_SKIP_TEST(feature) \
53 if (!(feature())) { \
54 LOG(LS_INFO) << "Feature disabled... skipping"; \
55 return; \
56 }
57
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000060using rtc::SocketAddress;
61using rtc::scoped_ptr;
62using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000064using webrtc::CreateSessionDescriptionObserver;
65using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070066using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020067using webrtc::DtlsIdentityStoreInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070069using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070071using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072using webrtc::JsepIceCandidate;
73using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000074using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using webrtc::PeerConnectionInterface;
76using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070077using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000079using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000080using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000081using webrtc::kCreateChannelFailed;
82using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000084using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000085using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000086using webrtc::kSdpWithoutDtlsFingerprint;
87using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000089using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000090using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000092typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
93
wu@webrtc.org364f2042013-11-20 21:49:41 +000094static const int kClientAddrPort = 0;
95static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000096static const char kClientIPv6AddrHost1[] =
97 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000098static const char kClientAddrHost2[] = "22.22.22.22";
99static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000100static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
101static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000102static const char kTurnUsername[] = "test";
103static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104
105static const char kSessionVersion[] = "1";
106
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107// Media index of candidates belonging to the first media content.
108static const int kMediaContentIndex0 = 0;
109static const char kMediaContentName0[] = "audio";
110
111// Media index of candidates belonging to the second media content.
112static const int kMediaContentIndex1 = 1;
113static const char kMediaContentName1[] = "video";
114
115static const int kIceCandidatesTimeout = 10000;
116
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000117static const char kFakeDtlsFingerprint[] =
118 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
119 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
120
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000121static const char kTooLongIceUfragPwd[] =
122 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
123 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
124 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
125 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
126
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000127static const char kSdpWithRtx[] =
128 "v=0\r\n"
129 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
130 "s=-\r\n"
131 "t=0 0\r\n"
132 "a=msid-semantic: WMS stream1\r\n"
133 "m=video 9 RTP/SAVPF 0 96\r\n"
134 "c=IN IP4 0.0.0.0\r\n"
135 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
136 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
137 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
138 "a=mid:video\r\n"
139 "a=sendrecv\r\n"
140 "a=rtcp-mux\r\n"
141 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
142 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
143 "a=rtpmap:0 fake_video_codec/90000\r\n"
144 "a=rtpmap:96 rtx/90000\r\n"
145 "a=fmtp:96 apt=0\r\n";
146
deadbeefab9b2d12015-10-14 11:33:11 -0700147static const char kStream1[] = "stream1";
148static const char kVideoTrack1[] = "video1";
149static const char kAudioTrack1[] = "audio1";
150
151static const char kStream2[] = "stream2";
152static const char kVideoTrack2[] = "video2";
153static const char kAudioTrack2[] = "audio2";
154
Henrik Boström87713d02015-08-25 09:53:21 +0200155enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
156
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157class MockIceObserver : public webrtc::IceObserver {
158 public:
159 MockIceObserver()
160 : oncandidatesready_(false),
161 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
162 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
163 }
164
perkjdfb769d2016-02-09 03:09:43 -0800165 void OnIceConnectionChange(
166 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 ice_connection_state_ = new_state;
168 }
perkjdfb769d2016-02-09 03:09:43 -0800169 void OnIceGatheringChange(
170 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 // We can never transition back to "new".
172 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
173 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800174 oncandidatesready_ =
175 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176 }
177
178 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800179 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000180 switch (candidate->sdp_mline_index()) {
181 case kMediaContentIndex0:
182 mline_0_candidates_.push_back(candidate->candidate());
183 break;
184 case kMediaContentIndex1:
185 mline_1_candidates_.push_back(candidate->candidate());
186 break;
187 default:
188 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000190
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 // The ICE gathering state should always be Gathering when a candidate is
192 // received (or possibly Completed in the case of the final candidate).
193 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
194 }
195
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 bool oncandidatesready_;
197 std::vector<cricket::Candidate> mline_0_candidates_;
198 std::vector<cricket::Candidate> mline_1_candidates_;
199 PeerConnectionInterface::IceConnectionState ice_connection_state_;
200 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
201};
202
203class WebRtcSessionForTest : public webrtc::WebRtcSession {
204 public:
stefanc1aeaf02015-10-15 07:26:07 -0700205 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000206 rtc::Thread* signaling_thread,
207 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700209 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700210 : WebRtcSession(media_controller,
211 signaling_thread,
212 worker_thread,
213 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 RegisterIceObserver(ice_observer);
215 }
216 virtual ~WebRtcSessionForTest() {}
217
deadbeefcbecd352015-09-23 11:50:27 -0700218 // Note that these methods are only safe to use if the signaling thread
219 // is the same as the worker thread
220 cricket::TransportChannel* voice_rtp_transport_channel() {
221 return rtp_transport_channel(voice_channel());
222 }
223
224 cricket::TransportChannel* voice_rtcp_transport_channel() {
225 return rtcp_transport_channel(voice_channel());
226 }
227
228 cricket::TransportChannel* video_rtp_transport_channel() {
229 return rtp_transport_channel(video_channel());
230 }
231
232 cricket::TransportChannel* video_rtcp_transport_channel() {
233 return rtcp_transport_channel(video_channel());
234 }
235
236 cricket::TransportChannel* data_rtp_transport_channel() {
237 return rtp_transport_channel(data_channel());
238 }
239
240 cricket::TransportChannel* data_rtcp_transport_channel() {
241 return rtcp_transport_channel(data_channel());
242 }
243
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 using webrtc::WebRtcSession::SetAudioPlayout;
245 using webrtc::WebRtcSession::SetAudioSend;
246 using webrtc::WebRtcSession::SetCaptureDevice;
247 using webrtc::WebRtcSession::SetVideoPlayout;
248 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700249
250 private:
251 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
252 if (!ch) {
253 return nullptr;
254 }
255 return ch->transport_channel();
256 }
257
258 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
259 if (!ch) {
260 return nullptr;
261 }
262 return ch->rtcp_transport_channel();
263 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264};
265
wu@webrtc.org91053e72013-08-10 07:18:04 +0000266class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000267 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000269 enum State {
270 kInit,
271 kFailed,
272 kSucceeded,
273 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000274 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000275
276 // CreateSessionDescriptionObserver implementation.
277 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000278 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000279 state_ = kSucceeded;
280 }
281 virtual void OnFailure(const std::string& error) {
282 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283 }
284
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000285 SessionDescriptionInterface* description() { return description_.get(); }
286
287 SessionDescriptionInterface* ReleaseDescription() {
288 return description_.release();
289 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290
wu@webrtc.org91053e72013-08-10 07:18:04 +0000291 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292
wu@webrtc.org91053e72013-08-10 07:18:04 +0000293 protected:
294 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295
296 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000297 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000298 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299};
300
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000301class FakeAudioRenderer : public cricket::AudioRenderer {
302 public:
solenberg98c68862015-10-09 03:27:14 -0700303 FakeAudioRenderer() : sink_(NULL) {}
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000304 virtual ~FakeAudioRenderer() {
305 if (sink_)
306 sink_->OnClose();
307 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000308
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000309 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000310
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000311 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000312 private:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000313 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000314};
315
Henrik Boström87713d02015-08-25 09:53:21 +0200316class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700317 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
318 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 protected:
320 // TODO Investigate why ChannelManager crashes, if it's created
321 // after stun_server.
322 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700323 : media_engine_(new cricket::FakeMediaEngine()),
324 data_engine_(new cricket::FakeDataEngine()),
325 channel_manager_(
326 new cricket::ChannelManager(media_engine_,
327 data_engine_,
328 new cricket::CaptureManager(),
329 rtc::Thread::Current())),
330 fake_call_(webrtc::Call::Config()),
331 media_controller_(
332 webrtc::MediaControllerInterface::Create(rtc::Thread::Current(),
333 channel_manager_.get())),
334 tdesc_factory_(new cricket::TransportDescriptionFactory()),
335 desc_factory_(
336 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
337 tdesc_factory_.get())),
338 pss_(new rtc::PhysicalSocketServer),
339 vss_(new rtc::VirtualSocketServer(pss_.get())),
340 fss_(new rtc::FirewallSocketServer(vss_.get())),
341 ss_scope_(fss_.get()),
342 stun_socket_addr_(
343 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
344 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
345 stun_socket_addr_)),
346 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
347 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000348 cricket::ServerAddresses stun_servers;
349 stun_servers.insert(stun_socket_addr_);
350 allocator_.reset(new cricket::BasicPortAllocator(
351 &network_manager_,
352 stun_servers,
353 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000354 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700355 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 EXPECT_TRUE(channel_manager_->Init());
357 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000358 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 }
360
361 void AddInterface(const SocketAddress& addr) {
362 network_manager_.AddInterface(addr);
363 }
364
Henrik Boström87713d02015-08-25 09:53:21 +0200365 // If |dtls_identity_store| != null or |rtc_configuration| contains
366 // |certificates| then DTLS will be enabled unless explicitly disabled by
367 // |rtc_configuration| options. When DTLS is enabled a certificate will be
368 // used if provided, otherwise one will be generated using the
369 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000370 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200371 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200372 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373 ASSERT_TRUE(session_.get() == NULL);
374 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700375 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700376 allocator_.get(), &observer_));
377 session_->SignalDataChannelOpenMessage.connect(
378 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800379 session_->GetOnDestroyedSignal()->connect(
380 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381
382 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
383 observer_.ice_connection_state_);
384 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
385 observer_.ice_gathering_state_);
386
deadbeefcbecd352015-09-23 11:50:27 -0700387 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
kwiberg0eb15ed2015-12-17 03:04:15 -0800388 std::move(dtls_identity_store),
deadbeefcbecd352015-09-23 11:50:27 -0700389 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700390 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000391 }
392
deadbeefab9b2d12015-10-14 11:33:11 -0700393 void OnDataChannelOpenMessage(const std::string& label,
394 const InternalDataChannelInit& config) {
395 last_data_channel_label_ = label;
396 last_data_channel_config_ = config;
397 }
398
deadbeef057ecf02016-01-20 14:30:43 -0800399 void OnSessionDestroyed() { session_destroyed_ = true; }
400
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000401 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200402 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200403 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000404 }
405
406 void InitWithIceTransport(
407 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200408 PeerConnectionInterface::RTCConfiguration configuration;
409 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200410 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000411 }
412
413 void InitWithBundlePolicy(
414 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200415 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200416 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200417 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700418 }
419
420 void InitWithRtcpMuxPolicy(
421 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
422 PeerConnectionInterface::RTCConfiguration configuration;
423 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200424 Init(nullptr, configuration);
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;
431 PeerConnectionInterface::RTCConfiguration configuration;
432 if (cert_gen_method == ALREADY_GENERATED) {
433 configuration.certificates.push_back(
434 FakeDtlsIdentityStore::GenerateCertificate());
435 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
436 dtls_identity_store.reset(new FakeDtlsIdentityStore());
437 dtls_identity_store->set_should_fail(false);
438 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700439 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200440 }
kwiberg0eb15ed2015-12-17 03:04:15 -0800441 Init(std::move(dtls_identity_store), configuration);
Henrik Boström87713d02015-08-25 09:53:21 +0200442 }
443
444 // Init with DTLS with a store that will fail to generate a certificate.
445 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200446 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
447 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200448 dtls_identity_store->set_should_fail(true);
Henrik Lundin64dad832015-05-11 12:44:23 +0200449 PeerConnectionInterface::RTCConfiguration configuration;
kwiberg0eb15ed2015-12-17 03:04:15 -0800450 Init(std::move(dtls_identity_store), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000451 }
452
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453 void InitWithDtmfCodec() {
454 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000455 const cricket::AudioCodec kTelephoneEventCodec(
456 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457 std::vector<cricket::AudioCodec> codecs;
458 codecs.push_back(kTelephoneEventCodec);
459 media_engine_->SetAudioCodecs(codecs);
460 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000461 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 }
463
deadbeefab9b2d12015-10-14 11:33:11 -0700464 void SendAudioVideoStream1() {
465 send_stream_1_ = true;
466 send_stream_2_ = false;
467 send_audio_ = true;
468 send_video_ = true;
469 }
470
471 void SendAudioVideoStream2() {
472 send_stream_1_ = false;
473 send_stream_2_ = true;
474 send_audio_ = true;
475 send_video_ = true;
476 }
477
478 void SendAudioVideoStream1And2() {
479 send_stream_1_ = true;
480 send_stream_2_ = true;
481 send_audio_ = true;
482 send_video_ = true;
483 }
484
485 void SendNothing() {
486 send_stream_1_ = false;
487 send_stream_2_ = false;
488 send_audio_ = false;
489 send_video_ = false;
490 }
491
492 void SendAudioOnlyStream2() {
493 send_stream_1_ = false;
494 send_stream_2_ = true;
495 send_audio_ = true;
496 send_video_ = false;
497 }
498
499 void SendVideoOnlyStream2() {
500 send_stream_1_ = false;
501 send_stream_2_ = true;
502 send_audio_ = false;
503 send_video_ = true;
504 }
505
506 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
507 if (send_stream_1_ && send_audio_) {
508 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
509 kStream1);
510 }
511 if (send_stream_1_ && send_video_) {
512 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
513 kStream1);
514 }
515 if (send_stream_2_ && send_audio_) {
516 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
517 kStream2);
518 }
519 if (send_stream_2_ && send_video_) {
520 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
521 kStream2);
522 }
523 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
524 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
525 data_channel_->label(),
526 data_channel_->label());
527 }
528 }
529
530 void GetOptionsForOffer(
531 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
532 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700533 ASSERT_TRUE(ConvertRtcOptionsForOffer(rtc_options, session_options));
534
deadbeefc80741f2015-10-22 13:14:45 -0700535 AddStreamsToOptions(session_options);
536 if (rtc_options.offer_to_receive_audio ==
537 RTCOfferAnswerOptions::kUndefined) {
538 session_options->recv_audio =
539 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
540 }
541 if (rtc_options.offer_to_receive_video ==
542 RTCOfferAnswerOptions::kUndefined) {
543 session_options->recv_video =
544 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
545 }
546 session_options->bundle_enabled =
547 session_options->bundle_enabled &&
548 (session_options->has_audio() || session_options->has_video() ||
549 session_options->has_data());
550
deadbeefab9b2d12015-10-14 11:33:11 -0700551 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
552 session_options->data_channel_type = cricket::DCT_SCTP;
553 }
554 }
555
556 void GetOptionsForAnswer(const webrtc::MediaConstraintsInterface* constraints,
557 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700558 session_options->recv_audio = false;
559 session_options->recv_video = false;
560 ASSERT_TRUE(ParseConstraintsForAnswer(constraints, session_options));
561
deadbeefc80741f2015-10-22 13:14:45 -0700562 AddStreamsToOptions(session_options);
563 session_options->bundle_enabled =
564 session_options->bundle_enabled &&
565 (session_options->has_audio() || session_options->has_video() ||
566 session_options->has_data());
567
deadbeefab9b2d12015-10-14 11:33:11 -0700568 if (session_->data_channel_type() == cricket::DCT_SCTP) {
569 session_options->data_channel_type = cricket::DCT_SCTP;
570 }
571 }
572
573 // Creates a local offer and applies it. Starts ICE.
574 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 // to decide which streams to create.
576 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000577 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 SetLocalDescriptionWithoutError(offer);
579 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
580 observer_.ice_gathering_state_,
581 kIceCandidatesTimeout);
582 }
583
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000584 SessionDescriptionInterface* CreateOffer() {
585 PeerConnectionInterface::RTCOfferAnswerOptions options;
586 options.offer_to_receive_audio =
587 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
588
589 return CreateOffer(options);
590 }
591
wu@webrtc.org91053e72013-08-10 07:18:04 +0000592 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000593 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000594 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000595 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700596 cricket::MediaSessionOptions session_options;
597 GetOptionsForOffer(options, &session_options);
598 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000599 EXPECT_TRUE_WAIT(
600 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000601 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000602 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000603 }
604
605 SessionDescriptionInterface* CreateAnswer(
606 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000607 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000608 = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700609 cricket::MediaSessionOptions session_options;
610 GetOptionsForAnswer(constraints, &session_options);
611 session_->CreateAnswer(observer, constraints, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000612 EXPECT_TRUE_WAIT(
613 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000614 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000615 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000616 }
617
wu@webrtc.org364f2042013-11-20 21:49:41 +0000618 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000619 return (session_->voice_channel() != NULL &&
620 session_->video_channel() != NULL);
621 }
622
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000623 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
624 ASSERT_TRUE(session_.get() != NULL);
625 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
626 ASSERT_TRUE(content != NULL);
627 const cricket::AudioContentDescription* audio_content =
628 static_cast<const cricket::AudioContentDescription*>(
629 content->description);
630 ASSERT_TRUE(audio_content != NULL);
631 ASSERT_EQ(1U, audio_content->cryptos().size());
632 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
633 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
634 audio_content->cryptos()[0].cipher_suite);
635 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
636 audio_content->protocol());
637
638 content = cricket::GetFirstVideoContent(sdp);
639 ASSERT_TRUE(content != NULL);
640 const cricket::VideoContentDescription* video_content =
641 static_cast<const cricket::VideoContentDescription*>(
642 content->description);
643 ASSERT_TRUE(video_content != NULL);
644 ASSERT_EQ(1U, video_content->cryptos().size());
645 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
646 video_content->cryptos()[0].cipher_suite);
647 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
648 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
649 video_content->protocol());
650 }
651
652 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
653 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
654 ASSERT_TRUE(content != NULL);
655 const cricket::AudioContentDescription* audio_content =
656 static_cast<const cricket::AudioContentDescription*>(
657 content->description);
658 ASSERT_TRUE(audio_content != NULL);
659 ASSERT_EQ(0U, audio_content->cryptos().size());
660
661 content = cricket::GetFirstVideoContent(sdp);
662 ASSERT_TRUE(content != NULL);
663 const cricket::VideoContentDescription* video_content =
664 static_cast<const cricket::VideoContentDescription*>(
665 content->description);
666 ASSERT_TRUE(video_content != NULL);
667 ASSERT_EQ(0U, video_content->cryptos().size());
668
669 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700670 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000671 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700672 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673 video_content->protocol());
674 } else {
675 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
676 audio_content->protocol());
677 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
678 video_content->protocol());
679 }
680 }
681
682 // Set the internal fake description factories to do DTLS-SRTP.
683 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000684 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000686 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200687 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800688 tdesc_factory_->set_certificate(
689 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
690 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
692 }
693
694 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
695 bool expected) {
696 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
697 ASSERT_TRUE(audio != NULL);
698 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000699 const TransportInfo* video = sdp->GetTransportInfoByName("video");
700 ASSERT_TRUE(video != NULL);
701 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702 }
703
704 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000705 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000707 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000708 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000710 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000712 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
713 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000714 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715 // Answer should be NULL as no crypto params in offer.
716 ASSERT_TRUE(answer == NULL);
717 }
718
719 void VerifyAnswerFromCryptoOffer() {
720 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000721 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 options.bundle_enabled = true;
723 scoped_ptr<JsepSessionDescription> offer(
724 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
725 ASSERT_TRUE(offer.get() != NULL);
726 VerifyCryptoParams(offer->description());
727 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000728 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 ASSERT_TRUE(answer.get() != NULL);
730 VerifyCryptoParams(answer->description());
731 }
732
733 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
734 const cricket::SessionDescription* desc2,
735 bool expect_equal) {
736 if (desc1->contents().size() != desc2->contents().size()) {
737 EXPECT_FALSE(expect_equal);
738 return;
739 }
740
741 const cricket::ContentInfos& contents = desc1->contents();
742 cricket::ContentInfos::const_iterator it = contents.begin();
743
744 for (; it != contents.end(); ++it) {
745 const cricket::TransportDescription* transport_desc1 =
746 desc1->GetTransportDescriptionByName(it->name);
747 const cricket::TransportDescription* transport_desc2 =
748 desc2->GetTransportDescriptionByName(it->name);
749 if (!transport_desc1 || !transport_desc2) {
750 EXPECT_FALSE(expect_equal);
751 return;
752 }
753 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
754 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
755 EXPECT_FALSE(expect_equal);
756 return;
757 }
758 }
759 EXPECT_TRUE(expect_equal);
760 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000761
762 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
763 std::string *sdp) {
764 const cricket::SessionDescription* desc = current_desc->description();
765 EXPECT_TRUE(current_desc->ToString(sdp));
766
767 const cricket::ContentInfos& contents = desc->contents();
768 cricket::ContentInfos::const_iterator it = contents.begin();
769 // Replace ufrag and pwd lines with empty strings.
770 for (; it != contents.end(); ++it) {
771 const cricket::TransportDescription* transport_desc =
772 desc->GetTransportDescriptionByName(it->name);
773 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
774 + "\r\n";
775 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
776 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000777 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000778 "", 0,
779 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000780 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000781 "", 0,
782 sdp);
783 }
784 }
785
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000786 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
787 const std::string& modified_ice_ufrag,
788 const std::string& modified_ice_pwd,
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 |modified_ice_ufrag| and
796 // |modified_ice_pwd| strings.
797 for (; it != contents.end(); ++it) {
798 const cricket::TransportDescription* transport_desc =
799 desc->GetTransportDescriptionByName(it->name);
800 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
801 + "\r\n";
802 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
803 + "\r\n";
804 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
805 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000806 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000807 mod_ufrag.c_str(), mod_ufrag.length(),
808 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000809 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000810 mod_pwd.c_str(), mod_pwd.length(),
811 sdp);
812 }
813 }
814
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 // Creates a remote offer and and applies it as a remote description,
816 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700817 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 // to decide which local and remote streams to create.
819 void CreateAndSetRemoteOfferAndLocalAnswer() {
820 SessionDescriptionInterface* offer = CreateRemoteOffer();
821 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000822 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 SetLocalDescriptionWithoutError(answer);
824 }
825 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
826 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700827 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 }
829 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700830 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 SetLocalDescriptionWithoutError(desc);
832 EXPECT_EQ(expected_state, session_->state());
833 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000834 void SetLocalDescriptionExpectError(const std::string& action,
835 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836 SessionDescriptionInterface* desc) {
837 std::string error;
838 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000839 std::string sdp_type = "local ";
840 sdp_type.append(action);
841 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 EXPECT_NE(std::string::npos, error.find(expected_error));
843 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000844 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
845 SessionDescriptionInterface* desc) {
846 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
847 expected_error, desc);
848 }
849 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
850 SessionDescriptionInterface* desc) {
851 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
852 expected_error, desc);
853 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
855 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
856 }
857 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700858 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 SetRemoteDescriptionWithoutError(desc);
860 EXPECT_EQ(expected_state, session_->state());
861 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000862 void SetRemoteDescriptionExpectError(const std::string& action,
863 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 SessionDescriptionInterface* desc) {
865 std::string error;
866 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000867 std::string sdp_type = "remote ";
868 sdp_type.append(action);
869 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 EXPECT_NE(std::string::npos, error.find(expected_error));
871 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000872 void SetRemoteDescriptionOfferExpectError(
873 const std::string& expected_error, SessionDescriptionInterface* desc) {
874 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
875 expected_error, desc);
876 }
877 void SetRemoteDescriptionPranswerExpectError(
878 const std::string& expected_error, SessionDescriptionInterface* desc) {
879 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
880 expected_error, desc);
881 }
882 void SetRemoteDescriptionAnswerExpectError(
883 const std::string& expected_error, SessionDescriptionInterface* desc) {
884 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
885 expected_error, desc);
886 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887
888 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
889 SessionDescriptionInterface** nocrypto_answer) {
890 // Create a SDP without Crypto.
891 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000892 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893 options.bundle_enabled = true;
894 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
895 ASSERT_TRUE(*offer != NULL);
896 VerifyCryptoParams((*offer)->description());
897
898 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
899 cricket::SEC_DISABLED);
900 EXPECT_TRUE(*nocrypto_answer != NULL);
901 }
902
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000903 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
904 SessionDescriptionInterface** nodtls_answer) {
905 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000906 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000907 options.bundle_enabled = true;
908
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000909 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000910 CreateRemoteOffer(options, cricket::SEC_ENABLED));
911
912 *nodtls_answer =
913 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
914 EXPECT_TRUE(*nodtls_answer != NULL);
915 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
916 VerifyCryptoParams((*nodtls_answer)->description());
917
918 SetFactoryDtlsSrtp();
919 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
920 ASSERT_TRUE(*offer != NULL);
921 VerifyFingerprintStatus((*offer)->description(), true);
922 VerifyCryptoParams((*offer)->description());
923 }
924
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 JsepSessionDescription* CreateRemoteOfferWithVersion(
926 cricket::MediaSessionOptions options,
927 cricket::SecurePolicy secure_policy,
928 const std::string& session_version,
929 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000930 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 const cricket::SessionDescription* cricket_desc = NULL;
932 if (current_desc) {
933 cricket_desc = current_desc->description();
934 session_id = current_desc->session_id();
935 }
936
937 desc_factory_->set_secure(secure_policy);
938 JsepSessionDescription* offer(
939 new JsepSessionDescription(JsepSessionDescription::kOffer));
940 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
941 session_id, session_version)) {
942 delete offer;
943 offer = NULL;
944 }
945 return offer;
946 }
947 JsepSessionDescription* CreateRemoteOffer(
948 cricket::MediaSessionOptions options) {
949 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
950 kSessionVersion, NULL);
951 }
952 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000953 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
954 return CreateRemoteOfferWithVersion(
955 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 }
957 JsepSessionDescription* CreateRemoteOffer(
958 cricket::MediaSessionOptions options,
959 const SessionDescriptionInterface* current_desc) {
960 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
961 kSessionVersion, current_desc);
962 }
963
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000964 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
965 const char* sctp_stream_name, int new_port,
966 cricket::MediaSessionOptions options) {
967 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000968 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
969 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000970 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
971 }
972
973 // Takes ownership of offer_basis (and deletes it).
974 JsepSessionDescription* ChangeSDPSctpPort(
975 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
976 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
977 // SessionDescription from the mutated string.
978 const char* default_port_str = "5000";
979 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000980 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000981 std::string offer_str;
982 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000983 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000984 new_port_str, strlen(new_port_str),
985 &offer_str);
986 JsepSessionDescription* offer = new JsepSessionDescription(
987 offer_basis->type());
988 delete offer_basis;
989 offer->Initialize(offer_str, NULL);
990 return offer;
991 }
992
deadbeefab9b2d12015-10-14 11:33:11 -0700993 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994 // before this function to decide which streams to create.
995 JsepSessionDescription* CreateRemoteOffer() {
996 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -0700997 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998 return CreateRemoteOffer(options, session_->remote_description());
999 }
1000
1001 JsepSessionDescription* CreateRemoteAnswer(
1002 const SessionDescriptionInterface* offer,
1003 cricket::MediaSessionOptions options,
1004 cricket::SecurePolicy policy) {
1005 desc_factory_->set_secure(policy);
1006 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001007 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 JsepSessionDescription* answer(
1009 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1010 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1011 options, NULL),
1012 session_id, kSessionVersion)) {
1013 delete answer;
1014 answer = NULL;
1015 }
1016 return answer;
1017 }
1018
1019 JsepSessionDescription* CreateRemoteAnswer(
1020 const SessionDescriptionInterface* offer,
1021 cricket::MediaSessionOptions options) {
1022 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1023 }
1024
deadbeefab9b2d12015-10-14 11:33:11 -07001025 // Creates an answer session description.
1026 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001027 // to decide which streams to create.
1028 JsepSessionDescription* CreateRemoteAnswer(
1029 const SessionDescriptionInterface* offer) {
1030 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001031 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1033 }
1034
1035 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001036 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001037 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001038 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001039
1040 PeerConnectionInterface::RTCOfferAnswerOptions options;
1041 options.use_rtp_mux = bundle;
1042
1043 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1045 // and answer.
1046 SetLocalDescriptionWithoutError(offer);
1047
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001048 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001049 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001050 std::string sdp;
1051 EXPECT_TRUE(answer->ToString(&sdp));
1052
1053 size_t expected_candidate_num = 2;
1054 if (!rtcp_mux) {
1055 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1056 // for rtp and rtcp.
1057 expected_candidate_num = 4;
1058 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 const std::string kRtcpMux = "a=rtcp-mux";
1060 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001061 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001062 kXRtcpMux.c_str(), kXRtcpMux.length(),
1063 &sdp);
1064 }
1065
1066 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1067 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068
1069 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001070 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001071 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1072 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001073 if (bundle) {
1074 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1075 } else {
1076 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001077 }
1078 }
1079 // Tests that we can only send DTMF when the dtmf codec is supported.
1080 void TestCanInsertDtmf(bool can) {
1081 if (can) {
1082 InitWithDtmfCodec();
1083 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001084 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085 }
deadbeefab9b2d12015-10-14 11:33:11 -07001086 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087 CreateAndSetRemoteOfferAndLocalAnswer();
1088 EXPECT_FALSE(session_->CanInsertDtmf(""));
1089 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1090 }
1091
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001092 // Helper class to configure loopback network and verify Best
1093 // Connection using right IP protocol for TestLoopbackCall
1094 // method. LoopbackNetworkManager applies firewall rules to block
1095 // all ping traffic once ICE completed, and remove them to observe
1096 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1097 // verifies the best connection is using the right IP protocol after
1098 // initial ICE convergences.
1099
1100 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001101 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001102 LoopbackNetworkConfiguration()
1103 : test_ipv6_network_(false),
1104 test_extra_ipv4_network_(false),
1105 best_connection_after_initial_ice_converged_(1, 0) {}
1106
1107 // Used to track the expected best connection count in each IP protocol.
1108 struct ExpectedBestConnection {
1109 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1110 : ipv4_count_(ipv4_count),
1111 ipv6_count_(ipv6_count) {}
1112
1113 int ipv4_count_;
1114 int ipv6_count_;
1115 };
1116
1117 bool test_ipv6_network_;
1118 bool test_extra_ipv4_network_;
1119 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1120
1121 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001122 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001123 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1124 }
1125
1126 private:
jbauchac8869e2015-07-03 01:36:14 -07001127 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001128 const ExpectedBestConnection& expected) const {
1129 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001130 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1131 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001132 expected.ipv4_count_);
1133 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001134 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1135 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001136 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001137 // This is used in the loopback call so there is only single host to host
1138 // candidate pair.
1139 EXPECT_EQ(metrics_observer->GetEnumCounter(
1140 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1141 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001142 0);
1143 EXPECT_EQ(metrics_observer->GetEnumCounter(
1144 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1145 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001146 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001147 }
1148 };
1149
1150 class LoopbackNetworkManager {
1151 public:
1152 LoopbackNetworkManager(WebRtcSessionTest* session,
1153 const LoopbackNetworkConfiguration& config)
1154 : config_(config) {
1155 session->AddInterface(
1156 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1157 if (config_.test_extra_ipv4_network_) {
1158 session->AddInterface(
1159 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1160 }
1161 if (config_.test_ipv6_network_) {
1162 session->AddInterface(
1163 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1164 }
1165 }
1166
1167 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1168 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1169 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1170 if (config_.test_extra_ipv4_network_) {
1171 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1172 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1173 }
1174 if (config_.test_ipv6_network_) {
1175 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1176 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1177 }
1178 }
1179
1180 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1181
1182 private:
1183 LoopbackNetworkConfiguration config_;
1184 };
1185
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001186 // The method sets up a call from the session to itself, in a loopback
1187 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001188 // disconnection, and then a permanent disconnection.
1189 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001190 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1191 // While running the call, this method also checks if the session goes through
1192 // the correct sequence of ICE states when a connection is established,
1193 // broken, and re-established.
1194 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001195 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1196 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001197 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001198
stefanc1aeaf02015-10-15 07:26:07 -07001199 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001200 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001201 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001202 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001203
1204 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1205 observer_.ice_gathering_state_);
1206 SetLocalDescriptionWithoutError(offer);
1207 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1208 observer_.ice_connection_state_);
1209 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001210 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001211 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1212 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001213 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001214
1215 std::string sdp;
1216 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001217 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1218 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001219 ASSERT_TRUE(desc != NULL);
1220 SetRemoteDescriptionWithoutError(desc);
1221
1222 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001223 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001224
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001225 // The ice connection state is "Connected" too briefly to catch in a test.
1226 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001227 observer_.ice_connection_state_, kIceCandidatesTimeout);
1228 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001229
stefanc1aeaf02015-10-15 07:26:07 -07001230 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1231 LoopbackNetworkManager loopback_network_manager(this, config);
1232 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001233 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001234 // Adding firewall rule to block ping requests, which should cause
1235 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001236
1237 loopback_network_manager.ApplyFirewallRules(fss_.get());
1238
1239 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001240 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1241 observer_.ice_connection_state_,
1242 kIceCandidatesTimeout);
1243
jbauchac8869e2015-07-03 01:36:14 -07001244 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001245
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001246 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001247 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001249 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001250 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251 observer_.ice_connection_state_,
1252 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001253
1254 // Now we block ping requests and wait until the ICE connection transitions
1255 // to the Failed state. This will take at least 30 seconds because it must
1256 // wait for the Port to timeout.
1257 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001258
1259 loopback_network_manager.ApplyFirewallRules(fss_.get());
1260 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001261 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001262 observer_.ice_connection_state_,
1263 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264 }
1265
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001266 void TestLoopbackCall() {
1267 LoopbackNetworkConfiguration config;
1268 TestLoopbackCall(config);
1269 }
1270
stefanc1aeaf02015-10-15 07:26:07 -07001271 void TestPacketOptions() {
1272 media_controller_.reset(
1273 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1274 LoopbackNetworkConfiguration config;
1275 LoopbackNetworkManager loopback_network_manager(this, config);
1276
1277 SetupLoopbackCall();
1278
1279 uint8_t test_packet[15] = {0};
1280 rtc::PacketOptions options;
1281 options.packet_id = 10;
1282 media_engine_->GetVideoChannel(0)
1283 ->SendRtp(test_packet, sizeof(test_packet), options);
1284
1285 const int kPacketTimeout = 2000;
1286 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1287 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1288 }
1289
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1291 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001292 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1293 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1294
1295 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1297 codecs.push_back(kCNCodec1);
1298 codecs.push_back(kCNCodec2);
1299 media_engine_->SetAudioCodecs(codecs);
1300 desc_factory_->set_audio_codecs(codecs);
1301 }
1302
1303 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1304 const cricket::ContentDescription* description = content->description;
1305 ASSERT(description != NULL);
1306 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001307 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 ASSERT(audio_content_desc != NULL);
1309 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1310 if (audio_content_desc->codecs()[i].name == "CN")
1311 return false;
1312 }
1313 return true;
1314 }
1315
deadbeefab9b2d12015-10-14 11:33:11 -07001316 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001317 webrtc::InternalDataChannelInit dci;
deadbeefab9b2d12015-10-14 11:33:11 -07001318 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1319 data_channel_ = DataChannel::Create(
1320 session_.get(), session_->data_channel_type(), "datachannel", dci);
1321 }
1322
1323 void SetLocalDescriptionWithDataChannel() {
1324 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001325 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326 SetLocalDescriptionWithoutError(offer);
1327 }
1328
wu@webrtc.org91053e72013-08-10 07:18:04 +00001329 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001330 RTCCertificateGenerationMethod cert_gen_method,
1331 CreateSessionDescriptionRequest::Type type) {
1332 InitWithDtls(cert_gen_method);
1333 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1334 }
1335
1336 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1337 CreateSessionDescriptionRequest::Type type) {
1338 InitWithDtlsIdentityGenFail();
1339 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1340 }
1341
1342 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001343 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001344 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001345 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001346 if (type == CreateSessionDescriptionRequest::kAnswer) {
1347 cricket::MediaSessionOptions options;
1348 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001349 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001350 ASSERT_TRUE(offer.get() != NULL);
1351 SetRemoteDescriptionWithoutError(offer.release());
1352 }
1353
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001354 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001355 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001356 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001357 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001358 observers[kNumber];
1359 for (int i = 0; i < kNumber; ++i) {
1360 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1361 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001362 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001363 } else {
deadbeefab9b2d12015-10-14 11:33:11 -07001364 session_->CreateAnswer(observers[i], nullptr, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001365 }
1366 }
1367
1368 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1369 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1370 WebRtcSessionCreateSDPObserverForTest::kFailed;
1371
1372 for (int i = 0; i < kNumber; ++i) {
1373 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1374 if (success) {
1375 EXPECT_TRUE(observers[i]->description() != NULL);
1376 } else {
1377 EXPECT_TRUE(observers[i]->description() == NULL);
1378 }
1379 }
1380 }
1381
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001382 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001383 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001384 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001385 turn_server.credentials = credentials;
1386 turn_server.ports.push_back(
1387 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1388 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001389 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001390 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001391 }
1392
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001393 cricket::FakeMediaEngine* media_engine_;
1394 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001395 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001396 cricket::FakeCall fake_call_;
1397 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001398 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001399 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1400 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1401 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1402 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1403 rtc::SocketServerScope ss_scope_;
1404 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001405 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001406 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001407 rtc::FakeNetworkManager network_manager_;
1408 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001409 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001410 rtc::scoped_ptr<FakeConstraints> constraints_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001411 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412 MockIceObserver observer_;
1413 cricket::FakeVideoMediaChannel* video_channel_;
1414 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001415 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001416 // The following flags affect options created for CreateOffer/CreateAnswer.
1417 bool send_stream_1_ = false;
1418 bool send_stream_2_ = false;
1419 bool send_audio_ = false;
1420 bool send_video_ = false;
1421 rtc::scoped_refptr<DataChannel> data_channel_;
1422 // Last values received from data channel creation signal.
1423 std::string last_data_channel_label_;
1424 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001425 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426};
1427
Henrik Boström87713d02015-08-25 09:53:21 +02001428TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1429 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001430 // SDES is disabled when DTLS is on.
1431 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001432}
1433
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001434TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001435 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001436 // SDES is required if DTLS is off.
1437 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001438}
1439
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001440TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1441 TestSessionCandidatesWithBundleRtcpMux(false, false);
1442}
1443
1444// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1445// with rtcp-mux and/or bundle.
1446TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1447 TestSessionCandidatesWithBundleRtcpMux(false, true);
1448}
1449
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1451 TestSessionCandidatesWithBundleRtcpMux(true, true);
1452}
1453
1454TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001455 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1456 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001457 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001458 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459 InitiateCall();
1460 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1461 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1462 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1463}
1464
minyuec8930ba2016-01-22 06:17:46 -08001465// Crashes on Win only. See webrtc:5411.
1466#if defined(WEBRTC_WIN)
1467#define MAYBE_TestStunError DISABLED_TestStunError
1468#else
1469#define MAYBE_TestStunError TestStunError
1470#endif
1471TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001472 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1473 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001474 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001475 rtc::FP_UDP,
1476 rtc::FD_ANY,
1477 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001478 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001479 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001481 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001482 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1483 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1484 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1485}
1486
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001487// Test session delivers no candidates gathered when constraint set to "none".
1488TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1489 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001490 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001491 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001492 InitiateCall();
1493 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1494 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1495 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1496}
1497
1498// Test session delivers only relay candidates gathered when constaint set to
1499// "relay".
1500TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1501 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1502 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001503 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001504 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001505 InitiateCall();
1506 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1507 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1508 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1509 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1510 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1511 observer_.mline_0_candidates_[i].type());
1512 }
1513 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1514 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1515 observer_.mline_1_candidates_[i].type());
1516 }
1517}
1518
1519// Test session delivers all candidates gathered when constaint set to "all".
1520TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1521 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001522 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001523 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001524 InitiateCall();
1525 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1526 // Host + STUN. By default allocator is disabled to gather relay candidates.
1527 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1528 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1529}
1530
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001531TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001532 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001533 SessionDescriptionInterface* offer = NULL;
1534 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1535 std::string unknown_action;
1536 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1537 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1538}
1539
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001540// Test creating offers and receive answers and make sure the
1541// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001542TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001543 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001544 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001545 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001546 const std::string session_id_orig = offer->session_id();
1547 const std::string session_version_orig = offer->session_version();
1548 SetLocalDescriptionWithoutError(offer);
1549
deadbeefab9b2d12015-10-14 11:33:11 -07001550 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551 SessionDescriptionInterface* answer =
1552 CreateRemoteAnswer(session_->local_description());
1553 SetRemoteDescriptionWithoutError(answer);
1554
1555 video_channel_ = media_engine_->GetVideoChannel(0);
1556 voice_channel_ = media_engine_->GetVoiceChannel(0);
1557
1558 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1559 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1560
1561 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1562 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1563
1564 ASSERT_EQ(1u, video_channel_->send_streams().size());
1565 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1566 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1567 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1568
1569 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001570 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001571 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572
1573 // Verify the session id is the same and the session version is
1574 // increased.
1575 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001576 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1577 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578
1579 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001580 EXPECT_EQ(0u, video_channel_->send_streams().size());
1581 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582
deadbeefab9b2d12015-10-14 11:33:11 -07001583 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 answer = CreateRemoteAnswer(session_->local_description());
1585 SetRemoteDescriptionWithoutError(answer);
1586
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 // Make sure the receive streams have not changed.
1588 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1589 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1590 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1591 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1592}
1593
1594// Test receiving offers and creating answers and make sure the
1595// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001596TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001597 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001598 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001599 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001600 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 SetRemoteDescriptionWithoutError(offer);
1602
deadbeefab9b2d12015-10-14 11:33:11 -07001603 SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001604 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001605 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 SetLocalDescriptionWithoutError(answer);
1607
1608 const std::string session_id_orig = answer->session_id();
1609 const std::string session_version_orig = answer->session_version();
1610
1611 video_channel_ = media_engine_->GetVideoChannel(0);
1612 voice_channel_ = media_engine_->GetVoiceChannel(0);
1613
1614 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1615 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1616
1617 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1618 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1619
1620 ASSERT_EQ(1u, video_channel_->send_streams().size());
1621 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1622 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1623 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1624
deadbeefab9b2d12015-10-14 11:33:11 -07001625 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001626 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 SetRemoteDescriptionWithoutError(offer);
1628
1629 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001630 SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001631 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632
1633 // Verify the session id is the same and the session version is
1634 // increased.
1635 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001636 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1637 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638 SetLocalDescriptionWithoutError(answer);
1639
1640 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1641 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1642 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1643 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1644 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1645 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1646
1647 // Make sure we have no send streams.
1648 EXPECT_EQ(0u, video_channel_->send_streams().size());
1649 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1650}
1651
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001652TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001653 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001654 media_engine_->set_fail_create_channel(true);
1655
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001656 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001657 ASSERT_TRUE(offer != NULL);
1658 // SetRemoteDescription and SetLocalDescription will take the ownership of
1659 // the offer.
1660 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001661 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001662 ASSERT_TRUE(offer != NULL);
1663 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1664}
1665
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001666//
1667// Tests for creating/setting SDP under different SDES/DTLS polices:
1668//
1669// --DTLS off and SDES on
1670// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1671// set local/remote offer/answer with crypto --> success
1672// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1673// failure
1674// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1675// failure
1676// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1677// failure
1678//
1679// --DTLS on and SDES off
1680// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1681// set local/remote offer/answer with DTLS fingerprint --> success
1682// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1683// fingerprint --> failure
1684// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1685// --> failure
1686// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1687// --> failure
1688//
1689// --Encryption disabled: DTLS off and SDES off
1690// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1691// answer without SDES or DTLS --> success
1692// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1693// answer without SDES or DTLS --> success
1694//
1695
1696// Test that we return a failure when applying a remote/local offer that doesn't
1697// have cryptos enabled when DTLS is off.
1698TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001699 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001701 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702 JsepSessionDescription* offer = CreateRemoteOffer(
1703 options, cricket::SEC_DISABLED);
1704 ASSERT_TRUE(offer != NULL);
1705 VerifyNoCryptoParams(offer->description(), false);
1706 // SetRemoteDescription and SetLocalDescription will take the ownership of
1707 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001708 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001709 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1710 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001711 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712}
1713
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001714// Test that we return a failure when applying a local answer that doesn't have
1715// cryptos enabled when DTLS is off.
1716TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001717 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 SessionDescriptionInterface* offer = NULL;
1719 SessionDescriptionInterface* answer = NULL;
1720 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1721 // SetRemoteDescription and SetLocalDescription will take the ownership of
1722 // the offer.
1723 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001724 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725}
1726
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001727// Test we will return fail when apply an remote answer that doesn't have
1728// crypto enabled when DTLS is off.
1729TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001730 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 SessionDescriptionInterface* offer = NULL;
1732 SessionDescriptionInterface* answer = NULL;
1733 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1734 // SetRemoteDescription and SetLocalDescription will take the ownership of
1735 // the offer.
1736 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001737 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738}
1739
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001740// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1741// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001742TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001743 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001744 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001745 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 SetFactoryDtlsSrtp();
1747 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001748 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001749 JsepSessionDescription* offer =
1750 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 ASSERT_TRUE(offer != NULL);
1752 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001753 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754
1755 // SetRemoteDescription will take the ownership of the offer.
1756 SetRemoteDescriptionWithoutError(offer);
1757
1758 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001759 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 ASSERT_TRUE(answer != NULL);
1761 VerifyFingerprintStatus(answer->description(), true);
1762 // Check that we don't have an a=crypto line in the answer.
1763 VerifyNoCryptoParams(answer->description(), true);
1764
1765 // Now set the local description, which should work, even without a=crypto.
1766 SetLocalDescriptionWithoutError(answer);
1767}
1768
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001769// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1770// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001771TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001772 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001773 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001774 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001775 SetFactoryDtlsSrtp();
1776
1777 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001778 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001779 ASSERT_TRUE(offer != NULL);
1780 VerifyFingerprintStatus(offer->description(), true);
1781 // Check that we don't have an a=crypto line in the offer.
1782 VerifyNoCryptoParams(offer->description(), true);
1783
1784 // Now set the local description, which should work, even without a=crypto.
1785 SetLocalDescriptionWithoutError(offer);
1786
1787 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001788 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001789 JsepSessionDescription* answer =
1790 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1791 ASSERT_TRUE(answer != NULL);
1792 VerifyFingerprintStatus(answer->description(), true);
1793 VerifyNoCryptoParams(answer->description(), true);
1794
1795 // SetRemoteDescription will take the ownership of the answer.
1796 SetRemoteDescriptionWithoutError(answer);
1797}
1798
1799// Test that if we support DTLS and the other side didn't offer a fingerprint,
1800// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001801TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001802 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001803 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001805 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001806 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 JsepSessionDescription* offer = CreateRemoteOffer(
1808 options, cricket::SEC_REQUIRED);
1809 ASSERT_TRUE(offer != NULL);
1810 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001811 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001813 // SetRemoteDescription will take the ownership of the offer.
1814 SetRemoteDescriptionOfferExpectError(
1815 kSdpWithoutDtlsFingerprint, offer);
1816
1817 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1818 // SetLocalDescription will take the ownership of the offer.
1819 SetLocalDescriptionOfferExpectError(
1820 kSdpWithoutDtlsFingerprint, offer);
1821}
1822
1823// Test that we return a failure when applying a local answer that doesn't have
1824// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001825TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001826 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001827 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001828 SessionDescriptionInterface* offer = NULL;
1829 SessionDescriptionInterface* answer = NULL;
1830 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1831
1832 // SetRemoteDescription and SetLocalDescription will take the ownership of
1833 // the offer and answer.
1834 SetRemoteDescriptionWithoutError(offer);
1835 SetLocalDescriptionAnswerExpectError(
1836 kSdpWithoutDtlsFingerprint, answer);
1837}
1838
1839// Test that we return a failure when applying a remote answer that doesn't have
1840// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001841TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001842 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001843 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001844 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001845 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001846 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001847 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1848 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001849 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001850 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001851
1852 // SetRemoteDescription and SetLocalDescription will take the ownership of
1853 // the offer and answer.
1854 SetLocalDescriptionWithoutError(offer);
1855 SetRemoteDescriptionAnswerExpectError(
1856 kSdpWithoutDtlsFingerprint, answer);
1857}
1858
1859// Test that we create a local offer without SDES or DTLS and accept a remote
1860// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001861TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001862 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001863 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001864 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001865
1866 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001867 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001868 ASSERT_TRUE(offer != NULL);
1869 VerifyFingerprintStatus(offer->description(), false);
1870 // Check that we don't have an a=crypto line in the offer.
1871 VerifyNoCryptoParams(offer->description(), false);
1872
1873 // Now set the local description, which should work, even without a=crypto.
1874 SetLocalDescriptionWithoutError(offer);
1875
1876 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001877 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001878 JsepSessionDescription* answer =
1879 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1880 ASSERT_TRUE(answer != NULL);
1881 VerifyFingerprintStatus(answer->description(), false);
1882 VerifyNoCryptoParams(answer->description(), false);
1883
1884 // SetRemoteDescription will take the ownership of the answer.
1885 SetRemoteDescriptionWithoutError(answer);
1886}
1887
1888// Test that we create a local answer without SDES or DTLS and accept a remote
1889// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001890TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001891 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001892 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001893
1894 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001895 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001896 JsepSessionDescription* offer =
1897 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1898 ASSERT_TRUE(offer != NULL);
1899 VerifyFingerprintStatus(offer->description(), false);
1900 VerifyNoCryptoParams(offer->description(), false);
1901
1902 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001903 SetRemoteDescriptionWithoutError(offer);
1904
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001905 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001906 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 ASSERT_TRUE(answer != NULL);
1908 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001909 // Check that we don't have an a=crypto line in the answer.
1910 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001912 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913 SetLocalDescriptionWithoutError(answer);
1914}
1915
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001916// Test that we can create and set an answer correctly when different
1917// SSL roles have been negotiated for different transports.
1918// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1919TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1920 SendAudioVideoStream1();
1921 InitWithDtls(GetParam());
1922 SetFactoryDtlsSrtp();
1923
1924 SessionDescriptionInterface* offer = CreateOffer();
1925 SetLocalDescriptionWithoutError(offer);
1926
1927 cricket::MediaSessionOptions options;
1928 options.recv_video = true;
1929
1930 // First, negotiate different SSL roles.
1931 SessionDescriptionInterface* answer =
1932 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1933 TransportInfo* audio_transport_info =
1934 answer->description()->GetTransportInfoByName("audio");
1935 audio_transport_info->description.connection_role =
1936 cricket::CONNECTIONROLE_ACTIVE;
1937 TransportInfo* video_transport_info =
1938 answer->description()->GetTransportInfoByName("video");
1939 video_transport_info->description.connection_role =
1940 cricket::CONNECTIONROLE_PASSIVE;
1941 SetRemoteDescriptionWithoutError(answer);
1942
1943 // Now create an offer in the reverse direction, and ensure the initial
1944 // offerer responds with an answer with correct SSL roles.
1945 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1946 kSessionVersion,
1947 session_->remote_description());
1948 SetRemoteDescriptionWithoutError(offer);
1949
1950 answer = CreateAnswer(nullptr);
1951 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1952 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1953 audio_transport_info->description.connection_role);
1954 video_transport_info = answer->description()->GetTransportInfoByName("video");
1955 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1956 video_transport_info->description.connection_role);
1957 SetLocalDescriptionWithoutError(answer);
1958
1959 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1960 // audio is transferred over to video in the answer that completes the BUNDLE
1961 // negotiation.
1962 options.bundle_enabled = true;
1963 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1964 kSessionVersion,
1965 session_->remote_description());
1966 SetRemoteDescriptionWithoutError(offer);
1967 answer = CreateAnswer(nullptr);
1968 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1969 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1970 audio_transport_info->description.connection_role);
1971 video_transport_info = answer->description()->GetTransportInfoByName("video");
1972 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1973 video_transport_info->description.connection_role);
1974 SetLocalDescriptionWithoutError(answer);
1975}
1976
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001978 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001979 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001981 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982 SetLocalDescriptionWithoutError(offer);
1983
1984 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001985 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 SetLocalDescriptionWithoutError(offer2);
1987}
1988
1989TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001990 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001991 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001993 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994 SetRemoteDescriptionWithoutError(offer);
1995
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001996 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 SetRemoteDescriptionWithoutError(offer2);
1998}
1999
2000TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002001 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002002 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002003 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002005 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002006 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2007 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008}
2009
2010TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002011 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002012 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002013 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002015 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002016 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002017 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018}
2019
2020TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002021 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002022 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002024 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025
2026 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002027 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002029 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030
deadbeefab9b2d12015-10-14 11:33:11 -07002031 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002032 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002033 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2035
deadbeefd59daf82015-10-14 15:02:44 -07002036 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037
deadbeefab9b2d12015-10-14 11:33:11 -07002038 SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002039 SessionDescriptionInterface* answer = CreateAnswer(NULL);
deadbeefd59daf82015-10-14 15:02:44 -07002040 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041}
2042
2043TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002044 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002045 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002046 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002047 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048
2049 JsepSessionDescription* pranswer =
2050 CreateRemoteAnswer(session_->local_description());
2051 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2052
2053 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002054 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055
deadbeefab9b2d12015-10-14 11:33:11 -07002056 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057 JsepSessionDescription* pranswer2 =
2058 CreateRemoteAnswer(session_->local_description());
2059 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2060
2061 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002062 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063
deadbeefab9b2d12015-10-14 11:33:11 -07002064 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065 SessionDescriptionInterface* answer =
2066 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002067 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068}
2069
2070TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
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 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2074
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075 SessionDescriptionInterface* answer =
2076 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002077 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2078 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079}
2080
2081TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002082 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002083 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002084 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2085
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002086 SessionDescriptionInterface* answer =
2087 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002088 SetRemoteDescriptionAnswerExpectError(
2089 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090}
2091
2092TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002093 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002094 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095
2096 cricket::Candidate candidate;
2097 candidate.set_component(1);
2098 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2099
deadbeefd59daf82015-10-14 15:02:44 -07002100 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2102
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002103 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002105
2106 // Fail since we have not set a remote description.
2107 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108
2109 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2110 session_->local_description());
2111 SetRemoteDescriptionWithoutError(answer);
2112
deadbeefd59daf82015-10-14 15:02:44 -07002113 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2114 candidate.set_component(2);
2115 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2116 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2117
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118 // Verifying the candidates are copied properly from internal vector.
2119 const SessionDescriptionInterface* remote_desc =
2120 session_->remote_description();
2121 ASSERT_TRUE(remote_desc != NULL);
2122 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2123 const IceCandidateCollection* candidates =
2124 remote_desc->candidates(kMediaContentIndex0);
2125 ASSERT_EQ(2u, candidates->count());
2126 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2127 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2128 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2129 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2130
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002131 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2132 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 candidate.set_component(2);
2134 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2135 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002136 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137
2138 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2139 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2140}
2141
2142// Test that a remote candidate is added to the remote session description and
2143// that it is retained if the remote session description is changed.
2144TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002145 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146 cricket::Candidate candidate1;
2147 candidate1.set_component(1);
2148 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2149 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002150 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151 CreateAndSetRemoteOfferAndLocalAnswer();
2152
2153 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2154 const SessionDescriptionInterface* remote_desc =
2155 session_->remote_description();
2156 ASSERT_TRUE(remote_desc != NULL);
2157 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2158 const IceCandidateCollection* candidates =
2159 remote_desc->candidates(kMediaContentIndex0);
2160 ASSERT_EQ(1u, candidates->count());
2161 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2162
2163 // Update the RemoteSessionDescription with a new session description and
2164 // a candidate and check that the new remote session description contains both
2165 // candidates.
2166 SessionDescriptionInterface* offer = CreateRemoteOffer();
2167 cricket::Candidate candidate2;
2168 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2169 candidate2);
2170 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2171 SetRemoteDescriptionWithoutError(offer);
2172
2173 remote_desc = session_->remote_description();
2174 ASSERT_TRUE(remote_desc != NULL);
2175 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2176 candidates = remote_desc->candidates(kMediaContentIndex0);
2177 ASSERT_EQ(2u, candidates->count());
2178 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2179 // Username and password have be updated with the TransportInfo of the
2180 // SessionDescription, won't be equal to the original one.
2181 candidate2.set_username(candidates->at(0)->candidate().username());
2182 candidate2.set_password(candidates->at(0)->candidate().password());
2183 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2184 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2185 // No need to verify the username and password.
2186 candidate1.set_username(candidates->at(1)->candidate().username());
2187 candidate1.set_password(candidates->at(1)->candidate().password());
2188 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2189
2190 // Test that the candidate is ignored if we can add the same candidate again.
2191 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2192}
2193
2194// Test that local candidates are added to the local session description and
2195// that they are retained if the local session description is changed.
2196TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002197 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002198 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002199 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002200 CreateAndSetRemoteOfferAndLocalAnswer();
2201
2202 const SessionDescriptionInterface* local_desc = session_->local_description();
2203 const IceCandidateCollection* candidates =
2204 local_desc->candidates(kMediaContentIndex0);
2205 ASSERT_TRUE(candidates != NULL);
2206 EXPECT_EQ(0u, candidates->count());
2207
2208 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2209
2210 local_desc = session_->local_description();
2211 candidates = local_desc->candidates(kMediaContentIndex0);
2212 ASSERT_TRUE(candidates != NULL);
2213 EXPECT_LT(0u, candidates->count());
2214 candidates = local_desc->candidates(1);
2215 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002216 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217
2218 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002219 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220 CreateAndSetRemoteOfferAndLocalAnswer();
2221
2222 local_desc = session_->local_description();
2223 candidates = local_desc->candidates(kMediaContentIndex0);
2224 ASSERT_TRUE(candidates != NULL);
2225 EXPECT_LT(0u, candidates->count());
2226 candidates = local_desc->candidates(1);
2227 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002228 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229}
2230
2231// Test that we can set a remote session description with remote candidates.
2232TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002233 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002234
2235 cricket::Candidate candidate1;
2236 candidate1.set_component(1);
2237 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2238 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002239 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002240 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002241
2242 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2243 SetRemoteDescriptionWithoutError(offer);
2244
2245 const SessionDescriptionInterface* remote_desc =
2246 session_->remote_description();
2247 ASSERT_TRUE(remote_desc != NULL);
2248 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2249 const IceCandidateCollection* candidates =
2250 remote_desc->candidates(kMediaContentIndex0);
2251 ASSERT_EQ(1u, candidates->count());
2252 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2253
wu@webrtc.org91053e72013-08-10 07:18:04 +00002254 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002255 SetLocalDescriptionWithoutError(answer);
2256}
2257
2258// Test that offers and answers contains ice candidates when Ice candidates have
2259// been gathered.
2260TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002261 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002262 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002263 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002264 // Ice is started but candidates are not provided until SetLocalDescription
2265 // is called.
2266 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2267 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2268 CreateAndSetRemoteOfferAndLocalAnswer();
2269 // Wait until at least one local candidate has been collected.
2270 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2271 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002273 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2274
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2276 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277
2278 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2279 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002280 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2282 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 SetLocalDescriptionWithoutError(answer);
2284}
2285
2286// Verifies TransportProxy and media channels are created with content names
2287// present in the SessionDescription.
2288TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002289 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002290 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002291 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292
2293 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002294 // "video". Goal is to modify these content names and verify transport
2295 // channels
2296 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297 // present in SDP.
2298 std::string sdp;
2299 EXPECT_TRUE(offer->ToString(&sdp));
2300 const std::string kAudioMid = "a=mid:audio";
2301 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2302 const std::string kVideoMid = "a=mid:video";
2303 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2304
2305 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002306 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002307 kAudioMidReplaceStr.c_str(),
2308 kAudioMidReplaceStr.length(),
2309 &sdp);
2310 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002311 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002312 kVideoMidReplaceStr.c_str(),
2313 kVideoMidReplaceStr.length(),
2314 &sdp);
2315
2316 SessionDescriptionInterface* modified_offer =
2317 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2318
2319 SetRemoteDescriptionWithoutError(modified_offer);
2320
2321 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002322 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323 SetLocalDescriptionWithoutError(answer);
2324
deadbeefcbecd352015-09-23 11:50:27 -07002325 cricket::TransportChannel* voice_transport_channel =
2326 session_->voice_rtp_transport_channel();
2327 EXPECT_TRUE(voice_transport_channel != NULL);
2328 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2329 cricket::TransportChannel* video_transport_channel =
2330 session_->video_rtp_transport_channel();
2331 EXPECT_TRUE(video_transport_channel != NULL);
2332 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2334 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2335}
2336
2337// Test that an offer contains the correct media content descriptions based on
2338// the send streams when no constraints have been set.
2339TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002340 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002341 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2342
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343 ASSERT_TRUE(offer != NULL);
2344 const cricket::ContentInfo* content =
2345 cricket::GetFirstAudioContent(offer->description());
2346 EXPECT_TRUE(content != NULL);
2347 content = cricket::GetFirstVideoContent(offer->description());
2348 EXPECT_TRUE(content == NULL);
2349}
2350
2351// Test that an offer contains the correct media content descriptions based on
2352// the send streams when no constraints have been set.
2353TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002354 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002356 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002357 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2358
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 const cricket::ContentInfo* content =
2360 cricket::GetFirstAudioContent(offer->description());
2361 EXPECT_TRUE(content != NULL);
2362 content = cricket::GetFirstVideoContent(offer->description());
2363 EXPECT_TRUE(content == NULL);
2364
2365 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002366 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002367 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368 content = cricket::GetFirstAudioContent(offer->description());
2369 EXPECT_TRUE(content != NULL);
2370 content = cricket::GetFirstVideoContent(offer->description());
2371 EXPECT_TRUE(content != NULL);
2372}
2373
2374// Test that an offer contains no media content descriptions if
2375// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2376TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002377 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002378 PeerConnectionInterface::RTCOfferAnswerOptions options;
2379 options.offer_to_receive_audio = 0;
2380 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002382 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002383 CreateOffer(options));
2384
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002385 ASSERT_TRUE(offer != NULL);
2386 const cricket::ContentInfo* content =
2387 cricket::GetFirstAudioContent(offer->description());
2388 EXPECT_TRUE(content == NULL);
2389 content = cricket::GetFirstVideoContent(offer->description());
2390 EXPECT_TRUE(content == NULL);
2391}
2392
2393// Test that an offer contains only audio media content descriptions if
2394// kOfferToReceiveAudio constraints are set to true.
2395TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002396 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002397 PeerConnectionInterface::RTCOfferAnswerOptions options;
2398 options.offer_to_receive_audio =
2399 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2400
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002401 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002402 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403
2404 const cricket::ContentInfo* content =
2405 cricket::GetFirstAudioContent(offer->description());
2406 EXPECT_TRUE(content != NULL);
2407 content = cricket::GetFirstVideoContent(offer->description());
2408 EXPECT_TRUE(content == NULL);
2409}
2410
2411// Test that an offer contains audio and video media content descriptions if
2412// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2413TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002414 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002415 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002416 PeerConnectionInterface::RTCOfferAnswerOptions options;
2417 options.offer_to_receive_audio =
2418 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2419 options.offer_to_receive_video =
2420 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2421
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002422 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002423 CreateOffer(options));
2424
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425 const cricket::ContentInfo* content =
2426 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002427 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002428
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002429 content = cricket::GetFirstVideoContent(offer->description());
2430 EXPECT_TRUE(content != NULL);
2431
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002432 // Sets constraints to false and verifies that audio/video contents are
2433 // removed.
2434 options.offer_to_receive_audio = 0;
2435 options.offer_to_receive_video = 0;
2436 offer.reset(CreateOffer(options));
2437
2438 content = cricket::GetFirstAudioContent(offer->description());
2439 EXPECT_TRUE(content == NULL);
2440 content = cricket::GetFirstVideoContent(offer->description());
2441 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002442}
2443
2444// Test that an answer can not be created if the last remote description is not
2445// an offer.
2446TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002447 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002448 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002449 SetLocalDescriptionWithoutError(offer);
2450 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2451 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002452 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002453}
2454
2455// Test that an answer contains the correct media content descriptions when no
2456// constraints have been set.
2457TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002458 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002460 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002461 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002462 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002463 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002464 const cricket::ContentInfo* content =
2465 cricket::GetFirstAudioContent(answer->description());
2466 ASSERT_TRUE(content != NULL);
2467 EXPECT_FALSE(content->rejected);
2468
2469 content = cricket::GetFirstVideoContent(answer->description());
2470 ASSERT_TRUE(content != NULL);
2471 EXPECT_FALSE(content->rejected);
2472}
2473
2474// Test that an answer contains the correct media content descriptions when no
2475// constraints have been set and the offer only contain audio.
2476TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002477 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478 // Create a remote offer with audio only.
2479 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002480
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002481 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002482 CreateRemoteOffer(options));
2483 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2484 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2485
2486 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002487 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002488 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002489 const cricket::ContentInfo* content =
2490 cricket::GetFirstAudioContent(answer->description());
2491 ASSERT_TRUE(content != NULL);
2492 EXPECT_FALSE(content->rejected);
2493
2494 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2495}
2496
2497// Test that an answer contains the correct media content descriptions when no
2498// constraints have been set.
2499TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002500 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002501 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002502 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002503 SetRemoteDescriptionWithoutError(offer.release());
2504 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002505 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002506 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002507 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002508 const cricket::ContentInfo* content =
2509 cricket::GetFirstAudioContent(answer->description());
2510 ASSERT_TRUE(content != NULL);
2511 EXPECT_FALSE(content->rejected);
2512
2513 content = cricket::GetFirstVideoContent(answer->description());
2514 ASSERT_TRUE(content != NULL);
2515 EXPECT_FALSE(content->rejected);
2516}
2517
2518// Test that an answer contains the correct media content descriptions when
2519// constraints have been set but no stream is sent.
2520TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002521 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002522 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002523 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002524 SetRemoteDescriptionWithoutError(offer.release());
2525
2526 webrtc::FakeConstraints constraints_no_receive;
2527 constraints_no_receive.SetMandatoryReceiveAudio(false);
2528 constraints_no_receive.SetMandatoryReceiveVideo(false);
2529
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002530 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002531 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532 const cricket::ContentInfo* content =
2533 cricket::GetFirstAudioContent(answer->description());
2534 ASSERT_TRUE(content != NULL);
2535 EXPECT_TRUE(content->rejected);
2536
2537 content = cricket::GetFirstVideoContent(answer->description());
2538 ASSERT_TRUE(content != NULL);
2539 EXPECT_TRUE(content->rejected);
2540}
2541
2542// Test that an answer contains the correct media content descriptions when
2543// constraints have been set and streams are sent.
2544TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002545 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002547 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548 SetRemoteDescriptionWithoutError(offer.release());
2549
2550 webrtc::FakeConstraints constraints_no_receive;
2551 constraints_no_receive.SetMandatoryReceiveAudio(false);
2552 constraints_no_receive.SetMandatoryReceiveVideo(false);
2553
2554 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002555 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002556 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002557 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558
2559 // TODO(perkj): Should the direction be set to SEND_ONLY?
2560 const cricket::ContentInfo* content =
2561 cricket::GetFirstAudioContent(answer->description());
2562 ASSERT_TRUE(content != NULL);
2563 EXPECT_FALSE(content->rejected);
2564
2565 // TODO(perkj): Should the direction be set to SEND_ONLY?
2566 content = cricket::GetFirstVideoContent(answer->description());
2567 ASSERT_TRUE(content != NULL);
2568 EXPECT_FALSE(content->rejected);
2569}
2570
2571TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2572 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002573 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002574 PeerConnectionInterface::RTCOfferAnswerOptions options;
2575 options.offer_to_receive_audio =
2576 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2577 options.voice_activity_detection = false;
2578
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002579 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002580 CreateOffer(options));
2581
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002582 const cricket::ContentInfo* content =
2583 cricket::GetFirstAudioContent(offer->description());
2584 EXPECT_TRUE(content != NULL);
2585 EXPECT_TRUE(VerifyNoCNCodecs(content));
2586}
2587
2588TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2589 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002590 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002591 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002592 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593 SetRemoteDescriptionWithoutError(offer.release());
2594
2595 webrtc::FakeConstraints constraints;
2596 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002597 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002598 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002599 const cricket::ContentInfo* content =
2600 cricket::GetFirstAudioContent(answer->description());
2601 ASSERT_TRUE(content != NULL);
2602 EXPECT_TRUE(VerifyNoCNCodecs(content));
2603}
2604
2605// This test verifies the call setup when remote answer with audio only and
2606// later updates with video.
2607TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002608 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002609 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2610 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2611
deadbeefab9b2d12015-10-14 11:33:11 -07002612 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002613 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002614
2615 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2617
2618 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2619 // and answer;
2620 SetLocalDescriptionWithoutError(offer);
2621 SetRemoteDescriptionWithoutError(answer);
2622
2623 video_channel_ = media_engine_->GetVideoChannel(0);
2624 voice_channel_ = media_engine_->GetVoiceChannel(0);
2625
2626 ASSERT_TRUE(video_channel_ == NULL);
2627
2628 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2629 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2630 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2631
2632 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002633 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002634 CreateAndSetRemoteOfferAndLocalAnswer();
2635
2636 video_channel_ = media_engine_->GetVideoChannel(0);
2637 voice_channel_ = media_engine_->GetVoiceChannel(0);
2638
2639 ASSERT_TRUE(video_channel_ != NULL);
2640 ASSERT_TRUE(voice_channel_ != NULL);
2641
2642 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2643 ASSERT_EQ(1u, video_channel_->send_streams().size());
2644 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2645 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2646 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2647 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2648 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2649 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2650
2651 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002652 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002653 CreateAndSetRemoteOfferAndLocalAnswer();
2654
2655 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2656 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2657 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2658 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2659 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2660}
2661
2662// This test verifies the call setup when remote answer with video only and
2663// later updates with audio.
2664TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002665 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002666 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2667 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002668 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002669 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002670
2671 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002672 options.recv_audio = false;
2673 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002674 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2675 offer, options, cricket::SEC_ENABLED);
2676
2677 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2678 // and answer.
2679 SetLocalDescriptionWithoutError(offer);
2680 SetRemoteDescriptionWithoutError(answer);
2681
2682 video_channel_ = media_engine_->GetVideoChannel(0);
2683 voice_channel_ = media_engine_->GetVoiceChannel(0);
2684
2685 ASSERT_TRUE(voice_channel_ == NULL);
2686 ASSERT_TRUE(video_channel_ != NULL);
2687
2688 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2689 ASSERT_EQ(1u, video_channel_->send_streams().size());
2690 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2691
2692 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002693 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002694 CreateAndSetRemoteOfferAndLocalAnswer();
2695
2696 voice_channel_ = media_engine_->GetVoiceChannel(0);
2697 ASSERT_TRUE(voice_channel_ != NULL);
2698
2699 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2700 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2701 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2702 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2703
2704 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002705 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002706 CreateAndSetRemoteOfferAndLocalAnswer();
2707
2708 video_channel_ = media_engine_->GetVideoChannel(0);
2709 voice_channel_ = media_engine_->GetVoiceChannel(0);
2710
2711 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2712 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2713 ASSERT_EQ(1u, video_channel_->send_streams().size());
2714 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2715}
2716
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002717TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002718 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002719 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002720 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002721 VerifyCryptoParams(offer->description());
2722 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002723 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002724 VerifyCryptoParams(answer->description());
2725}
2726
2727TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002728 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002729 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002730 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002731 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002732 VerifyNoCryptoParams(offer->description(), false);
2733}
2734
2735TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002736 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002737 VerifyAnswerFromNonCryptoOffer();
2738}
2739
2740TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002741 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002742 VerifyAnswerFromCryptoOffer();
2743}
2744
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002745// This test verifies that setLocalDescription fails if
2746// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2747TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002748 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002749 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002750 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2751
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002752 std::string sdp;
2753 RemoveIceUfragPwdLines(offer.get(), &sdp);
2754 SessionDescriptionInterface* modified_offer =
2755 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002756 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002757}
2758
2759// This test verifies that setRemoteDescription fails if
2760// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2761TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002762 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002763 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002764 std::string sdp;
2765 RemoveIceUfragPwdLines(offer.get(), &sdp);
2766 SessionDescriptionInterface* modified_offer =
2767 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002768 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002769}
2770
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002771// This test verifies that setLocalDescription fails if local offer has
2772// too short ice ufrag and pwd strings.
2773TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002774 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002775 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002776 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2777
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002778 std::string sdp;
2779 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2780 // recommended values of 4 and 22 bytes respectively.
2781 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2782 SessionDescriptionInterface* modified_offer =
2783 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2784 std::string error;
2785 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2786
2787 // Test with string greater than 256.
2788 sdp.clear();
2789 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2790 &sdp);
2791 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2792 NULL);
2793 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2794}
2795
2796// This test verifies that setRemoteDescription fails if remote offer has
2797// too short ice ufrag and pwd strings.
2798TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002799 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002800 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002801 std::string sdp;
2802 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2803 // recommended values of 4 and 22 bytes respectively.
2804 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2805 SessionDescriptionInterface* modified_offer =
2806 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2807 std::string error;
2808 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2809
2810 sdp.clear();
2811 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2812 &sdp);
2813 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2814 NULL);
2815 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2816}
2817
Honghai Zhang04e91462015-12-11 14:26:22 -08002818// Test that if the remote offer indicates the peer requested ICE restart (via
2819// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2820TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002821 Init();
2822 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2823
2824 // Create the first offer.
2825 std::string sdp;
2826 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2827 "abcdefghijklmnopqrstuvwx", &sdp);
2828 SessionDescriptionInterface* offer1 =
2829 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2830 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2831 0, "", "", "relay", 0, "");
2832 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2833 candidate1);
2834 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2835 SetRemoteDescriptionWithoutError(offer1);
2836 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2837
2838 // The second offer has the same ufrag and pwd but different address.
2839 sdp.clear();
2840 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2841 "abcdefghijklmnopqrstuvwx", &sdp);
2842 SessionDescriptionInterface* offer2 =
2843 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2844 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2845 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2846 candidate1);
2847 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2848 SetRemoteDescriptionWithoutError(offer2);
2849 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2850
2851 // The third offer has a different ufrag and different address.
2852 sdp.clear();
2853 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2854 "abcdefghijklmnopqrstuvwx", &sdp);
2855 SessionDescriptionInterface* offer3 =
2856 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2857 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2858 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2859 candidate1);
2860 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2861 SetRemoteDescriptionWithoutError(offer3);
2862 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2863
2864 // The fourth offer has no candidate but a different ufrag/pwd.
2865 sdp.clear();
2866 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2867 "abcdefghijklmnopqrstuvyz", &sdp);
2868 SessionDescriptionInterface* offer4 =
2869 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2870 SetRemoteDescriptionWithoutError(offer4);
2871 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2872}
2873
Honghai Zhang04e91462015-12-11 14:26:22 -08002874// Test that if the remote answer indicates the peer requested ICE restart (via
2875// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2876TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2877 Init();
2878 SessionDescriptionInterface* offer = CreateOffer();
2879 SetLocalDescriptionWithoutError(offer);
2880 scoped_ptr<SessionDescriptionInterface> answer(CreateRemoteAnswer(offer));
2881
2882 // Create the first answer.
2883 std::string sdp;
2884 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2885 "abcdefghijklmnopqrstuvwx", &sdp);
2886 SessionDescriptionInterface* answer1 =
2887 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2888 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2889 0, "", "", "relay", 0, "");
2890 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2891 candidate1);
2892 EXPECT_TRUE(answer1->AddCandidate(&ice_candidate1));
2893 SetRemoteDescriptionWithoutError(answer1);
2894 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2895
2896 // The second answer has the same ufrag and pwd but different address.
2897 sdp.clear();
2898 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2899 "abcdefghijklmnopqrstuvwx", &sdp);
2900 SessionDescriptionInterface* answer2 =
2901 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2902 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2903 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2904 candidate1);
2905 EXPECT_TRUE(answer2->AddCandidate(&ice_candidate2));
2906 SetRemoteDescriptionWithoutError(answer2);
2907 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2908
2909 // The third answer has a different ufrag and different address.
2910 sdp.clear();
2911 ModifyIceUfragPwdLines(answer.get(), "0123456789012333",
2912 "abcdefghijklmnopqrstuvwx", &sdp);
2913 SessionDescriptionInterface* answer3 =
2914 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2915 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2916 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2917 candidate1);
2918 EXPECT_TRUE(answer3->AddCandidate(&ice_candidate3));
2919 SetRemoteDescriptionWithoutError(answer3);
2920 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2921
2922 // The fourth answer has no candidate but a different ufrag/pwd.
2923 sdp.clear();
2924 ModifyIceUfragPwdLines(answer.get(), "0123456789012444",
2925 "abcdefghijklmnopqrstuvyz", &sdp);
2926 SessionDescriptionInterface* offer4 =
2927 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2928 SetRemoteDescriptionWithoutError(offer4);
2929 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2930}
2931
Donald Curtisd4f769d2015-05-28 09:48:21 -07002932// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002933// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002934TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2935 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2936
2937 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002938 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002939
2940 PeerConnectionInterface::RTCOfferAnswerOptions options;
2941 options.use_rtp_mux = true;
2942
2943 SessionDescriptionInterface* offer = CreateRemoteOffer();
2944 SetRemoteDescriptionWithoutError(offer);
2945
2946 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2947 SetLocalDescriptionWithoutError(answer);
2948
deadbeefcbecd352015-09-23 11:50:27 -07002949 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2950 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002951
deadbeefcbecd352015-09-23 11:50:27 -07002952 cricket::BaseChannel* voice_channel = session_->voice_channel();
2953 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002954
2955 // Checks if one of the transport channels contains a connection using a given
2956 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002957 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002958 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002959 session_->GetChannelTransportStats(voice_channel, &stats);
2960 for (auto& kv : stats.transport_stats) {
2961 for (auto& chan_stat : kv.second.channel_stats) {
2962 for (auto& conn_info : chan_stat.connection_infos) {
2963 if (conn_info.remote_candidate.address().port() == port) {
2964 return true;
2965 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002966 }
2967 }
2968 }
2969 return false;
2970 };
2971
2972 EXPECT_FALSE(connection_with_remote_port(5000));
2973 EXPECT_FALSE(connection_with_remote_port(5001));
2974 EXPECT_FALSE(connection_with_remote_port(6000));
2975
2976 // The way the *_WAIT checks work is they only wait if the condition fails,
2977 // which does not help in the case where state is not changing. This is
2978 // problematic in this test since we want to verify that adding a video
2979 // candidate does _not_ change state. So we interleave candidates and assume
2980 // that messages are executed in the order they were posted.
2981
2982 // First audio candidate.
2983 cricket::Candidate candidate0;
2984 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2985 candidate0.set_component(1);
2986 candidate0.set_protocol("udp");
2987 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2988 candidate0);
2989 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2990
2991 // Video candidate.
2992 cricket::Candidate candidate1;
2993 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2994 candidate1.set_component(1);
2995 candidate1.set_protocol("udp");
2996 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2997 candidate1);
2998 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2999
3000 // Second audio candidate.
3001 cricket::Candidate candidate2;
3002 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3003 candidate2.set_component(1);
3004 candidate2.set_protocol("udp");
3005 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3006 candidate2);
3007 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3008
3009 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3010 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3011
3012 // No need here for a _WAIT check since we are checking that state hasn't
3013 // changed: if this is false we would be doing waits for nothing and if this
3014 // is true then there will be no messages processed anyways.
3015 EXPECT_FALSE(connection_with_remote_port(6000));
3016}
3017
deadbeefcbecd352015-09-23 11:50:27 -07003018// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003019TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3020 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003021 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003022
3023 PeerConnectionInterface::RTCOfferAnswerOptions options;
3024 options.use_rtp_mux = true;
3025
3026 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003027 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003028
deadbeefcbecd352015-09-23 11:50:27 -07003029 EXPECT_NE(session_->voice_rtp_transport_channel(),
3030 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003031
deadbeefab9b2d12015-10-14 11:33:11 -07003032 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003033 SessionDescriptionInterface* answer =
3034 CreateRemoteAnswer(session_->local_description());
3035 SetRemoteDescriptionWithoutError(answer);
3036
deadbeefcbecd352015-09-23 11:50:27 -07003037 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3038 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003039}
3040
deadbeefcbecd352015-09-23 11:50:27 -07003041// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003042TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3043 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003044 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003045
Donald Curtis0e209b02015-03-24 09:29:54 -07003046 PeerConnectionInterface::RTCOfferAnswerOptions options;
3047 options.use_rtp_mux = true;
3048
3049 SessionDescriptionInterface* offer = CreateOffer(options);
3050 SetLocalDescriptionWithoutError(offer);
3051
deadbeefcbecd352015-09-23 11:50:27 -07003052 EXPECT_NE(session_->voice_rtp_transport_channel(),
3053 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003054
deadbeefab9b2d12015-10-14 11:33:11 -07003055 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003056
3057 // Remove BUNDLE from the answer.
3058 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3059 CreateRemoteAnswer(session_->local_description()));
3060 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3061 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3062 JsepSessionDescription* modified_answer =
3063 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3064 modified_answer->Initialize(answer_copy, "1", "1");
3065 SetRemoteDescriptionWithoutError(modified_answer); //
3066
deadbeefcbecd352015-09-23 11:50:27 -07003067 EXPECT_NE(session_->voice_rtp_transport_channel(),
3068 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003069}
3070
3071// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3072TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3073 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003074 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003075
3076 PeerConnectionInterface::RTCOfferAnswerOptions options;
3077 options.use_rtp_mux = true;
3078
3079 SessionDescriptionInterface* offer = CreateOffer(options);
3080 SetLocalDescriptionWithoutError(offer);
3081
deadbeefcbecd352015-09-23 11:50:27 -07003082 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3083 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003084
deadbeefab9b2d12015-10-14 11:33:11 -07003085 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003086 SessionDescriptionInterface* answer =
3087 CreateRemoteAnswer(session_->local_description());
3088 SetRemoteDescriptionWithoutError(answer);
3089
deadbeefcbecd352015-09-23 11:50:27 -07003090 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3091 session_->video_rtp_transport_channel());
3092}
3093
3094// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3095// audio content in the answer.
3096TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3097 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003098 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003099
3100 PeerConnectionInterface::RTCOfferAnswerOptions options;
3101 options.use_rtp_mux = true;
3102
3103 SessionDescriptionInterface* offer = CreateOffer(options);
3104 SetLocalDescriptionWithoutError(offer);
3105
3106 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3107 session_->video_rtp_transport_channel());
3108
deadbeefab9b2d12015-10-14 11:33:11 -07003109 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003110 cricket::MediaSessionOptions recv_options;
3111 recv_options.recv_audio = false;
3112 recv_options.recv_video = true;
3113 SessionDescriptionInterface* answer =
3114 CreateRemoteAnswer(session_->local_description(), recv_options);
3115 SetRemoteDescriptionWithoutError(answer);
3116
deadbeefd59daf82015-10-14 15:02:44 -07003117 EXPECT_TRUE(nullptr == session_->voice_channel());
3118 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003119
deadbeefd59daf82015-10-14 15:02:44 -07003120 session_->Close();
3121 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3122 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3123 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3124 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003125}
3126
3127// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3128TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3129 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003130 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003131
Donald Curtis0e209b02015-03-24 09:29:54 -07003132 PeerConnectionInterface::RTCOfferAnswerOptions options;
3133 options.use_rtp_mux = true;
3134
3135 SessionDescriptionInterface* offer = CreateOffer(options);
3136 SetLocalDescriptionWithoutError(offer);
3137
deadbeefcbecd352015-09-23 11:50:27 -07003138 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3139 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003140
deadbeefab9b2d12015-10-14 11:33:11 -07003141 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003142
3143 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003144 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003145 CreateRemoteAnswer(session_->local_description()));
3146 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3147 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3148 JsepSessionDescription* modified_answer =
3149 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3150 modified_answer->Initialize(answer_copy, "1", "1");
3151 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003152
deadbeefcbecd352015-09-23 11:50:27 -07003153 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3154 session_->video_rtp_transport_channel());
3155}
3156
3157// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3158TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3159 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003160 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003161
3162 SessionDescriptionInterface* offer = CreateRemoteOffer();
3163 SetRemoteDescriptionWithoutError(offer);
3164
3165 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3166 session_->video_rtp_transport_channel());
3167
deadbeefab9b2d12015-10-14 11:33:11 -07003168 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003169 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
3170 SetLocalDescriptionWithoutError(answer);
3171
3172 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3173 session_->video_rtp_transport_channel());
3174}
3175
3176// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3177TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3178 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003179 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003180
3181 // Remove BUNDLE from the offer.
3182 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3183 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3184 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3185 JsepSessionDescription* modified_offer =
3186 new JsepSessionDescription(JsepSessionDescription::kOffer);
3187 modified_offer->Initialize(offer_copy, "1", "1");
3188
3189 // Expect an error when applying the remote description
3190 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3191 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003192}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003193
Peter Thatcher4eddf182015-04-30 10:55:59 -07003194// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003195TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3196 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003197 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003198
Donald Curtis0e209b02015-03-24 09:29:54 -07003199 PeerConnectionInterface::RTCOfferAnswerOptions options;
3200 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003201
Donald Curtis0e209b02015-03-24 09:29:54 -07003202 SessionDescriptionInterface* offer = CreateOffer(options);
3203 SetLocalDescriptionWithoutError(offer);
3204
deadbeefcbecd352015-09-23 11:50:27 -07003205 EXPECT_NE(session_->voice_rtp_transport_channel(),
3206 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003207
deadbeefab9b2d12015-10-14 11:33:11 -07003208 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003209 SessionDescriptionInterface* answer =
3210 CreateRemoteAnswer(session_->local_description());
3211 SetRemoteDescriptionWithoutError(answer);
3212
3213 // This should lead to an audio-only call but isn't implemented
3214 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003215 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3216 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003217}
3218
deadbeefcbecd352015-09-23 11:50:27 -07003219// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003220TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3221 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003222 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003223 PeerConnectionInterface::RTCOfferAnswerOptions options;
3224 options.use_rtp_mux = true;
3225
3226 SessionDescriptionInterface* offer = CreateOffer(options);
3227 SetLocalDescriptionWithoutError(offer);
3228
deadbeefcbecd352015-09-23 11:50:27 -07003229 EXPECT_NE(session_->voice_rtp_transport_channel(),
3230 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003231
deadbeefab9b2d12015-10-14 11:33:11 -07003232 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003233
3234 // Remove BUNDLE from the answer.
3235 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3236 CreateRemoteAnswer(session_->local_description()));
3237 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3238 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3239 JsepSessionDescription* modified_answer =
3240 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3241 modified_answer->Initialize(answer_copy, "1", "1");
3242 SetRemoteDescriptionWithoutError(modified_answer); //
3243
deadbeefcbecd352015-09-23 11:50:27 -07003244 EXPECT_NE(session_->voice_rtp_transport_channel(),
3245 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003246}
3247
Peter Thatcher4eddf182015-04-30 10:55:59 -07003248// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3249TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3250 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003251 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003252
3253 PeerConnectionInterface::RTCOfferAnswerOptions options;
3254 options.use_rtp_mux = true;
3255
3256 SessionDescriptionInterface* offer = CreateOffer(options);
3257 SetRemoteDescriptionWithoutError(offer);
3258
deadbeefcbecd352015-09-23 11:50:27 -07003259 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3260 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003261}
3262
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003263TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3264 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003265 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003266
3267 PeerConnectionInterface::RTCOfferAnswerOptions options;
3268 SessionDescriptionInterface* offer = CreateOffer(options);
3269 SetLocalDescriptionWithoutError(offer);
3270
deadbeefcbecd352015-09-23 11:50:27 -07003271 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3272 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003273
deadbeefab9b2d12015-10-14 11:33:11 -07003274 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003275 SessionDescriptionInterface* answer =
3276 CreateRemoteAnswer(session_->local_description());
3277 SetRemoteDescriptionWithoutError(answer);
3278
deadbeefcbecd352015-09-23 11:50:27 -07003279 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3280 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003281}
3282
3283TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3284 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003285 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003286
3287 PeerConnectionInterface::RTCOfferAnswerOptions options;
3288 SessionDescriptionInterface* offer = CreateOffer(options);
3289 SetLocalDescriptionWithoutError(offer);
3290
deadbeefcbecd352015-09-23 11:50:27 -07003291 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3292 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003293
deadbeefab9b2d12015-10-14 11:33:11 -07003294 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003295 SessionDescriptionInterface* answer =
3296 CreateRemoteAnswer(session_->local_description());
3297 SetRemoteDescriptionWithoutError(answer);
3298
deadbeefcbecd352015-09-23 11:50:27 -07003299 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3300 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003301}
3302
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003303// This test verifies that SetLocalDescription and SetRemoteDescription fails
3304// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3305TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003306 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003307 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003308
3309 PeerConnectionInterface::RTCOfferAnswerOptions options;
3310 options.use_rtp_mux = true;
3311
3312 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003313 std::string offer_str;
3314 offer->ToString(&offer_str);
3315 // Disable rtcp-mux
3316 const std::string rtcp_mux = "rtcp-mux";
3317 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003318 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003319 xrtcp_mux.c_str(), xrtcp_mux.length(),
3320 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003321 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003322 new JsepSessionDescription(JsepSessionDescription::kOffer);
3323 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003324 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003325 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003326 new JsepSessionDescription(JsepSessionDescription::kOffer);
3327 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003328 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003329 // Trying unmodified SDP.
3330 SetLocalDescriptionWithoutError(offer);
3331}
3332
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003333TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003334 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003335 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336 CreateAndSetRemoteOfferAndLocalAnswer();
3337 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3338 ASSERT_TRUE(channel != NULL);
3339 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003340 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003341 double volume;
3342 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3343 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003344 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003345 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3346 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003347 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003348 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3349 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003350}
3351
3352TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003353 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003354 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003355 CreateAndSetRemoteOfferAndLocalAnswer();
3356 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3357 ASSERT_TRUE(channel != NULL);
3358 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003359 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003360 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3361
3362 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003363 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003364
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003365 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003366 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003367 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003368 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003369 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003370
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003371 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003372 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003373 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003374 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003375 EXPECT_TRUE(renderer->sink() == NULL);
3376}
3377
3378TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003379 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003380 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003381 CreateAndSetRemoteOfferAndLocalAnswer();
3382 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3383 ASSERT_TRUE(channel != NULL);
3384 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003385 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003386
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003387 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003388 cricket::AudioOptions options;
3389 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3390 EXPECT_TRUE(renderer->sink() != NULL);
3391
3392 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3393 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3394 // SetSink(NULL) callback afterwards.
3395 renderer.reset();
3396
3397 // This will trigger SetSink(NULL) if no OnClose() callback.
3398 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003399}
3400
3401TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003402 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003403 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003404 CreateAndSetRemoteOfferAndLocalAnswer();
3405 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3406 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003407 ASSERT_LT(0u, channel->sinks().size());
3408 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003409 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003410 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003411 cricket::FakeVideoRenderer renderer;
3412 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003413 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003414 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003415 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003416}
3417
3418TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003419 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003420 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003421 CreateAndSetRemoteOfferAndLocalAnswer();
3422 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3423 ASSERT_TRUE(channel != NULL);
3424 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003425 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003426 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3427 cricket::VideoOptions* options = NULL;
3428 session_->SetVideoSend(send_ssrc, false, options);
3429 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3430 session_->SetVideoSend(send_ssrc, true, options);
3431 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3432}
3433
3434TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3435 TestCanInsertDtmf(false);
3436}
3437
3438TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3439 TestCanInsertDtmf(true);
3440}
3441
3442TEST_F(WebRtcSessionTest, InsertDtmf) {
3443 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003444 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003445 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003446 CreateAndSetRemoteOfferAndLocalAnswer();
3447 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3448 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3449
3450 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003451 const int expected_duration = 90;
3452 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3453 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3454 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3455
3456 // Verify
3457 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003458 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003460 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003461 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003462 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003463 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003464 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003465}
3466
deadbeefd59daf82015-10-14 15:02:44 -07003467// This test verifies the |initial_offerer| flag when session initiates the
3468// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003469TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003470 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003471 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003472 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003473 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3474 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003475 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003477 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003478}
3479
deadbeefd59daf82015-10-14 15:02:44 -07003480// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003481TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003482 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003483 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003484 SessionDescriptionInterface* offer = CreateRemoteOffer();
3485 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003486 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003487
deadbeefd59daf82015-10-14 15:02:44 -07003488 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003489 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003490 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003491}
3492
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003493// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3494TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003495 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003496 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003497 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003498 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003499 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003500 CreateRemoteAnswer(session_->local_description()));
3501
3502 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3503 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003504 JsepSessionDescription* modified_answer =
3505 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003506
3507 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3508 answer->session_id(),
3509 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003510 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003511
wu@webrtc.org4e393072014-04-07 17:04:35 +00003512 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003513 std::string sdp;
3514 EXPECT_TRUE(answer->ToString(&sdp));
3515 const std::string kAudioMid = "a=mid:audio";
3516 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003517 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003518 kAudioMidReplaceStr.c_str(),
3519 kAudioMidReplaceStr.length(),
3520 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003521 SessionDescriptionInterface* modified_answer1 =
3522 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003523 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003524
wu@webrtc.org4e393072014-04-07 17:04:35 +00003525 // Different media types.
3526 EXPECT_TRUE(answer->ToString(&sdp));
3527 const std::string kAudioMline = "m=audio";
3528 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003529 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003530 kAudioMlineReplaceStr.c_str(),
3531 kAudioMlineReplaceStr.length(),
3532 &sdp);
3533 SessionDescriptionInterface* modified_answer2 =
3534 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3535 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3536
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003537 SetRemoteDescriptionWithoutError(answer.release());
3538}
3539
3540// Verifying remote offer and local answer have matching m-lines as per
3541// RFC 3264.
3542TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003543 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003544 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003545 SessionDescriptionInterface* offer = CreateRemoteOffer();
3546 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003547 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003548
3549 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3550 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003551 JsepSessionDescription* modified_answer =
3552 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003553
3554 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3555 answer->session_id(),
3556 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003557 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003558 SetLocalDescriptionWithoutError(answer);
3559}
3560
3561// This test verifies that WebRtcSession does not start candidate allocation
3562// before SetLocalDescription is called.
3563TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003564 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003565 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003566 SessionDescriptionInterface* offer = CreateRemoteOffer();
3567 cricket::Candidate candidate;
3568 candidate.set_component(1);
3569 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3570 candidate);
3571 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3572 cricket::Candidate candidate1;
3573 candidate1.set_component(1);
3574 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3575 candidate1);
3576 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3577 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003578 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3579 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580
3581 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003582 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003583 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3584 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3585
wu@webrtc.org91053e72013-08-10 07:18:04 +00003586 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003587 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003588 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3589}
3590
3591// This test verifies that crypto parameter is updated in local session
3592// description as per security policy set in MediaSessionDescriptionFactory.
3593TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003594 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003595 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003596 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003597
3598 // Making sure SetLocalDescription correctly sets crypto value in
3599 // SessionDescription object after de-serialization of sdp string. The value
3600 // will be set as per MediaSessionDescriptionFactory.
3601 std::string offer_str;
3602 offer->ToString(&offer_str);
3603 SessionDescriptionInterface* jsep_offer_str =
3604 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3605 SetLocalDescriptionWithoutError(jsep_offer_str);
3606 EXPECT_TRUE(session_->voice_channel()->secure_required());
3607 EXPECT_TRUE(session_->video_channel()->secure_required());
3608}
3609
3610// This test verifies the crypto parameter when security is disabled.
3611TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003612 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003613 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003614 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003615 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003616
3617 // Making sure SetLocalDescription correctly sets crypto value in
3618 // SessionDescription object after de-serialization of sdp string. The value
3619 // will be set as per MediaSessionDescriptionFactory.
3620 std::string offer_str;
3621 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003622 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003623 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3624 SetLocalDescriptionWithoutError(jsep_offer_str);
3625 EXPECT_FALSE(session_->voice_channel()->secure_required());
3626 EXPECT_FALSE(session_->video_channel()->secure_required());
3627}
3628
3629// This test verifies that an answer contains new ufrag and password if an offer
3630// with new ufrag and password is received.
3631TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003632 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003633 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003634 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003635 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003636 CreateRemoteOffer(options));
3637 SetRemoteDescriptionWithoutError(offer.release());
3638
deadbeefab9b2d12015-10-14 11:33:11 -07003639 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003640 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003641 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003642 SetLocalDescriptionWithoutError(answer.release());
3643
3644 // Receive an offer with new ufrag and password.
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003645 options.audio_transport_options.ice_restart = true;
3646 options.video_transport_options.ice_restart = true;
3647 options.data_transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003648 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003649 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003650 SetRemoteDescriptionWithoutError(updated_offer1.release());
3651
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003652 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003653 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003654
3655 CompareIceUfragAndPassword(updated_answer1->description(),
3656 session_->local_description()->description(),
3657 false);
3658
3659 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003660}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003661
wu@webrtc.org91053e72013-08-10 07:18:04 +00003662// This test verifies that an answer contains old ufrag and password if an offer
3663// with old ufrag and password is received.
3664TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003665 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003666 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003667 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003668 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003669 CreateRemoteOffer(options));
3670 SetRemoteDescriptionWithoutError(offer.release());
3671
deadbeefab9b2d12015-10-14 11:33:11 -07003672 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003673 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003674 CreateAnswer(NULL));
3675 SetLocalDescriptionWithoutError(answer.release());
3676
3677 // Receive an offer without changed ufrag or password.
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003678 options.audio_transport_options.ice_restart = false;
3679 options.video_transport_options.ice_restart = false;
3680 options.data_transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003681 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003682 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003683 SetRemoteDescriptionWithoutError(updated_offer2.release());
3684
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003685 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003686 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003687
3688 CompareIceUfragAndPassword(updated_answer2->description(),
3689 session_->local_description()->description(),
3690 true);
3691
3692 SetLocalDescriptionWithoutError(updated_answer2.release());
3693}
3694
3695TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003696 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003697 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003698 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003699 const std::string session_id_orig = offer->session_id();
3700 const std::string session_version_orig = offer->session_version();
3701 SetLocalDescriptionWithoutError(offer);
3702
3703 video_channel_ = media_engine_->GetVideoChannel(0);
3704 video_channel_->set_fail_set_send_codecs(true);
3705
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003706 SessionDescriptionInterface* answer =
3707 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003708 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003709
3710 // Test that after a content error, setting any description will
3711 // result in an error.
3712 video_channel_->set_fail_set_send_codecs(false);
3713 answer = CreateRemoteAnswer(session_->local_description());
3714 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3715 offer = CreateRemoteOffer();
3716 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003717}
3718
3719// Runs the loopback call test with BUNDLE and STUN disabled.
3720TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3721 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003722 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003723 cricket::PORTALLOCATOR_DISABLE_STUN |
3724 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003725 TestLoopbackCall();
3726}
3727
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003728TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003729 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003730 cricket::PORTALLOCATOR_DISABLE_STUN |
3731 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3732 cricket::PORTALLOCATOR_DISABLE_RELAY);
3733
3734 // best connection is IPv6 since it has higher network preference.
3735 LoopbackNetworkConfiguration config;
3736 config.test_ipv6_network_ = true;
3737 config.best_connection_after_initial_ice_converged_ =
3738 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3739
3740 TestLoopbackCall(config);
3741}
3742
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003743// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003744TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003745 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3746 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003747 TestLoopbackCall();
3748}
3749
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003750TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3751 constraints_.reset(new FakeConstraints());
3752 constraints_->AddOptional(
3753 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003754 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003755
3756 SetLocalDescriptionWithDataChannel();
3757 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3758}
3759
Henrik Boström87713d02015-08-25 09:53:21 +02003760TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003761 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003762
3763 constraints_.reset(new FakeConstraints());
3764 constraints_->AddOptional(
3765 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003766 options_.disable_sctp_data_channels = false;
3767
Henrik Boström87713d02015-08-25 09:53:21 +02003768 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003769
3770 SetLocalDescriptionWithDataChannel();
3771 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3772}
3773
Henrik Boström87713d02015-08-25 09:53:21 +02003774TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003775 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003776
Henrik Boström87713d02015-08-25 09:53:21 +02003777 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003778
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003779 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003780 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003781 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3782}
3783
Henrik Boström87713d02015-08-25 09:53:21 +02003784TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003785 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003786 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003787 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003788
3789 // Create remote offer with SCTP.
3790 cricket::MediaSessionOptions options;
3791 options.data_channel_type = cricket::DCT_SCTP;
3792 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003793 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003794 SetRemoteDescriptionWithoutError(offer);
3795
3796 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003797 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003798 EXPECT_TRUE(answer != NULL);
3799 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3800 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003801}
3802
Henrik Boström87713d02015-08-25 09:53:21 +02003803TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003804 constraints_.reset(new FakeConstraints());
3805 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003806 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003807 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003808
3809 SetLocalDescriptionWithDataChannel();
3810 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3811}
3812
Henrik Boström87713d02015-08-25 09:53:21 +02003813TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003814 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003815
Henrik Boström87713d02015-08-25 09:53:21 +02003816 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003817
3818 SetLocalDescriptionWithDataChannel();
3819 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3820}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003821
Henrik Boström87713d02015-08-25 09:53:21 +02003822TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003823 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003824 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003825 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003826
3827 SetLocalDescriptionWithDataChannel();
3828 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3829}
3830
Henrik Boström87713d02015-08-25 09:53:21 +02003831TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003832 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003833 const int new_send_port = 9998;
3834 const int new_recv_port = 7775;
3835
Henrik Boström87713d02015-08-25 09:53:21 +02003836 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003837 SetFactoryDtlsSrtp();
3838
3839 // By default, don't actually add the codecs to desc_factory_; they don't
3840 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3841 // let the session description get parsed. That'll get the proper codecs
3842 // into the stream.
3843 cricket::MediaSessionOptions options;
3844 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3845 "stream1", new_send_port, options);
3846
3847 // SetRemoteDescription will take the ownership of the offer.
3848 SetRemoteDescriptionWithoutError(offer);
3849
3850 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3851 new_recv_port, CreateAnswer(NULL));
3852 ASSERT_TRUE(answer != NULL);
3853
3854 // Now set the local description, which'll take ownership of the answer.
3855 SetLocalDescriptionWithoutError(answer);
3856
3857 // TEST PLAN: Set the port number to something new, set it in the SDP,
3858 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003859 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003860 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003861
3862 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3863 int portnum = -1;
3864 ASSERT_TRUE(ch != NULL);
3865 ASSERT_EQ(1UL, ch->send_codecs().size());
3866 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003867 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003868 ch->send_codecs()[0].name.c_str()));
3869 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3870 &portnum));
3871 EXPECT_EQ(new_send_port, portnum);
3872
3873 ASSERT_EQ(1UL, ch->recv_codecs().size());
3874 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003875 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003876 ch->recv_codecs()[0].name.c_str()));
3877 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3878 &portnum));
3879 EXPECT_EQ(new_recv_port, portnum);
3880}
3881
deadbeefab9b2d12015-10-14 11:33:11 -07003882// Verifies that when a session's DataChannel receives an OPEN message,
3883// WebRtcSession signals the DataChannel creation request with the expected
3884// config.
3885TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3886 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3887
3888 InitWithDtls(GetParam());
3889
3890 SetLocalDescriptionWithDataChannel();
3891 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3892
3893 webrtc::DataChannelInit config;
3894 config.id = 1;
3895 rtc::Buffer payload;
3896 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3897 cricket::ReceiveDataParams params;
3898 params.ssrc = config.id;
3899 params.type = cricket::DMT_CONTROL;
3900
3901 cricket::DataChannel* data_channel = session_->data_channel();
3902 data_channel->SignalDataReceived(data_channel, params, payload);
3903
3904 EXPECT_EQ("a", last_data_channel_label_);
3905 EXPECT_EQ(config.id, last_data_channel_config_.id);
3906 EXPECT_FALSE(last_data_channel_config_.negotiated);
3907 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3908 last_data_channel_config_.open_handshake_role);
3909}
3910
3911TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003912 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3913 FakeDtlsIdentityStore::GenerateCertificate();
3914
3915 PeerConnectionInterface::RTCConfiguration configuration;
3916 configuration.certificates.push_back(certificate);
3917 Init(nullptr, configuration);
3918 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3919
3920 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3921}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003922
Henrik Boström87713d02015-08-25 09:53:21 +02003923// Verifies that CreateOffer succeeds when CreateOffer is called before async
3924// identity generation is finished (even if a certificate is provided this is
3925// an async op).
3926TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3927 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3928 InitWithDtls(GetParam());
3929
Henrik Boströmd8281982015-08-27 10:12:24 +02003930 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003931 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003932 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3933
wu@webrtc.org91053e72013-08-10 07:18:04 +00003934 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003935 VerifyNoCryptoParams(offer->description(), true);
3936 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003937}
3938
3939// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003940// identity generation is finished (even if a certificate is provided this is
3941// an async op).
3942TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003943 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003944 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003945 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003946
3947 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003948 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003949 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003950 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003951 ASSERT_TRUE(offer.get() != NULL);
3952 SetRemoteDescriptionWithoutError(offer.release());
3953
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003954 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003955 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003956 VerifyNoCryptoParams(answer->description(), true);
3957 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003958}
3959
3960// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003961// identity generation is finished (even if a certificate is provided this is
3962// an async op).
3963TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003964 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003965 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003966
Henrik Boströmd8281982015-08-27 10:12:24 +02003967 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003968
3969 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003970 EXPECT_TRUE(offer != NULL);
3971}
3972
3973// Verifies that CreateOffer fails when CreateOffer is called after async
3974// identity generation fails.
3975TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003976 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003977 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003978
Henrik Boströmd8281982015-08-27 10:12:24 +02003979 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003980
3981 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003982 EXPECT_TRUE(offer == NULL);
3983}
3984
3985// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3986// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003987TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003988 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003989 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07003990 VerifyMultipleAsyncCreateDescription(GetParam(),
3991 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003992}
3993
3994// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3995// before async identity generation fails.
3996TEST_F(WebRtcSessionTest,
3997 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003998 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003999 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4000 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004001}
4002
4003// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4004// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004005TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004006 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004007 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004008 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004009 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004010}
4011
4012// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4013// before async identity generation fails.
4014TEST_F(WebRtcSessionTest,
4015 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004016 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004017 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4018 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004019}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004020
4021// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4022// offer has no SDES crypto but only DTLS fingerprint.
4023TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4024 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004025 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004026 // Create a remote offer with secured transport disabled.
4027 cricket::MediaSessionOptions options;
4028 JsepSessionDescription* offer(CreateRemoteOffer(
4029 options, cricket::SEC_DISABLED));
4030 // Adds a DTLS fingerprint to the remote offer.
4031 cricket::SessionDescription* sdp = offer->description();
4032 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4033 ASSERT_TRUE(audio != NULL);
4034 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4035 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004036 rtc::SSLFingerprint::CreateFromRfc4572(
4037 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004038 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004039 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004040}
4041
wu@webrtc.orgde305012013-10-31 15:40:38 +00004042// This test verifies DSCP is properly applied on the media channels.
4043TEST_F(WebRtcSessionTest, TestDscpConstraint) {
4044 constraints_.reset(new FakeConstraints());
4045 constraints_->AddOptional(
4046 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004047 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004048 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004049 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00004050
4051 SetLocalDescriptionWithoutError(offer);
4052
4053 video_channel_ = media_engine_->GetVideoChannel(0);
4054 voice_channel_ = media_engine_->GetVoiceChannel(0);
4055
4056 ASSERT_TRUE(video_channel_ != NULL);
4057 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004058 const cricket::AudioOptions& audio_options = voice_channel_->options();
4059 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004060 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.dscp);
4061 EXPECT_EQ(rtc::Optional<bool>(true), video_options.dscp);
wu@webrtc.orgde305012013-10-31 15:40:38 +00004062}
4063
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004064TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
4065 constraints_.reset(new FakeConstraints());
4066 constraints_->AddOptional(
4067 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4068 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004069 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004070 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004071 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004072
4073 SetLocalDescriptionWithoutError(offer);
4074
4075 video_channel_ = media_engine_->GetVideoChannel(0);
4076
4077 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004078 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004079 EXPECT_EQ(rtc::Optional<bool>(true), video_options.suspend_below_min_bitrate);
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004080}
4081
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004082TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
4083 constraints_.reset(new FakeConstraints());
4084 constraints_->AddOptional(
4085 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
4086 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004087 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004088 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004089 SessionDescriptionInterface* offer = CreateOffer();
4090
4091 SetLocalDescriptionWithoutError(offer);
4092
4093 voice_channel_ = media_engine_->GetVoiceChannel(0);
4094
4095 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004096 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004097 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004098}
4099
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004100// Tests that we can renegotiate new media content with ICE candidates in the
4101// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004102TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004103 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004104 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004105 SetFactoryDtlsSrtp();
4106
deadbeefab9b2d12015-10-14 11:33:11 -07004107 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004108 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004109 SetLocalDescriptionWithoutError(offer);
4110
4111 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4112 SetRemoteDescriptionWithoutError(answer);
4113
4114 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004115 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004116 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4117
4118 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004119 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004120 candidate1.set_component(1);
4121 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4122 candidate1);
4123 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4124 SetRemoteDescriptionWithoutError(offer);
4125
4126 answer = CreateAnswer(NULL);
4127 SetLocalDescriptionWithoutError(answer);
4128}
4129
4130// Tests that we can renegotiate new media content with ICE candidates separated
4131// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004132TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004133 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004134 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004135 SetFactoryDtlsSrtp();
4136
deadbeefab9b2d12015-10-14 11:33:11 -07004137 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004138 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004139 SetLocalDescriptionWithoutError(offer);
4140
4141 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4142 SetRemoteDescriptionWithoutError(answer);
4143
4144 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004145 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004146 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4147 SetRemoteDescriptionWithoutError(offer);
4148
4149 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004150 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004151 candidate1.set_component(1);
4152 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4153 candidate1);
4154 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4155
4156 answer = CreateAnswer(NULL);
4157 SetLocalDescriptionWithoutError(answer);
4158}
honghaiz7f777492016-02-02 21:54:01 -08004159
4160// Flaky on Win and Mac only. See webrtc:4943
4161#if defined(WEBRTC_WIN) || defined(WEBRTC_MAC)
4162#define MAYBE_TestRtxRemovedByCreateAnswer DISABLED_TestRtxRemovedByCreateAnswer
4163#else
4164#define MAYBE_TestRtxRemovedByCreateAnswer TestRtxRemovedByCreateAnswer
4165#endif
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004166// Tests that RTX codec is removed from the answer when it isn't supported
4167// by local side.
honghaiz7f777492016-02-02 21:54:01 -08004168TEST_F(WebRtcSessionTest, MAYBE_TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004169 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004170 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004171 std::string offer_sdp(kSdpWithRtx);
4172
4173 SessionDescriptionInterface* offer =
4174 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4175 EXPECT_TRUE(offer->ToString(&offer_sdp));
4176
4177 // Offer SDP contains the RTX codec.
4178 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4179 SetRemoteDescriptionWithoutError(offer);
4180
4181 SessionDescriptionInterface* answer = CreateAnswer(NULL);
4182 std::string answer_sdp;
4183 answer->ToString(&answer_sdp);
4184 // Answer SDP removes the unsupported RTX codec.
4185 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4186 SetLocalDescriptionWithoutError(answer);
4187}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004188
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004189// This verifies that the voice channel after bundle has both options from video
4190// and voice channels.
4191TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4192 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004193 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004194
4195 PeerConnectionInterface::RTCOfferAnswerOptions options;
4196 options.use_rtp_mux = true;
4197
4198 SessionDescriptionInterface* offer = CreateOffer(options);
4199 SetLocalDescriptionWithoutError(offer);
4200
4201 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4202 rtc::Socket::Option::OPT_SNDBUF, 4000);
4203
4204 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4205 rtc::Socket::Option::OPT_RCVBUF, 8000);
4206
4207 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004208 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004209 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4210 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004211 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004212 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4213
deadbeefcbecd352015-09-23 11:50:27 -07004214 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004215 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4216 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004217 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004218 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4219
deadbeefcbecd352015-09-23 11:50:27 -07004220 EXPECT_NE(session_->voice_rtp_transport_channel(),
4221 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004222
deadbeefab9b2d12015-10-14 11:33:11 -07004223 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004224 SessionDescriptionInterface* answer =
4225 CreateRemoteAnswer(session_->local_description());
4226 SetRemoteDescriptionWithoutError(answer);
4227
deadbeefcbecd352015-09-23 11:50:27 -07004228 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004229 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4230 EXPECT_EQ(4000, option_val);
4231
deadbeefcbecd352015-09-23 11:50:27 -07004232 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004233 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4234 EXPECT_EQ(8000, option_val);
4235}
4236
tommi0f620f42015-07-09 03:25:02 -07004237// Test creating a session, request multiple offers, destroy the session
4238// and make sure we got success/failure callbacks for all of the requests.
4239// Background: crbug.com/507307
4240TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4241 Init();
4242
4243 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4244 PeerConnectionInterface::RTCOfferAnswerOptions options;
4245 options.offer_to_receive_audio =
4246 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004247 cricket::MediaSessionOptions session_options;
4248 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004249
4250 for (auto& o : observers) {
4251 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004252 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004253 }
4254
4255 session_.reset();
4256
tommi0f620f42015-07-09 03:25:02 -07004257 for (auto& o : observers) {
4258 // We expect to have received a notification now even if the session was
4259 // terminated. The offer creation may or may not have succeeded, but we
4260 // must have received a notification which, so the only invalid state
4261 // is kInit.
4262 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4263 }
4264}
4265
stefanc1aeaf02015-10-15 07:26:07 -07004266TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4267 TestPacketOptions();
4268}
4269
deadbeef057ecf02016-01-20 14:30:43 -08004270// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4271// is destroyed.
4272TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4273 Init();
4274 session_.reset();
4275 EXPECT_TRUE(session_destroyed_);
4276}
4277
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004278// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4279// currently fails because upon disconnection and reconnection OnIceComplete is
4280// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004281
deadbeefcbecd352015-09-23 11:50:27 -07004282INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4283 WebRtcSessionTest,
4284 testing::Values(ALREADY_GENERATED,
4285 DTLS_IDENTITY_STORE));