blob: 87481a87958ebd09d9f5aac39833d69eaa65c3e7 [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
jbauch555604a2016-04-26 03:13:22 -070011#include <memory>
kwiberg0eb15ed2015-12-17 03:04:15 -080012#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070013#include <vector>
14
Henrik Kjellander15583c12016-02-10 10:53:12 +010015#include "webrtc/api/audiotrack.h"
16#include "webrtc/api/fakemediacontroller.h"
17#include "webrtc/api/fakemetricsobserver.h"
18#include "webrtc/api/jsepicecandidate.h"
19#include "webrtc/api/jsepsessiondescription.h"
20#include "webrtc/api/peerconnection.h"
21#include "webrtc/api/sctputils.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010022#include "webrtc/api/test/fakedtlsidentitystore.h"
23#include "webrtc/api/videotrack.h"
24#include "webrtc/api/webrtcsession.h"
25#include "webrtc/api/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000026#include "webrtc/base/fakenetwork.h"
27#include "webrtc/base/firewallsocketserver.h"
28#include "webrtc/base/gunit.h"
29#include "webrtc/base/logging.h"
30#include "webrtc/base/network.h"
31#include "webrtc/base/physicalsocketserver.h"
32#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020033#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000034#include "webrtc/base/sslstreamadapter.h"
35#include "webrtc/base/stringutils.h"
36#include "webrtc/base/thread.h"
37#include "webrtc/base/virtualsocketserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080038#include "webrtc/media/base/fakemediaengine.h"
39#include "webrtc/media/base/fakevideorenderer.h"
40#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010041#include "webrtc/media/engine/fakewebrtccall.h"
kjellandera96e2d72016-02-04 23:52:28 -080042#include "webrtc/p2p/base/stunserver.h"
43#include "webrtc/p2p/base/teststunserver.h"
44#include "webrtc/p2p/base/testturnserver.h"
45#include "webrtc/p2p/base/transportchannel.h"
46#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010047#include "webrtc/pc/channelmanager.h"
48#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
50#define MAYBE_SKIP_TEST(feature) \
51 if (!(feature())) { \
52 LOG(LS_INFO) << "Feature disabled... skipping"; \
53 return; \
54 }
55
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000058using rtc::SocketAddress;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000059using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000061using webrtc::CreateSessionDescriptionObserver;
62using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070063using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020064using webrtc::DtlsIdentityStoreInterface;
jbauchac8869e2015-07-03 01:36:14 -070065using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070067using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068using webrtc::JsepIceCandidate;
69using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000070using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071using webrtc::PeerConnectionInterface;
72using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070073using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000075using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000076using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000077using webrtc::kCreateChannelFailed;
78using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000080using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000081using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000082using webrtc::kSdpWithoutDtlsFingerprint;
83using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000085using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000086using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000088typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
89
wu@webrtc.org364f2042013-11-20 21:49:41 +000090static const int kClientAddrPort = 0;
91static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000092static const char kClientIPv6AddrHost1[] =
93 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000094static const char kClientAddrHost2[] = "22.22.22.22";
95static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000096static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
97static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000098static const char kTurnUsername[] = "test";
99static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
101static const char kSessionVersion[] = "1";
102
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103// Media index of candidates belonging to the first media content.
104static const int kMediaContentIndex0 = 0;
105static const char kMediaContentName0[] = "audio";
106
107// Media index of candidates belonging to the second media content.
108static const int kMediaContentIndex1 = 1;
109static const char kMediaContentName1[] = "video";
110
111static const int kIceCandidatesTimeout = 10000;
112
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000113static const char kFakeDtlsFingerprint[] =
114 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
115 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
116
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000117static const char kTooLongIceUfragPwd[] =
118 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
119 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
120 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
121 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
122
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000123static const char kSdpWithRtx[] =
124 "v=0\r\n"
125 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
126 "s=-\r\n"
127 "t=0 0\r\n"
128 "a=msid-semantic: WMS stream1\r\n"
129 "m=video 9 RTP/SAVPF 0 96\r\n"
130 "c=IN IP4 0.0.0.0\r\n"
131 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
132 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
133 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
134 "a=mid:video\r\n"
135 "a=sendrecv\r\n"
136 "a=rtcp-mux\r\n"
137 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
138 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
139 "a=rtpmap:0 fake_video_codec/90000\r\n"
140 "a=rtpmap:96 rtx/90000\r\n"
141 "a=fmtp:96 apt=0\r\n";
142
deadbeefab9b2d12015-10-14 11:33:11 -0700143static const char kStream1[] = "stream1";
144static const char kVideoTrack1[] = "video1";
145static const char kAudioTrack1[] = "audio1";
146
147static const char kStream2[] = "stream2";
148static const char kVideoTrack2[] = "video2";
149static const char kAudioTrack2[] = "audio2";
150
Henrik Boström87713d02015-08-25 09:53:21 +0200151enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
152
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153class MockIceObserver : public webrtc::IceObserver {
154 public:
155 MockIceObserver()
156 : oncandidatesready_(false),
157 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
158 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
159 }
160
perkjdfb769d2016-02-09 03:09:43 -0800161 void OnIceConnectionChange(
162 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 ice_connection_state_ = new_state;
164 }
perkjdfb769d2016-02-09 03:09:43 -0800165 void OnIceGatheringChange(
166 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 // We can never transition back to "new".
168 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
169 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800170 oncandidatesready_ =
171 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 }
173
174 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800175 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000176 switch (candidate->sdp_mline_index()) {
177 case kMediaContentIndex0:
178 mline_0_candidates_.push_back(candidate->candidate());
179 break;
180 case kMediaContentIndex1:
181 mline_1_candidates_.push_back(candidate->candidate());
182 break;
183 default:
184 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000186
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 // The ICE gathering state should always be Gathering when a candidate is
188 // received (or possibly Completed in the case of the final candidate).
189 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
190 }
191
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700192 // Some local candidates are removed.
193 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700194 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700195 num_candidates_removed_ += candidates.size();
196 }
197
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 bool oncandidatesready_;
199 std::vector<cricket::Candidate> mline_0_candidates_;
200 std::vector<cricket::Candidate> mline_1_candidates_;
201 PeerConnectionInterface::IceConnectionState ice_connection_state_;
202 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700203 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204};
205
206class WebRtcSessionForTest : public webrtc::WebRtcSession {
207 public:
stefanc1aeaf02015-10-15 07:26:07 -0700208 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000209 rtc::Thread* signaling_thread,
210 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700212 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700213 : WebRtcSession(media_controller,
214 signaling_thread,
215 worker_thread,
216 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 RegisterIceObserver(ice_observer);
218 }
219 virtual ~WebRtcSessionForTest() {}
220
deadbeefcbecd352015-09-23 11:50:27 -0700221 // Note that these methods are only safe to use if the signaling thread
222 // is the same as the worker thread
223 cricket::TransportChannel* voice_rtp_transport_channel() {
224 return rtp_transport_channel(voice_channel());
225 }
226
227 cricket::TransportChannel* voice_rtcp_transport_channel() {
228 return rtcp_transport_channel(voice_channel());
229 }
230
231 cricket::TransportChannel* video_rtp_transport_channel() {
232 return rtp_transport_channel(video_channel());
233 }
234
235 cricket::TransportChannel* video_rtcp_transport_channel() {
236 return rtcp_transport_channel(video_channel());
237 }
238
239 cricket::TransportChannel* data_rtp_transport_channel() {
240 return rtp_transport_channel(data_channel());
241 }
242
243 cricket::TransportChannel* data_rtcp_transport_channel() {
244 return rtcp_transport_channel(data_channel());
245 }
246
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 using webrtc::WebRtcSession::SetAudioPlayout;
248 using webrtc::WebRtcSession::SetAudioSend;
nisse2ded9b12016-04-08 02:23:55 -0700249 using webrtc::WebRtcSession::SetSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 using webrtc::WebRtcSession::SetVideoPlayout;
251 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700252
253 private:
254 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
255 if (!ch) {
256 return nullptr;
257 }
258 return ch->transport_channel();
259 }
260
261 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
262 if (!ch) {
263 return nullptr;
264 }
265 return ch->rtcp_transport_channel();
266 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267};
268
wu@webrtc.org91053e72013-08-10 07:18:04 +0000269class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000270 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000272 enum State {
273 kInit,
274 kFailed,
275 kSucceeded,
276 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000277 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000278
279 // CreateSessionDescriptionObserver implementation.
280 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000281 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000282 state_ = kSucceeded;
283 }
284 virtual void OnFailure(const std::string& error) {
285 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286 }
287
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000288 SessionDescriptionInterface* description() { return description_.get(); }
289
290 SessionDescriptionInterface* ReleaseDescription() {
291 return description_.release();
292 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293
wu@webrtc.org91053e72013-08-10 07:18:04 +0000294 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295
wu@webrtc.org91053e72013-08-10 07:18:04 +0000296 protected:
297 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298
299 private:
kwibergd1fe2812016-04-27 06:47:29 -0700300 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000301 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302};
303
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800304class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000305 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800306 FakeAudioSource() : sink_(NULL) {}
307 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000308 if (sink_)
309 sink_->OnClose();
310 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000311
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000312 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000313
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800314 const cricket::AudioSource::Sink* sink() const { return sink_; }
315
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000316 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800317 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000318};
319
Henrik Boström87713d02015-08-25 09:53:21 +0200320class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700321 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
322 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323 protected:
324 // TODO Investigate why ChannelManager crashes, if it's created
325 // after stun_server.
326 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700327 : media_engine_(new cricket::FakeMediaEngine()),
328 data_engine_(new cricket::FakeDataEngine()),
329 channel_manager_(
330 new cricket::ChannelManager(media_engine_,
331 data_engine_,
stefanc1aeaf02015-10-15 07:26:07 -0700332 rtc::Thread::Current())),
333 fake_call_(webrtc::Call::Config()),
334 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800335 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
336 rtc::Thread::Current(),
stefanc1aeaf02015-10-15 07:26:07 -0700337 channel_manager_.get())),
338 tdesc_factory_(new cricket::TransportDescriptionFactory()),
339 desc_factory_(
340 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
341 tdesc_factory_.get())),
342 pss_(new rtc::PhysicalSocketServer),
343 vss_(new rtc::VirtualSocketServer(pss_.get())),
344 fss_(new rtc::FirewallSocketServer(vss_.get())),
345 ss_scope_(fss_.get()),
346 stun_socket_addr_(
347 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
348 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
349 stun_socket_addr_)),
350 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
351 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000352 cricket::ServerAddresses stun_servers;
353 stun_servers.insert(stun_socket_addr_);
354 allocator_.reset(new cricket::BasicPortAllocator(
355 &network_manager_,
356 stun_servers,
357 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000358 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700359 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 EXPECT_TRUE(channel_manager_->Init());
361 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000362 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 }
364
365 void AddInterface(const SocketAddress& addr) {
366 network_manager_.AddInterface(addr);
367 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700368 void RemoveInterface(const SocketAddress& addr) {
369 network_manager_.RemoveInterface(addr);
370 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371
Henrik Boström87713d02015-08-25 09:53:21 +0200372 // If |dtls_identity_store| != null or |rtc_configuration| contains
373 // |certificates| then DTLS will be enabled unless explicitly disabled by
374 // |rtc_configuration| options. When DTLS is enabled a certificate will be
375 // used if provided, otherwise one will be generated using the
376 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000377 void Init(
kwibergd1fe2812016-04-27 06:47:29 -0700378 std::unique_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 ASSERT_TRUE(session_.get() == NULL);
380 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700381 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700382 allocator_.get(), &observer_));
383 session_->SignalDataChannelOpenMessage.connect(
384 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800385 session_->GetOnDestroyedSignal()->connect(
386 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387
388 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
389 observer_.ice_connection_state_);
390 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
391 observer_.ice_gathering_state_);
392
htaa2a49d92016-03-04 02:51:39 -0800393 EXPECT_TRUE(session_->Initialize(options_, std::move(dtls_identity_store),
394 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700395 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000396 }
397
deadbeefab9b2d12015-10-14 11:33:11 -0700398 void OnDataChannelOpenMessage(const std::string& label,
399 const InternalDataChannelInit& config) {
400 last_data_channel_label_ = label;
401 last_data_channel_config_ = config;
402 }
403
deadbeef057ecf02016-01-20 14:30:43 -0800404 void OnSessionDestroyed() { session_destroyed_ = true; }
405
htaa2a49d92016-03-04 02:51:39 -0800406 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000407
408 void InitWithIceTransport(
409 PeerConnectionInterface::IceTransportsType ice_transport_type) {
htaa2a49d92016-03-04 02:51:39 -0800410 configuration_.type = ice_transport_type;
411 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000412 }
413
414 void InitWithBundlePolicy(
415 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800416 configuration_.bundle_policy = bundle_policy;
417 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700418 }
419
420 void InitWithRtcpMuxPolicy(
421 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
422 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800423 configuration_.rtcp_mux_policy = rtcp_mux_policy;
424 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000425 }
426
Henrik Boström87713d02015-08-25 09:53:21 +0200427 // Successfully init with DTLS; with a certificate generated and supplied or
428 // with a store that generates it for us.
429 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
kwibergd1fe2812016-04-27 06:47:29 -0700430 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store;
Henrik Boström87713d02015-08-25 09:53:21 +0200431 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800432 configuration_.certificates.push_back(
Henrik Boström87713d02015-08-25 09:53:21 +0200433 FakeDtlsIdentityStore::GenerateCertificate());
434 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
435 dtls_identity_store.reset(new FakeDtlsIdentityStore());
436 dtls_identity_store->set_should_fail(false);
437 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700438 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200439 }
htaa2a49d92016-03-04 02:51:39 -0800440 Init(std::move(dtls_identity_store));
Henrik Boström87713d02015-08-25 09:53:21 +0200441 }
442
443 // Init with DTLS with a store that will fail to generate a certificate.
444 void InitWithDtlsIdentityGenFail() {
kwibergd1fe2812016-04-27 06:47:29 -0700445 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store(
Henrik Boström5e56c592015-08-11 10:33:13 +0200446 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200447 dtls_identity_store->set_should_fail(true);
htaa2a49d92016-03-04 02:51:39 -0800448 Init(std::move(dtls_identity_store));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000449 }
450
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451 void InitWithDtmfCodec() {
452 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700453 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
454 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455 std::vector<cricket::AudioCodec> codecs;
456 codecs.push_back(kTelephoneEventCodec);
457 media_engine_->SetAudioCodecs(codecs);
458 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000459 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460 }
461
deadbeefab9b2d12015-10-14 11:33:11 -0700462 void SendAudioVideoStream1() {
463 send_stream_1_ = true;
464 send_stream_2_ = false;
465 send_audio_ = true;
466 send_video_ = true;
467 }
468
469 void SendAudioVideoStream2() {
470 send_stream_1_ = false;
471 send_stream_2_ = true;
472 send_audio_ = true;
473 send_video_ = true;
474 }
475
476 void SendAudioVideoStream1And2() {
477 send_stream_1_ = true;
478 send_stream_2_ = true;
479 send_audio_ = true;
480 send_video_ = true;
481 }
482
483 void SendNothing() {
484 send_stream_1_ = false;
485 send_stream_2_ = false;
486 send_audio_ = false;
487 send_video_ = false;
488 }
489
490 void SendAudioOnlyStream2() {
491 send_stream_1_ = false;
492 send_stream_2_ = true;
493 send_audio_ = true;
494 send_video_ = false;
495 }
496
497 void SendVideoOnlyStream2() {
498 send_stream_1_ = false;
499 send_stream_2_ = true;
500 send_audio_ = false;
501 send_video_ = true;
502 }
503
504 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
505 if (send_stream_1_ && send_audio_) {
506 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
507 kStream1);
508 }
509 if (send_stream_1_ && send_video_) {
510 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
511 kStream1);
512 }
513 if (send_stream_2_ && send_audio_) {
514 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
515 kStream2);
516 }
517 if (send_stream_2_ && send_video_) {
518 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
519 kStream2);
520 }
521 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
522 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
523 data_channel_->label(),
524 data_channel_->label());
525 }
526 }
527
528 void GetOptionsForOffer(
529 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
530 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800531 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700532
deadbeefc80741f2015-10-22 13:14:45 -0700533 AddStreamsToOptions(session_options);
534 if (rtc_options.offer_to_receive_audio ==
535 RTCOfferAnswerOptions::kUndefined) {
536 session_options->recv_audio =
537 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
538 }
539 if (rtc_options.offer_to_receive_video ==
540 RTCOfferAnswerOptions::kUndefined) {
541 session_options->recv_video =
542 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
543 }
544 session_options->bundle_enabled =
545 session_options->bundle_enabled &&
546 (session_options->has_audio() || session_options->has_video() ||
547 session_options->has_data());
548
deadbeefab9b2d12015-10-14 11:33:11 -0700549 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
550 session_options->data_channel_type = cricket::DCT_SCTP;
551 }
552 }
553
htaa2a49d92016-03-04 02:51:39 -0800554 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
555 // ParseConstraintsForAnswer is used to set some defaults.
556 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700557
deadbeefc80741f2015-10-22 13:14:45 -0700558 AddStreamsToOptions(session_options);
559 session_options->bundle_enabled =
560 session_options->bundle_enabled &&
561 (session_options->has_audio() || session_options->has_video() ||
562 session_options->has_data());
563
deadbeefab9b2d12015-10-14 11:33:11 -0700564 if (session_->data_channel_type() == cricket::DCT_SCTP) {
565 session_options->data_channel_type = cricket::DCT_SCTP;
566 }
567 }
568
569 // Creates a local offer and applies it. Starts ICE.
570 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 // to decide which streams to create.
572 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000573 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000574 SetLocalDescriptionWithoutError(offer);
575 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
576 observer_.ice_gathering_state_,
577 kIceCandidatesTimeout);
578 }
579
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000580 SessionDescriptionInterface* CreateOffer() {
581 PeerConnectionInterface::RTCOfferAnswerOptions options;
582 options.offer_to_receive_audio =
583 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
584
585 return CreateOffer(options);
586 }
587
wu@webrtc.org91053e72013-08-10 07:18:04 +0000588 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800589 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000590 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000591 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700592 cricket::MediaSessionOptions session_options;
593 GetOptionsForOffer(options, &session_options);
594 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000595 EXPECT_TRUE_WAIT(
596 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000597 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000598 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000599 }
600
601 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800602 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000603 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000604 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800605 cricket::MediaSessionOptions session_options = options;
606 GetOptionsForAnswer(&session_options);
607 // Overwrite recv_audio and recv_video with passed-in values.
608 session_options.recv_video = options.recv_video;
609 session_options.recv_audio = options.recv_audio;
610 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000611 EXPECT_TRUE_WAIT(
612 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000613 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000614 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000615 }
616
htaa2a49d92016-03-04 02:51:39 -0800617 SessionDescriptionInterface* CreateAnswer() {
618 cricket::MediaSessionOptions options;
619 options.recv_video = true;
620 options.recv_audio = true;
621 return CreateAnswer(options);
622 }
623
wu@webrtc.org364f2042013-11-20 21:49:41 +0000624 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000625 return (session_->voice_channel() != NULL &&
626 session_->video_channel() != NULL);
627 }
628
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000629 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
630 ASSERT_TRUE(session_.get() != NULL);
631 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
632 ASSERT_TRUE(content != NULL);
633 const cricket::AudioContentDescription* audio_content =
634 static_cast<const cricket::AudioContentDescription*>(
635 content->description);
636 ASSERT_TRUE(audio_content != NULL);
637 ASSERT_EQ(1U, audio_content->cryptos().size());
638 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
639 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
640 audio_content->cryptos()[0].cipher_suite);
641 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
642 audio_content->protocol());
643
644 content = cricket::GetFirstVideoContent(sdp);
645 ASSERT_TRUE(content != NULL);
646 const cricket::VideoContentDescription* video_content =
647 static_cast<const cricket::VideoContentDescription*>(
648 content->description);
649 ASSERT_TRUE(video_content != NULL);
650 ASSERT_EQ(1U, video_content->cryptos().size());
651 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
652 video_content->cryptos()[0].cipher_suite);
653 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
654 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
655 video_content->protocol());
656 }
657
658 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
659 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
660 ASSERT_TRUE(content != NULL);
661 const cricket::AudioContentDescription* audio_content =
662 static_cast<const cricket::AudioContentDescription*>(
663 content->description);
664 ASSERT_TRUE(audio_content != NULL);
665 ASSERT_EQ(0U, audio_content->cryptos().size());
666
667 content = cricket::GetFirstVideoContent(sdp);
668 ASSERT_TRUE(content != NULL);
669 const cricket::VideoContentDescription* video_content =
670 static_cast<const cricket::VideoContentDescription*>(
671 content->description);
672 ASSERT_TRUE(video_content != NULL);
673 ASSERT_EQ(0U, video_content->cryptos().size());
674
675 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700676 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000677 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700678 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679 video_content->protocol());
680 } else {
681 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
682 audio_content->protocol());
683 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
684 video_content->protocol());
685 }
686 }
687
688 // Set the internal fake description factories to do DTLS-SRTP.
689 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000690 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000692 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200693 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800694 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700695 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800696 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
698 }
699
700 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
701 bool expected) {
702 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
703 ASSERT_TRUE(audio != NULL);
704 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 const TransportInfo* video = sdp->GetTransportInfoByName("video");
706 ASSERT_TRUE(video != NULL);
707 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 }
709
710 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000711 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000713 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000714 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000716 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000718 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
719 offer);
htaa2a49d92016-03-04 02:51:39 -0800720 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 // Answer should be NULL as no crypto params in offer.
722 ASSERT_TRUE(answer == NULL);
723 }
724
725 void VerifyAnswerFromCryptoOffer() {
726 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000727 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700729 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
731 ASSERT_TRUE(offer.get() != NULL);
732 VerifyCryptoParams(offer->description());
733 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700734 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735 ASSERT_TRUE(answer.get() != NULL);
736 VerifyCryptoParams(answer->description());
737 }
738
deadbeef0ed85b22016-02-23 17:24:52 -0800739 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
740 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800742 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 }
744
745 const cricket::ContentInfos& contents = desc1->contents();
746 cricket::ContentInfos::const_iterator it = contents.begin();
747
748 for (; it != contents.end(); ++it) {
749 const cricket::TransportDescription* transport_desc1 =
750 desc1->GetTransportDescriptionByName(it->name);
751 const cricket::TransportDescription* transport_desc2 =
752 desc2->GetTransportDescriptionByName(it->name);
753 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800754 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755 }
756 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
757 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800758 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 }
760 }
deadbeef0ed85b22016-02-23 17:24:52 -0800761 return true;
762 }
763
764 // Compares ufrag/password only for the specified |media_type|.
765 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
766 const cricket::SessionDescription* desc2,
767 cricket::MediaType media_type) {
768 if (desc1->contents().size() != desc2->contents().size()) {
769 return false;
770 }
771
772 const cricket::ContentInfo* cinfo =
773 cricket::GetFirstMediaContent(desc1->contents(), media_type);
774 const cricket::TransportDescription* transport_desc1 =
775 desc1->GetTransportDescriptionByName(cinfo->name);
776 const cricket::TransportDescription* transport_desc2 =
777 desc2->GetTransportDescriptionByName(cinfo->name);
778 if (!transport_desc1 || !transport_desc2) {
779 return false;
780 }
781 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
782 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
783 return false;
784 }
785 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000787
788 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
789 std::string *sdp) {
790 const cricket::SessionDescription* desc = current_desc->description();
791 EXPECT_TRUE(current_desc->ToString(sdp));
792
793 const cricket::ContentInfos& contents = desc->contents();
794 cricket::ContentInfos::const_iterator it = contents.begin();
795 // Replace ufrag and pwd lines with empty strings.
796 for (; it != contents.end(); ++it) {
797 const cricket::TransportDescription* transport_desc =
798 desc->GetTransportDescriptionByName(it->name);
799 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
800 + "\r\n";
801 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
802 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000803 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000804 "", 0,
805 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000806 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000807 "", 0,
808 sdp);
809 }
810 }
811
deadbeef0ed85b22016-02-23 17:24:52 -0800812 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
813 const std::string& ufrag,
814 const std::string& pwd) {
815 cricket::SessionDescription* desc = current_desc->description();
816 for (TransportInfo& transport_info : desc->transport_infos()) {
817 cricket::TransportDescription& transport_desc =
818 transport_info.description;
819 transport_desc.ice_ufrag = ufrag;
820 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000821 }
822 }
823
deadbeef0ed85b22016-02-23 17:24:52 -0800824 // Sets ufrag/pwd for specified |media_type|.
825 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
826 cricket::MediaType media_type,
827 const std::string& ufrag,
828 const std::string& pwd) {
829 cricket::SessionDescription* desc = current_desc->description();
830 const cricket::ContentInfo* cinfo =
831 cricket::GetFirstMediaContent(desc->contents(), media_type);
832 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
833 cricket::TransportDescription* transport_desc =
834 &transport_info->description;
835 transport_desc->ice_ufrag = ufrag;
836 transport_desc->ice_pwd = pwd;
837 }
838
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 // Creates a remote offer and and applies it as a remote description,
840 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700841 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 // to decide which local and remote streams to create.
843 void CreateAndSetRemoteOfferAndLocalAnswer() {
844 SessionDescriptionInterface* offer = CreateRemoteOffer();
845 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800846 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 SetLocalDescriptionWithoutError(answer);
848 }
849 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
850 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700851 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 }
853 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700854 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 SetLocalDescriptionWithoutError(desc);
856 EXPECT_EQ(expected_state, session_->state());
857 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000858 void SetLocalDescriptionExpectError(const std::string& action,
859 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 SessionDescriptionInterface* desc) {
861 std::string error;
862 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000863 std::string sdp_type = "local ";
864 sdp_type.append(action);
865 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 EXPECT_NE(std::string::npos, error.find(expected_error));
867 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000868 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
869 SessionDescriptionInterface* desc) {
870 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
871 expected_error, desc);
872 }
873 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
874 SessionDescriptionInterface* desc) {
875 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
876 expected_error, desc);
877 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
879 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
880 }
881 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700882 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 SetRemoteDescriptionWithoutError(desc);
884 EXPECT_EQ(expected_state, session_->state());
885 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000886 void SetRemoteDescriptionExpectError(const std::string& action,
887 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 SessionDescriptionInterface* desc) {
889 std::string error;
890 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000891 std::string sdp_type = "remote ";
892 sdp_type.append(action);
893 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 EXPECT_NE(std::string::npos, error.find(expected_error));
895 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000896 void SetRemoteDescriptionOfferExpectError(
897 const std::string& expected_error, SessionDescriptionInterface* desc) {
898 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
899 expected_error, desc);
900 }
901 void SetRemoteDescriptionPranswerExpectError(
902 const std::string& expected_error, SessionDescriptionInterface* desc) {
903 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
904 expected_error, desc);
905 }
906 void SetRemoteDescriptionAnswerExpectError(
907 const std::string& expected_error, SessionDescriptionInterface* desc) {
908 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
909 expected_error, desc);
910 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911
912 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
913 SessionDescriptionInterface** nocrypto_answer) {
914 // Create a SDP without Crypto.
915 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000916 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 options.bundle_enabled = true;
918 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
919 ASSERT_TRUE(*offer != NULL);
920 VerifyCryptoParams((*offer)->description());
921
922 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
923 cricket::SEC_DISABLED);
924 EXPECT_TRUE(*nocrypto_answer != NULL);
925 }
926
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000927 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
928 SessionDescriptionInterface** nodtls_answer) {
929 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000930 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000931 options.bundle_enabled = true;
932
kwibergd1fe2812016-04-27 06:47:29 -0700933 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000934 CreateRemoteOffer(options, cricket::SEC_ENABLED));
935
936 *nodtls_answer =
937 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
938 EXPECT_TRUE(*nodtls_answer != NULL);
939 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
940 VerifyCryptoParams((*nodtls_answer)->description());
941
942 SetFactoryDtlsSrtp();
943 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
944 ASSERT_TRUE(*offer != NULL);
945 VerifyFingerprintStatus((*offer)->description(), true);
946 VerifyCryptoParams((*offer)->description());
947 }
948
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 JsepSessionDescription* CreateRemoteOfferWithVersion(
950 cricket::MediaSessionOptions options,
951 cricket::SecurePolicy secure_policy,
952 const std::string& session_version,
953 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000954 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 const cricket::SessionDescription* cricket_desc = NULL;
956 if (current_desc) {
957 cricket_desc = current_desc->description();
958 session_id = current_desc->session_id();
959 }
960
961 desc_factory_->set_secure(secure_policy);
962 JsepSessionDescription* offer(
963 new JsepSessionDescription(JsepSessionDescription::kOffer));
964 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
965 session_id, session_version)) {
966 delete offer;
967 offer = NULL;
968 }
969 return offer;
970 }
971 JsepSessionDescription* CreateRemoteOffer(
972 cricket::MediaSessionOptions options) {
973 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
974 kSessionVersion, NULL);
975 }
976 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000977 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
978 return CreateRemoteOfferWithVersion(
979 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 }
981 JsepSessionDescription* CreateRemoteOffer(
982 cricket::MediaSessionOptions options,
983 const SessionDescriptionInterface* current_desc) {
984 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
985 kSessionVersion, current_desc);
986 }
987
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000988 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
989 const char* sctp_stream_name, int new_port,
990 cricket::MediaSessionOptions options) {
991 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000992 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
993 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000994 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
995 }
996
997 // Takes ownership of offer_basis (and deletes it).
998 JsepSessionDescription* ChangeSDPSctpPort(
999 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1000 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1001 // SessionDescription from the mutated string.
1002 const char* default_port_str = "5000";
1003 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001004 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001005 std::string offer_str;
1006 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001007 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001008 new_port_str, strlen(new_port_str),
1009 &offer_str);
1010 JsepSessionDescription* offer = new JsepSessionDescription(
1011 offer_basis->type());
1012 delete offer_basis;
1013 offer->Initialize(offer_str, NULL);
1014 return offer;
1015 }
1016
deadbeefab9b2d12015-10-14 11:33:11 -07001017 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018 // before this function to decide which streams to create.
1019 JsepSessionDescription* CreateRemoteOffer() {
1020 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001021 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 return CreateRemoteOffer(options, session_->remote_description());
1023 }
1024
1025 JsepSessionDescription* CreateRemoteAnswer(
1026 const SessionDescriptionInterface* offer,
1027 cricket::MediaSessionOptions options,
1028 cricket::SecurePolicy policy) {
1029 desc_factory_->set_secure(policy);
1030 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001031 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 JsepSessionDescription* answer(
1033 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1034 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1035 options, NULL),
1036 session_id, kSessionVersion)) {
1037 delete answer;
1038 answer = NULL;
1039 }
1040 return answer;
1041 }
1042
1043 JsepSessionDescription* CreateRemoteAnswer(
1044 const SessionDescriptionInterface* offer,
1045 cricket::MediaSessionOptions options) {
1046 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1047 }
1048
deadbeefab9b2d12015-10-14 11:33:11 -07001049 // Creates an answer session description.
1050 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001051 // to decide which streams to create.
1052 JsepSessionDescription* CreateRemoteAnswer(
1053 const SessionDescriptionInterface* offer) {
1054 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001055 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1057 }
1058
1059 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001060 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001061 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001062 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001063
1064 PeerConnectionInterface::RTCOfferAnswerOptions options;
1065 options.use_rtp_mux = bundle;
1066
1067 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1069 // and answer.
1070 SetLocalDescriptionWithoutError(offer);
1071
kwibergd1fe2812016-04-27 06:47:29 -07001072 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001073 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 std::string sdp;
1075 EXPECT_TRUE(answer->ToString(&sdp));
1076
1077 size_t expected_candidate_num = 2;
1078 if (!rtcp_mux) {
1079 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1080 // for rtp and rtcp.
1081 expected_candidate_num = 4;
1082 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 const std::string kRtcpMux = "a=rtcp-mux";
1084 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001085 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001086 kXRtcpMux.c_str(), kXRtcpMux.length(),
1087 &sdp);
1088 }
1089
1090 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1091 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001092
1093 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001094 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001095 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1096 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001097 if (bundle) {
1098 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1099 } else {
1100 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 }
1102 }
1103 // Tests that we can only send DTMF when the dtmf codec is supported.
1104 void TestCanInsertDtmf(bool can) {
1105 if (can) {
1106 InitWithDtmfCodec();
1107 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001108 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001109 }
deadbeefab9b2d12015-10-14 11:33:11 -07001110 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 CreateAndSetRemoteOfferAndLocalAnswer();
1112 EXPECT_FALSE(session_->CanInsertDtmf(""));
1113 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1114 }
1115
zhihuang3a334652016-05-05 18:37:49 -07001116 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1117 const std::string& codec_name) {
1118 for (const auto& content : desc->description()->contents()) {
1119 if (static_cast<cricket::MediaContentDescription*>(content.description)
1120 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1121 const auto* mdesc =
1122 static_cast<cricket::VideoContentDescription*>(content.description);
1123 for (const auto& codec : mdesc->codecs()) {
1124 if (codec.name == codec_name) {
1125 return true;
1126 }
1127 }
1128 }
1129 }
1130 return false;
1131 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001132 // Helper class to configure loopback network and verify Best
1133 // Connection using right IP protocol for TestLoopbackCall
1134 // method. LoopbackNetworkManager applies firewall rules to block
1135 // all ping traffic once ICE completed, and remove them to observe
1136 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1137 // verifies the best connection is using the right IP protocol after
1138 // initial ICE convergences.
1139
1140 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001141 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001142 LoopbackNetworkConfiguration()
1143 : test_ipv6_network_(false),
1144 test_extra_ipv4_network_(false),
1145 best_connection_after_initial_ice_converged_(1, 0) {}
1146
1147 // Used to track the expected best connection count in each IP protocol.
1148 struct ExpectedBestConnection {
1149 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1150 : ipv4_count_(ipv4_count),
1151 ipv6_count_(ipv6_count) {}
1152
1153 int ipv4_count_;
1154 int ipv6_count_;
1155 };
1156
1157 bool test_ipv6_network_;
1158 bool test_extra_ipv4_network_;
1159 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1160
1161 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001162 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001163 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1164 }
1165
1166 private:
jbauchac8869e2015-07-03 01:36:14 -07001167 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001168 const ExpectedBestConnection& expected) const {
1169 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001170 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1171 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001172 expected.ipv4_count_);
1173 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001174 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1175 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001176 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001177 // This is used in the loopback call so there is only single host to host
1178 // candidate pair.
1179 EXPECT_EQ(metrics_observer->GetEnumCounter(
1180 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1181 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001182 0);
1183 EXPECT_EQ(metrics_observer->GetEnumCounter(
1184 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1185 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001186 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001187 }
1188 };
1189
1190 class LoopbackNetworkManager {
1191 public:
1192 LoopbackNetworkManager(WebRtcSessionTest* session,
1193 const LoopbackNetworkConfiguration& config)
1194 : config_(config) {
1195 session->AddInterface(
1196 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1197 if (config_.test_extra_ipv4_network_) {
1198 session->AddInterface(
1199 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1200 }
1201 if (config_.test_ipv6_network_) {
1202 session->AddInterface(
1203 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1204 }
1205 }
1206
1207 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1208 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1209 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1210 if (config_.test_extra_ipv4_network_) {
1211 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1212 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1213 }
1214 if (config_.test_ipv6_network_) {
1215 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1216 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1217 }
1218 }
1219
1220 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1221
1222 private:
1223 LoopbackNetworkConfiguration config_;
1224 };
1225
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001226 // The method sets up a call from the session to itself, in a loopback
1227 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001228 // disconnection, and then a permanent disconnection.
1229 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001230 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1231 // While running the call, this method also checks if the session goes through
1232 // the correct sequence of ICE states when a connection is established,
1233 // broken, and re-established.
1234 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001235 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1236 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001237 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001238
stefanc1aeaf02015-10-15 07:26:07 -07001239 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001240 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001241 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001242 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001243
1244 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1245 observer_.ice_gathering_state_);
1246 SetLocalDescriptionWithoutError(offer);
1247 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1248 observer_.ice_connection_state_);
1249 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001250 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1252 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001253 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001254
1255 std::string sdp;
1256 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001257 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1258 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001259 ASSERT_TRUE(desc != NULL);
1260 SetRemoteDescriptionWithoutError(desc);
1261
1262 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001263 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001264
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001265 // The ice connection state is "Connected" too briefly to catch in a test.
1266 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001267 observer_.ice_connection_state_, kIceCandidatesTimeout);
1268 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001269
stefanc1aeaf02015-10-15 07:26:07 -07001270 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1271 LoopbackNetworkManager loopback_network_manager(this, config);
1272 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001273 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001274 // Adding firewall rule to block ping requests, which should cause
1275 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001276
1277 loopback_network_manager.ApplyFirewallRules(fss_.get());
1278
1279 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1281 observer_.ice_connection_state_,
1282 kIceCandidatesTimeout);
1283
jbauchac8869e2015-07-03 01:36:14 -07001284 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001285
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001286 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001287 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001289 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001290 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291 observer_.ice_connection_state_,
1292 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001293
1294 // Now we block ping requests and wait until the ICE connection transitions
1295 // to the Failed state. This will take at least 30 seconds because it must
1296 // wait for the Port to timeout.
1297 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001298
1299 loopback_network_manager.ApplyFirewallRules(fss_.get());
1300 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001301 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001302 observer_.ice_connection_state_,
1303 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304 }
1305
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001306 void TestLoopbackCall() {
1307 LoopbackNetworkConfiguration config;
1308 TestLoopbackCall(config);
1309 }
1310
stefanc1aeaf02015-10-15 07:26:07 -07001311 void TestPacketOptions() {
1312 media_controller_.reset(
1313 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1314 LoopbackNetworkConfiguration config;
1315 LoopbackNetworkManager loopback_network_manager(this, config);
1316
1317 SetupLoopbackCall();
1318
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001319 // Wait for channel to be ready for sending.
1320 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001321 uint8_t test_packet[15] = {0};
1322 rtc::PacketOptions options;
1323 options.packet_id = 10;
1324 media_engine_->GetVideoChannel(0)
1325 ->SendRtp(test_packet, sizeof(test_packet), options);
1326
1327 const int kPacketTimeout = 2000;
1328 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1329 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1330 }
1331
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001332 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1333 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001334 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1335 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001336
1337 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1339 codecs.push_back(kCNCodec1);
1340 codecs.push_back(kCNCodec2);
1341 media_engine_->SetAudioCodecs(codecs);
1342 desc_factory_->set_audio_codecs(codecs);
1343 }
1344
1345 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1346 const cricket::ContentDescription* description = content->description;
1347 ASSERT(description != NULL);
1348 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001349 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350 ASSERT(audio_content_desc != NULL);
1351 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1352 if (audio_content_desc->codecs()[i].name == "CN")
1353 return false;
1354 }
1355 return true;
1356 }
1357
deadbeefab9b2d12015-10-14 11:33:11 -07001358 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001359 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001360 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001361 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1362 data_channel_ = DataChannel::Create(
1363 session_.get(), session_->data_channel_type(), "datachannel", dci);
1364 }
1365
1366 void SetLocalDescriptionWithDataChannel() {
1367 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001368 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001369 SetLocalDescriptionWithoutError(offer);
1370 }
1371
wu@webrtc.org91053e72013-08-10 07:18:04 +00001372 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001373 RTCCertificateGenerationMethod cert_gen_method,
1374 CreateSessionDescriptionRequest::Type type) {
1375 InitWithDtls(cert_gen_method);
1376 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1377 }
1378
1379 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1380 CreateSessionDescriptionRequest::Type type) {
1381 InitWithDtlsIdentityGenFail();
1382 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1383 }
1384
1385 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001386 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001387 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001388 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001389 if (type == CreateSessionDescriptionRequest::kAnswer) {
1390 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001391 std::unique_ptr<JsepSessionDescription> offer(
1392 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001393 ASSERT_TRUE(offer.get() != NULL);
1394 SetRemoteDescriptionWithoutError(offer.release());
1395 }
1396
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001397 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001398 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001399 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001400 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001401 observers[kNumber];
1402 for (int i = 0; i < kNumber; ++i) {
1403 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1404 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001405 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001406 } else {
htaa2a49d92016-03-04 02:51:39 -08001407 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001408 }
1409 }
1410
1411 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1412 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1413 WebRtcSessionCreateSDPObserverForTest::kFailed;
1414
1415 for (int i = 0; i < kNumber; ++i) {
1416 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1417 if (success) {
1418 EXPECT_TRUE(observers[i]->description() != NULL);
1419 } else {
1420 EXPECT_TRUE(observers[i]->description() == NULL);
1421 }
1422 }
1423 }
1424
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001425 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001426 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001427 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001428 turn_server.credentials = credentials;
1429 turn_server.ports.push_back(
1430 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1431 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001432 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001433 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001434 }
1435
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001436 cricket::FakeMediaEngine* media_engine_;
1437 cricket::FakeDataEngine* data_engine_;
kwibergd1fe2812016-04-27 06:47:29 -07001438 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001439 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001440 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1441 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1442 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1443 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1444 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1445 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001446 rtc::SocketServerScope ss_scope_;
1447 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001448 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001449 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001450 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001451 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001452 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001453 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001454 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 MockIceObserver observer_;
1456 cricket::FakeVideoMediaChannel* video_channel_;
1457 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001458 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001459 // The following flags affect options created for CreateOffer/CreateAnswer.
1460 bool send_stream_1_ = false;
1461 bool send_stream_2_ = false;
1462 bool send_audio_ = false;
1463 bool send_video_ = false;
1464 rtc::scoped_refptr<DataChannel> data_channel_;
1465 // Last values received from data channel creation signal.
1466 std::string last_data_channel_label_;
1467 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001468 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469};
1470
Henrik Boström87713d02015-08-25 09:53:21 +02001471TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1472 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001473 // SDES is disabled when DTLS is on.
1474 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475}
1476
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001477TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001478 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001479 // SDES is required if DTLS is off.
1480 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001481}
1482
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1484 TestSessionCandidatesWithBundleRtcpMux(false, false);
1485}
1486
1487// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1488// with rtcp-mux and/or bundle.
1489TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1490 TestSessionCandidatesWithBundleRtcpMux(false, true);
1491}
1492
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001493TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1494 TestSessionCandidatesWithBundleRtcpMux(true, true);
1495}
1496
1497TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001498 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1499 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001500 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001501 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001502 InitiateCall();
1503 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1504 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1505 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1506}
1507
minyuec8930ba2016-01-22 06:17:46 -08001508// Crashes on Win only. See webrtc:5411.
1509#if defined(WEBRTC_WIN)
1510#define MAYBE_TestStunError DISABLED_TestStunError
1511#else
1512#define MAYBE_TestStunError TestStunError
1513#endif
1514TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001515 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1516 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001517 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001518 rtc::FP_UDP,
1519 rtc::FD_ANY,
1520 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001521 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001522 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001524 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1526 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1527 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1528}
1529
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001530// Test session delivers no candidates gathered when constraint set to "none".
1531TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1532 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001533 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001534 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001535 InitiateCall();
1536 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1537 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1538 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1539}
1540
1541// Test session delivers only relay candidates gathered when constaint set to
1542// "relay".
1543TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1544 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1545 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001546 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001547 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001548 InitiateCall();
1549 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1550 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1551 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1552 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1553 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1554 observer_.mline_0_candidates_[i].type());
1555 }
1556 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1557 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1558 observer_.mline_1_candidates_[i].type());
1559 }
1560}
1561
1562// Test session delivers all candidates gathered when constaint set to "all".
1563TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1564 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001565 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001566 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001567 InitiateCall();
1568 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1569 // Host + STUN. By default allocator is disabled to gather relay candidates.
1570 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1571 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1572}
1573
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001574TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001575 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001576 SessionDescriptionInterface* offer = NULL;
1577 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1578 std::string unknown_action;
1579 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1580 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1581}
1582
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583// Test creating offers and receive answers and make sure the
1584// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001585TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001586 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001587 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001588 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 const std::string session_id_orig = offer->session_id();
1590 const std::string session_version_orig = offer->session_version();
1591 SetLocalDescriptionWithoutError(offer);
1592
deadbeefab9b2d12015-10-14 11:33:11 -07001593 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594 SessionDescriptionInterface* answer =
1595 CreateRemoteAnswer(session_->local_description());
1596 SetRemoteDescriptionWithoutError(answer);
1597
1598 video_channel_ = media_engine_->GetVideoChannel(0);
1599 voice_channel_ = media_engine_->GetVoiceChannel(0);
1600
1601 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1602 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1603
1604 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1605 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1606
1607 ASSERT_EQ(1u, video_channel_->send_streams().size());
1608 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1609 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1610 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1611
1612 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001613 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001614 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615
1616 // Verify the session id is the same and the session version is
1617 // increased.
1618 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001619 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1620 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621
1622 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001623 EXPECT_EQ(0u, video_channel_->send_streams().size());
1624 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625
deadbeefab9b2d12015-10-14 11:33:11 -07001626 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 answer = CreateRemoteAnswer(session_->local_description());
1628 SetRemoteDescriptionWithoutError(answer);
1629
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630 // Make sure the receive streams have not changed.
1631 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1632 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1633 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1634 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1635}
1636
1637// Test receiving offers and creating answers and make sure the
1638// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001639TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001640 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001641 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001642 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001643 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001644 SetRemoteDescriptionWithoutError(offer);
1645
deadbeefab9b2d12015-10-14 11:33:11 -07001646 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001647 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001648 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649 SetLocalDescriptionWithoutError(answer);
1650
1651 const std::string session_id_orig = answer->session_id();
1652 const std::string session_version_orig = answer->session_version();
1653
1654 video_channel_ = media_engine_->GetVideoChannel(0);
1655 voice_channel_ = media_engine_->GetVoiceChannel(0);
1656
htaa2a49d92016-03-04 02:51:39 -08001657 ASSERT_TRUE(video_channel_);
1658 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1660 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1661
1662 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1663 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1664
1665 ASSERT_EQ(1u, video_channel_->send_streams().size());
1666 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1667 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1668 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1669
deadbeefab9b2d12015-10-14 11:33:11 -07001670 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001671 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672 SetRemoteDescriptionWithoutError(offer);
1673
1674 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001675 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001676 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677
1678 // Verify the session id is the same and the session version is
1679 // increased.
1680 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001681 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1682 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001683 SetLocalDescriptionWithoutError(answer);
1684
1685 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1686 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1687 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1688 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1689 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1690 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1691
1692 // Make sure we have no send streams.
1693 EXPECT_EQ(0u, video_channel_->send_streams().size());
1694 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1695}
1696
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001697TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001698 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001699 media_engine_->set_fail_create_channel(true);
1700
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001701 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001702 ASSERT_TRUE(offer != NULL);
1703 // SetRemoteDescription and SetLocalDescription will take the ownership of
1704 // the offer.
1705 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001706 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001707 ASSERT_TRUE(offer != NULL);
1708 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1709}
1710
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001711//
1712// Tests for creating/setting SDP under different SDES/DTLS polices:
1713//
1714// --DTLS off and SDES on
1715// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1716// set local/remote offer/answer with crypto --> success
1717// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1718// failure
1719// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1720// failure
1721// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1722// failure
1723//
1724// --DTLS on and SDES off
1725// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1726// set local/remote offer/answer with DTLS fingerprint --> success
1727// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1728// fingerprint --> failure
1729// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1730// --> failure
1731// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1732// --> failure
1733//
1734// --Encryption disabled: DTLS off and SDES off
1735// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1736// answer without SDES or DTLS --> success
1737// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1738// answer without SDES or DTLS --> success
1739//
1740
1741// Test that we return a failure when applying a remote/local offer that doesn't
1742// have cryptos enabled when DTLS is off.
1743TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001744 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001746 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747 JsepSessionDescription* offer = CreateRemoteOffer(
1748 options, cricket::SEC_DISABLED);
1749 ASSERT_TRUE(offer != NULL);
1750 VerifyNoCryptoParams(offer->description(), false);
1751 // SetRemoteDescription and SetLocalDescription will take the ownership of
1752 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001753 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1755 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001756 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757}
1758
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001759// Test that we return a failure when applying a local answer that doesn't have
1760// cryptos enabled when DTLS is off.
1761TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001762 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 SessionDescriptionInterface* offer = NULL;
1764 SessionDescriptionInterface* answer = NULL;
1765 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1766 // SetRemoteDescription and SetLocalDescription will take the ownership of
1767 // the offer.
1768 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001769 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770}
1771
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001772// Test we will return fail when apply an remote answer that doesn't have
1773// crypto enabled when DTLS is off.
1774TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001775 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 SessionDescriptionInterface* offer = NULL;
1777 SessionDescriptionInterface* answer = NULL;
1778 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1779 // SetRemoteDescription and SetLocalDescription will take the ownership of
1780 // the offer.
1781 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001782 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783}
1784
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001785// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1786// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001787TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001788 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001789 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001790 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791 SetFactoryDtlsSrtp();
1792 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001793 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001794 JsepSessionDescription* offer =
1795 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 ASSERT_TRUE(offer != NULL);
1797 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001798 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799
1800 // SetRemoteDescription will take the ownership of the offer.
1801 SetRemoteDescriptionWithoutError(offer);
1802
1803 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001804 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 ASSERT_TRUE(answer != NULL);
1806 VerifyFingerprintStatus(answer->description(), true);
1807 // Check that we don't have an a=crypto line in the answer.
1808 VerifyNoCryptoParams(answer->description(), true);
1809
1810 // Now set the local description, which should work, even without a=crypto.
1811 SetLocalDescriptionWithoutError(answer);
1812}
1813
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001814// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1815// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001816TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001817 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001818 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001819 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001820 SetFactoryDtlsSrtp();
1821
1822 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001823 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001824 ASSERT_TRUE(offer != NULL);
1825 VerifyFingerprintStatus(offer->description(), true);
1826 // Check that we don't have an a=crypto line in the offer.
1827 VerifyNoCryptoParams(offer->description(), true);
1828
1829 // Now set the local description, which should work, even without a=crypto.
1830 SetLocalDescriptionWithoutError(offer);
1831
1832 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001833 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001834 JsepSessionDescription* answer =
1835 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1836 ASSERT_TRUE(answer != NULL);
1837 VerifyFingerprintStatus(answer->description(), true);
1838 VerifyNoCryptoParams(answer->description(), true);
1839
1840 // SetRemoteDescription will take the ownership of the answer.
1841 SetRemoteDescriptionWithoutError(answer);
1842}
1843
1844// Test that if we support DTLS and the other side didn't offer a fingerprint,
1845// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001846TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001847 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001848 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001850 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001851 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001852 JsepSessionDescription* offer = CreateRemoteOffer(
1853 options, cricket::SEC_REQUIRED);
1854 ASSERT_TRUE(offer != NULL);
1855 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001856 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001858 // SetRemoteDescription will take the ownership of the offer.
1859 SetRemoteDescriptionOfferExpectError(
1860 kSdpWithoutDtlsFingerprint, offer);
1861
1862 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1863 // SetLocalDescription will take the ownership of the offer.
1864 SetLocalDescriptionOfferExpectError(
1865 kSdpWithoutDtlsFingerprint, offer);
1866}
1867
1868// Test that we return a failure when applying a local answer that doesn't have
1869// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001870TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001871 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001872 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001873 SessionDescriptionInterface* offer = NULL;
1874 SessionDescriptionInterface* answer = NULL;
1875 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1876
1877 // SetRemoteDescription and SetLocalDescription will take the ownership of
1878 // the offer and answer.
1879 SetRemoteDescriptionWithoutError(offer);
1880 SetLocalDescriptionAnswerExpectError(
1881 kSdpWithoutDtlsFingerprint, answer);
1882}
1883
1884// Test that we return a failure when applying a remote answer that doesn't have
1885// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001886TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001887 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001888 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001889 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001890 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001891 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001892 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001893 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001894 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001895 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001896
1897 // SetRemoteDescription and SetLocalDescription will take the ownership of
1898 // the offer and answer.
1899 SetLocalDescriptionWithoutError(offer);
1900 SetRemoteDescriptionAnswerExpectError(
1901 kSdpWithoutDtlsFingerprint, answer);
1902}
1903
1904// Test that we create a local offer without SDES or DTLS and accept a remote
1905// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001906TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001907 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001908 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001909 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001910
1911 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001912 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001913 ASSERT_TRUE(offer != NULL);
1914 VerifyFingerprintStatus(offer->description(), false);
1915 // Check that we don't have an a=crypto line in the offer.
1916 VerifyNoCryptoParams(offer->description(), false);
1917
1918 // Now set the local description, which should work, even without a=crypto.
1919 SetLocalDescriptionWithoutError(offer);
1920
1921 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001922 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001923 JsepSessionDescription* answer =
1924 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1925 ASSERT_TRUE(answer != NULL);
1926 VerifyFingerprintStatus(answer->description(), false);
1927 VerifyNoCryptoParams(answer->description(), false);
1928
1929 // SetRemoteDescription will take the ownership of the answer.
1930 SetRemoteDescriptionWithoutError(answer);
1931}
1932
1933// Test that we create a local answer without SDES or DTLS and accept a remote
1934// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001935TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001936 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001937 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001938
1939 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001940 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001941 JsepSessionDescription* offer =
1942 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1943 ASSERT_TRUE(offer != NULL);
1944 VerifyFingerprintStatus(offer->description(), false);
1945 VerifyNoCryptoParams(offer->description(), false);
1946
1947 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001948 SetRemoteDescriptionWithoutError(offer);
1949
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001950 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001951 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001952 ASSERT_TRUE(answer != NULL);
1953 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001954 // Check that we don't have an a=crypto line in the answer.
1955 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001957 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958 SetLocalDescriptionWithoutError(answer);
1959}
1960
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001961// Test that we can create and set an answer correctly when different
1962// SSL roles have been negotiated for different transports.
1963// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1964TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1965 SendAudioVideoStream1();
1966 InitWithDtls(GetParam());
1967 SetFactoryDtlsSrtp();
1968
1969 SessionDescriptionInterface* offer = CreateOffer();
1970 SetLocalDescriptionWithoutError(offer);
1971
1972 cricket::MediaSessionOptions options;
1973 options.recv_video = true;
1974
1975 // First, negotiate different SSL roles.
1976 SessionDescriptionInterface* answer =
1977 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1978 TransportInfo* audio_transport_info =
1979 answer->description()->GetTransportInfoByName("audio");
1980 audio_transport_info->description.connection_role =
1981 cricket::CONNECTIONROLE_ACTIVE;
1982 TransportInfo* video_transport_info =
1983 answer->description()->GetTransportInfoByName("video");
1984 video_transport_info->description.connection_role =
1985 cricket::CONNECTIONROLE_PASSIVE;
1986 SetRemoteDescriptionWithoutError(answer);
1987
1988 // Now create an offer in the reverse direction, and ensure the initial
1989 // offerer responds with an answer with correct SSL roles.
1990 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1991 kSessionVersion,
1992 session_->remote_description());
1993 SetRemoteDescriptionWithoutError(offer);
1994
htaa2a49d92016-03-04 02:51:39 -08001995 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001996 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1997 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1998 audio_transport_info->description.connection_role);
1999 video_transport_info = answer->description()->GetTransportInfoByName("video");
2000 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2001 video_transport_info->description.connection_role);
2002 SetLocalDescriptionWithoutError(answer);
2003
2004 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2005 // audio is transferred over to video in the answer that completes the BUNDLE
2006 // negotiation.
2007 options.bundle_enabled = true;
2008 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2009 kSessionVersion,
2010 session_->remote_description());
2011 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002012 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002013 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2014 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2015 audio_transport_info->description.connection_role);
2016 video_transport_info = answer->description()->GetTransportInfoByName("video");
2017 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2018 video_transport_info->description.connection_role);
2019 SetLocalDescriptionWithoutError(answer);
2020}
2021
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002023 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002024 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002026 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027 SetLocalDescriptionWithoutError(offer);
2028
2029 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002030 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 SetLocalDescriptionWithoutError(offer2);
2032}
2033
2034TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002035 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002036 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002038 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039 SetRemoteDescriptionWithoutError(offer);
2040
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002041 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042 SetRemoteDescriptionWithoutError(offer2);
2043}
2044
2045TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002046 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002047 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002048 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002050 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002051 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2052 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053}
2054
2055TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002056 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002057 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002058 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002060 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002061 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002062 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063}
2064
2065TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002066 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002067 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002069 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070
htaa2a49d92016-03-04 02:51:39 -08002071 JsepSessionDescription* pranswer =
2072 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002074 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075
deadbeefab9b2d12015-10-14 11:33:11 -07002076 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002077 JsepSessionDescription* pranswer2 =
2078 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2080
deadbeefd59daf82015-10-14 15:02:44 -07002081 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082
deadbeefab9b2d12015-10-14 11:33:11 -07002083 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002084 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002085 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002086}
2087
2088TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002089 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002090 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002091 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002092 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093
2094 JsepSessionDescription* pranswer =
2095 CreateRemoteAnswer(session_->local_description());
2096 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2097
2098 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002099 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100
deadbeefab9b2d12015-10-14 11:33:11 -07002101 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102 JsepSessionDescription* pranswer2 =
2103 CreateRemoteAnswer(session_->local_description());
2104 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2105
2106 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002107 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108
deadbeefab9b2d12015-10-14 11:33:11 -07002109 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110 SessionDescriptionInterface* answer =
2111 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002112 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002113}
2114
2115TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002116 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002117 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002118 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002119
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 SessionDescriptionInterface* answer =
2121 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002122 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2123 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124}
2125
2126TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002127 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002128 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002129 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002130
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131 SessionDescriptionInterface* answer =
2132 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002133 SetRemoteDescriptionAnswerExpectError(
2134 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135}
2136
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002137// Tests that the remote candidates are added and removed successfully.
2138TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002139 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002140 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002142 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2143 "", "", "host", 0, "");
2144 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2146
deadbeefd59daf82015-10-14 15:02:44 -07002147 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2149
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002150 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002152
2153 // Fail since we have not set a remote description.
2154 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155
2156 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2157 session_->local_description());
2158 SetRemoteDescriptionWithoutError(answer);
2159
deadbeefd59daf82015-10-14 15:02:44 -07002160 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2161 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002162 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002163 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2164 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2165
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166 // Verifying the candidates are copied properly from internal vector.
2167 const SessionDescriptionInterface* remote_desc =
2168 session_->remote_description();
2169 ASSERT_TRUE(remote_desc != NULL);
2170 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2171 const IceCandidateCollection* candidates =
2172 remote_desc->candidates(kMediaContentIndex0);
2173 ASSERT_EQ(2u, candidates->count());
2174 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2175 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2176 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2177 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2178
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002179 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2180 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181 candidate.set_component(2);
2182 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2183 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002184 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185
2186 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2187 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002188
2189 // Remove candidate1 and candidate2
2190 std::vector<cricket::Candidate> remote_candidates;
2191 remote_candidates.push_back(ice_candidate1.candidate());
2192 remote_candidates.push_back(ice_candidate2.candidate());
2193 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2194 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002195}
2196
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002197// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002198// that it is retained if the remote session description is changed.
2199TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002200 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201 cricket::Candidate candidate1;
2202 candidate1.set_component(1);
2203 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2204 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002205 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002206 CreateAndSetRemoteOfferAndLocalAnswer();
2207
2208 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2209 const SessionDescriptionInterface* remote_desc =
2210 session_->remote_description();
2211 ASSERT_TRUE(remote_desc != NULL);
2212 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2213 const IceCandidateCollection* candidates =
2214 remote_desc->candidates(kMediaContentIndex0);
2215 ASSERT_EQ(1u, candidates->count());
2216 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2217
2218 // Update the RemoteSessionDescription with a new session description and
2219 // a candidate and check that the new remote session description contains both
2220 // candidates.
2221 SessionDescriptionInterface* offer = CreateRemoteOffer();
2222 cricket::Candidate candidate2;
2223 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2224 candidate2);
2225 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2226 SetRemoteDescriptionWithoutError(offer);
2227
2228 remote_desc = session_->remote_description();
2229 ASSERT_TRUE(remote_desc != NULL);
2230 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2231 candidates = remote_desc->candidates(kMediaContentIndex0);
2232 ASSERT_EQ(2u, candidates->count());
2233 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2234 // Username and password have be updated with the TransportInfo of the
2235 // SessionDescription, won't be equal to the original one.
2236 candidate2.set_username(candidates->at(0)->candidate().username());
2237 candidate2.set_password(candidates->at(0)->candidate().password());
2238 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2239 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2240 // No need to verify the username and password.
2241 candidate1.set_username(candidates->at(1)->candidate().username());
2242 candidate1.set_password(candidates->at(1)->candidate().password());
2243 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2244
2245 // Test that the candidate is ignored if we can add the same candidate again.
2246 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2247}
2248
2249// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002250// that they are retained if the local session description is changed. And if
2251// continual gathering is enabled, they are removed from the local session
2252// description when the network is down.
2253TEST_F(WebRtcSessionTest,
2254 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002255 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002256 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002257 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002258 CreateAndSetRemoteOfferAndLocalAnswer();
2259
2260 const SessionDescriptionInterface* local_desc = session_->local_description();
2261 const IceCandidateCollection* candidates =
2262 local_desc->candidates(kMediaContentIndex0);
2263 ASSERT_TRUE(candidates != NULL);
2264 EXPECT_EQ(0u, candidates->count());
2265
2266 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2267
2268 local_desc = session_->local_description();
2269 candidates = local_desc->candidates(kMediaContentIndex0);
2270 ASSERT_TRUE(candidates != NULL);
2271 EXPECT_LT(0u, candidates->count());
2272 candidates = local_desc->candidates(1);
2273 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002274 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275
2276 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002277 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278 CreateAndSetRemoteOfferAndLocalAnswer();
2279
2280 local_desc = session_->local_description();
2281 candidates = local_desc->candidates(kMediaContentIndex0);
2282 ASSERT_TRUE(candidates != NULL);
2283 EXPECT_LT(0u, candidates->count());
2284 candidates = local_desc->candidates(1);
2285 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002286 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002287
2288 candidates = local_desc->candidates(kMediaContentIndex0);
2289 size_t num_local_candidates = candidates->count();
2290 // Enable Continual Gathering
2291 session_->SetIceConfig(cricket::IceConfig(-1, -1, true, false, -1));
2292 // Bring down the network interface to trigger candidate removals.
2293 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2294 // Verify that all local candidates are removed.
2295 EXPECT_EQ(0, observer_.num_candidates_removed_);
2296 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2297 kIceCandidatesTimeout);
2298 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2299}
2300
2301// Tests that if continual gathering is disabled, local candidates won't be
2302// removed when the interface is turned down.
2303TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2304 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2305 Init();
2306 SendAudioVideoStream1();
2307 CreateAndSetRemoteOfferAndLocalAnswer();
2308
2309 const SessionDescriptionInterface* local_desc = session_->local_description();
2310 const IceCandidateCollection* candidates =
2311 local_desc->candidates(kMediaContentIndex0);
2312 ASSERT_TRUE(candidates != NULL);
2313 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2314
2315 size_t num_local_candidates = candidates->count();
2316 EXPECT_LT(0u, num_local_candidates);
2317 // By default, Continual Gathering is disabled.
2318 // Bring down the network interface.
2319 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2320 // Verify that the local candidates are not removed.
2321 rtc::Thread::Current()->ProcessMessages(1000);
2322 EXPECT_EQ(0, observer_.num_candidates_removed_);
2323 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324}
2325
2326// Test that we can set a remote session description with remote candidates.
2327TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002328 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329
2330 cricket::Candidate candidate1;
2331 candidate1.set_component(1);
2332 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2333 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002334 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002335 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336
2337 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2338 SetRemoteDescriptionWithoutError(offer);
2339
2340 const SessionDescriptionInterface* remote_desc =
2341 session_->remote_description();
2342 ASSERT_TRUE(remote_desc != NULL);
2343 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2344 const IceCandidateCollection* candidates =
2345 remote_desc->candidates(kMediaContentIndex0);
2346 ASSERT_EQ(1u, candidates->count());
2347 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2348
htaa2a49d92016-03-04 02:51:39 -08002349 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002350 SetLocalDescriptionWithoutError(answer);
2351}
2352
2353// Test that offers and answers contains ice candidates when Ice candidates have
2354// been gathered.
2355TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002356 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002357 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002358 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 // Ice is started but candidates are not provided until SetLocalDescription
2360 // is called.
2361 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2362 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2363 CreateAndSetRemoteOfferAndLocalAnswer();
2364 // Wait until at least one local candidate has been collected.
2365 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2366 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367
kwibergd1fe2812016-04-27 06:47:29 -07002368 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002369
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2371 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002372
2373 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2374 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002375 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2377 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 SetLocalDescriptionWithoutError(answer);
2379}
2380
2381// Verifies TransportProxy and media channels are created with content names
2382// present in the SessionDescription.
2383TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002384 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002385 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002386 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387
2388 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002389 // "video". Goal is to modify these content names and verify transport
2390 // channels
2391 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002392 // present in SDP.
2393 std::string sdp;
2394 EXPECT_TRUE(offer->ToString(&sdp));
2395 const std::string kAudioMid = "a=mid:audio";
2396 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2397 const std::string kVideoMid = "a=mid:video";
2398 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2399
2400 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002401 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002402 kAudioMidReplaceStr.c_str(),
2403 kAudioMidReplaceStr.length(),
2404 &sdp);
2405 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002406 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002407 kVideoMidReplaceStr.c_str(),
2408 kVideoMidReplaceStr.length(),
2409 &sdp);
2410
2411 SessionDescriptionInterface* modified_offer =
2412 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2413
2414 SetRemoteDescriptionWithoutError(modified_offer);
2415
htaa2a49d92016-03-04 02:51:39 -08002416 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002417 SetLocalDescriptionWithoutError(answer);
2418
deadbeefcbecd352015-09-23 11:50:27 -07002419 cricket::TransportChannel* voice_transport_channel =
2420 session_->voice_rtp_transport_channel();
2421 EXPECT_TRUE(voice_transport_channel != NULL);
2422 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2423 cricket::TransportChannel* video_transport_channel =
2424 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002425 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002426 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002427 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2428 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2429}
2430
2431// Test that an offer contains the correct media content descriptions based on
2432// the send streams when no constraints have been set.
2433TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002434 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002435 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002436
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002437 ASSERT_TRUE(offer != NULL);
2438 const cricket::ContentInfo* content =
2439 cricket::GetFirstAudioContent(offer->description());
2440 EXPECT_TRUE(content != NULL);
2441 content = cricket::GetFirstVideoContent(offer->description());
2442 EXPECT_TRUE(content == NULL);
2443}
2444
2445// Test that an offer contains the correct media content descriptions based on
2446// the send streams when no constraints have been set.
2447TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002448 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002449 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002450 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002451 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002452
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002453 const cricket::ContentInfo* content =
2454 cricket::GetFirstAudioContent(offer->description());
2455 EXPECT_TRUE(content != NULL);
2456 content = cricket::GetFirstVideoContent(offer->description());
2457 EXPECT_TRUE(content == NULL);
2458
2459 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002460 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002461 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462 content = cricket::GetFirstAudioContent(offer->description());
2463 EXPECT_TRUE(content != NULL);
2464 content = cricket::GetFirstVideoContent(offer->description());
2465 EXPECT_TRUE(content != NULL);
2466}
2467
2468// Test that an offer contains no media content descriptions if
2469// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2470TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002471 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002472 PeerConnectionInterface::RTCOfferAnswerOptions options;
2473 options.offer_to_receive_audio = 0;
2474 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475
kwibergd1fe2812016-04-27 06:47:29 -07002476 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002477
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478 ASSERT_TRUE(offer != NULL);
2479 const cricket::ContentInfo* content =
2480 cricket::GetFirstAudioContent(offer->description());
2481 EXPECT_TRUE(content == NULL);
2482 content = cricket::GetFirstVideoContent(offer->description());
2483 EXPECT_TRUE(content == NULL);
2484}
2485
2486// Test that an offer contains only audio media content descriptions if
2487// kOfferToReceiveAudio constraints are set to true.
2488TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002489 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002490 PeerConnectionInterface::RTCOfferAnswerOptions options;
2491 options.offer_to_receive_audio =
2492 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2493
kwibergd1fe2812016-04-27 06:47:29 -07002494 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495
2496 const cricket::ContentInfo* content =
2497 cricket::GetFirstAudioContent(offer->description());
2498 EXPECT_TRUE(content != NULL);
2499 content = cricket::GetFirstVideoContent(offer->description());
2500 EXPECT_TRUE(content == NULL);
2501}
2502
2503// Test that an offer contains audio and video media content descriptions if
2504// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2505TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002506 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002507 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002508 PeerConnectionInterface::RTCOfferAnswerOptions options;
2509 options.offer_to_receive_audio =
2510 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2511 options.offer_to_receive_video =
2512 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2513
kwibergd1fe2812016-04-27 06:47:29 -07002514 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002515
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516 const cricket::ContentInfo* content =
2517 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002518 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002519
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520 content = cricket::GetFirstVideoContent(offer->description());
2521 EXPECT_TRUE(content != NULL);
2522
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002523 // Sets constraints to false and verifies that audio/video contents are
2524 // removed.
2525 options.offer_to_receive_audio = 0;
2526 options.offer_to_receive_video = 0;
2527 offer.reset(CreateOffer(options));
2528
2529 content = cricket::GetFirstAudioContent(offer->description());
2530 EXPECT_TRUE(content == NULL);
2531 content = cricket::GetFirstVideoContent(offer->description());
2532 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002533}
2534
2535// Test that an answer can not be created if the last remote description is not
2536// an offer.
2537TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002538 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002539 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002540 SetLocalDescriptionWithoutError(offer);
2541 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2542 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002543 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544}
2545
2546// Test that an answer contains the correct media content descriptions when no
2547// constraints have been set.
2548TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002549 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002550 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002551 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002552 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002553 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002554 const cricket::ContentInfo* content =
2555 cricket::GetFirstAudioContent(answer->description());
2556 ASSERT_TRUE(content != NULL);
2557 EXPECT_FALSE(content->rejected);
2558
2559 content = cricket::GetFirstVideoContent(answer->description());
2560 ASSERT_TRUE(content != NULL);
2561 EXPECT_FALSE(content->rejected);
2562}
2563
2564// Test that an answer contains the correct media content descriptions when no
2565// constraints have been set and the offer only contain audio.
2566TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002567 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002568 // Create a remote offer with audio only.
2569 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002570
kwibergd1fe2812016-04-27 06:47:29 -07002571 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002572 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2573 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2574
2575 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002576 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002577 const cricket::ContentInfo* content =
2578 cricket::GetFirstAudioContent(answer->description());
2579 ASSERT_TRUE(content != NULL);
2580 EXPECT_FALSE(content->rejected);
2581
2582 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2583}
2584
2585// Test that an answer contains the correct media content descriptions when no
2586// constraints have been set.
2587TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002588 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002589 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002590 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002591 SetRemoteDescriptionWithoutError(offer.release());
2592 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002593 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002594 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002595 const cricket::ContentInfo* content =
2596 cricket::GetFirstAudioContent(answer->description());
2597 ASSERT_TRUE(content != NULL);
2598 EXPECT_FALSE(content->rejected);
2599
2600 content = cricket::GetFirstVideoContent(answer->description());
2601 ASSERT_TRUE(content != NULL);
2602 EXPECT_FALSE(content->rejected);
2603}
2604
2605// Test that an answer contains the correct media content descriptions when
2606// constraints have been set but no stream is sent.
2607TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002608 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002609 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002610 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002611 SetRemoteDescriptionWithoutError(offer.release());
2612
htaa2a49d92016-03-04 02:51:39 -08002613 cricket::MediaSessionOptions session_options;
2614 session_options.recv_audio = false;
2615 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002616 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002617 CreateAnswer(session_options));
2618
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002619 const cricket::ContentInfo* content =
2620 cricket::GetFirstAudioContent(answer->description());
2621 ASSERT_TRUE(content != NULL);
2622 EXPECT_TRUE(content->rejected);
2623
2624 content = cricket::GetFirstVideoContent(answer->description());
2625 ASSERT_TRUE(content != NULL);
2626 EXPECT_TRUE(content->rejected);
2627}
2628
2629// Test that an answer contains the correct media content descriptions when
2630// constraints have been set and streams are sent.
2631TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002632 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002633 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002634 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002635 SetRemoteDescriptionWithoutError(offer.release());
2636
htaa2a49d92016-03-04 02:51:39 -08002637 cricket::MediaSessionOptions options;
2638 options.recv_audio = false;
2639 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002640
2641 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002642 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002643 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002644
2645 // TODO(perkj): Should the direction be set to SEND_ONLY?
2646 const cricket::ContentInfo* content =
2647 cricket::GetFirstAudioContent(answer->description());
2648 ASSERT_TRUE(content != NULL);
2649 EXPECT_FALSE(content->rejected);
2650
2651 // TODO(perkj): Should the direction be set to SEND_ONLY?
2652 content = cricket::GetFirstVideoContent(answer->description());
2653 ASSERT_TRUE(content != NULL);
2654 EXPECT_FALSE(content->rejected);
2655}
2656
2657TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2658 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002659 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002660 PeerConnectionInterface::RTCOfferAnswerOptions options;
2661 options.offer_to_receive_audio =
2662 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2663 options.voice_activity_detection = false;
2664
kwibergd1fe2812016-04-27 06:47:29 -07002665 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002666
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002667 const cricket::ContentInfo* content =
2668 cricket::GetFirstAudioContent(offer->description());
2669 EXPECT_TRUE(content != NULL);
2670 EXPECT_TRUE(VerifyNoCNCodecs(content));
2671}
2672
2673TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2674 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002675 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002676 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002677 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002678 SetRemoteDescriptionWithoutError(offer.release());
2679
htaa2a49d92016-03-04 02:51:39 -08002680 cricket::MediaSessionOptions options;
2681 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002682 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002683 const cricket::ContentInfo* content =
2684 cricket::GetFirstAudioContent(answer->description());
2685 ASSERT_TRUE(content != NULL);
2686 EXPECT_TRUE(VerifyNoCNCodecs(content));
2687}
2688
2689// This test verifies the call setup when remote answer with audio only and
2690// later updates with video.
2691TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002692 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002693 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2694 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2695
deadbeefab9b2d12015-10-14 11:33:11 -07002696 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002697 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002698
2699 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002700 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2701
2702 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2703 // and answer;
2704 SetLocalDescriptionWithoutError(offer);
2705 SetRemoteDescriptionWithoutError(answer);
2706
2707 video_channel_ = media_engine_->GetVideoChannel(0);
2708 voice_channel_ = media_engine_->GetVoiceChannel(0);
2709
2710 ASSERT_TRUE(video_channel_ == NULL);
2711
2712 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2713 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2714 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2715
2716 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002717 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718 CreateAndSetRemoteOfferAndLocalAnswer();
2719
2720 video_channel_ = media_engine_->GetVideoChannel(0);
2721 voice_channel_ = media_engine_->GetVoiceChannel(0);
2722
2723 ASSERT_TRUE(video_channel_ != NULL);
2724 ASSERT_TRUE(voice_channel_ != NULL);
2725
2726 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2727 ASSERT_EQ(1u, video_channel_->send_streams().size());
2728 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2729 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2730 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2731 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2732 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2733 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2734
2735 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002736 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002737 CreateAndSetRemoteOfferAndLocalAnswer();
2738
2739 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2740 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2741 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2742 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2743 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2744}
2745
2746// This test verifies the call setup when remote answer with video only and
2747// later updates with audio.
2748TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002749 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002750 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2751 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002752 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002753 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002754
2755 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002756 options.recv_audio = false;
2757 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002758 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2759 offer, options, cricket::SEC_ENABLED);
2760
2761 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2762 // and answer.
2763 SetLocalDescriptionWithoutError(offer);
2764 SetRemoteDescriptionWithoutError(answer);
2765
2766 video_channel_ = media_engine_->GetVideoChannel(0);
2767 voice_channel_ = media_engine_->GetVoiceChannel(0);
2768
2769 ASSERT_TRUE(voice_channel_ == NULL);
2770 ASSERT_TRUE(video_channel_ != NULL);
2771
2772 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2773 ASSERT_EQ(1u, video_channel_->send_streams().size());
2774 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2775
2776 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002777 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002778 CreateAndSetRemoteOfferAndLocalAnswer();
2779
2780 voice_channel_ = media_engine_->GetVoiceChannel(0);
2781 ASSERT_TRUE(voice_channel_ != NULL);
2782
2783 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2784 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2785 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2786 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2787
2788 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002789 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002790 CreateAndSetRemoteOfferAndLocalAnswer();
2791
2792 video_channel_ = media_engine_->GetVideoChannel(0);
2793 voice_channel_ = media_engine_->GetVoiceChannel(0);
2794
2795 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2796 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2797 ASSERT_EQ(1u, video_channel_->send_streams().size());
2798 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2799}
2800
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002801TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002802 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002803 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002804 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002805 VerifyCryptoParams(offer->description());
2806 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002807 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002808 VerifyCryptoParams(answer->description());
2809}
2810
2811TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002812 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002813 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002814 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002815 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002816 VerifyNoCryptoParams(offer->description(), false);
2817}
2818
2819TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002820 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002821 VerifyAnswerFromNonCryptoOffer();
2822}
2823
2824TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002825 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002826 VerifyAnswerFromCryptoOffer();
2827}
2828
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002829// This test verifies that setLocalDescription fails if
2830// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2831TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002832 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002833 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002834 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002835
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002836 std::string sdp;
2837 RemoveIceUfragPwdLines(offer.get(), &sdp);
2838 SessionDescriptionInterface* modified_offer =
2839 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002840 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002841}
2842
2843// This test verifies that setRemoteDescription fails if
2844// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2845TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002846 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002847 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002848 std::string sdp;
2849 RemoveIceUfragPwdLines(offer.get(), &sdp);
2850 SessionDescriptionInterface* modified_offer =
2851 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002852 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002853}
2854
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002855// This test verifies that setLocalDescription fails if local offer has
2856// too short ice ufrag and pwd strings.
2857TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002858 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002859 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002860 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002861 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2862 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002863 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002864 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002865 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002866
2867 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002868 offer.reset(CreateOffer());
2869 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2870 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002871}
2872
2873// This test verifies that setRemoteDescription fails if remote offer has
2874// too short ice ufrag and pwd strings.
2875TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002876 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002877 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002878 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2879 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002880 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002881 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002882 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002883
deadbeef0ed85b22016-02-23 17:24:52 -08002884 offer.reset(CreateRemoteOffer());
2885 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2886 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002887}
2888
Honghai Zhang04e91462015-12-11 14:26:22 -08002889// Test that if the remote offer indicates the peer requested ICE restart (via
2890// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2891TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002892 Init();
honghaiz503726c2015-07-31 12:37:38 -07002893
2894 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002895 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002896 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002897 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2898 0, "", "", "relay", 0, "");
2899 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2900 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002901 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2902 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002903 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2904
2905 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002906 offer.reset(CreateRemoteOffer());
2907 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002908 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2909 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2910 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002911 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2912 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002913 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2914
2915 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002916 offer.reset(CreateRemoteOffer());
2917 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002918 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2919 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2920 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002921 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2922 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002923 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2924
2925 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002926 offer.reset(CreateRemoteOffer());
2927 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2928 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002929 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2930}
2931
Honghai Zhang04e91462015-12-11 14:26:22 -08002932// Test that if the remote answer indicates the peer requested ICE restart (via
2933// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2934TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2935 Init();
2936 SessionDescriptionInterface* offer = CreateOffer();
2937 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002938
2939 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002940 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002941 answer->set_type(JsepSessionDescription::kPrAnswer);
2942 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002943 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2944 0, "", "", "relay", 0, "");
2945 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2946 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002947 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2948 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002949 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2950
2951 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002952 answer.reset(CreateRemoteAnswer(offer));
2953 answer->set_type(JsepSessionDescription::kPrAnswer);
2954 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002955 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2956 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2957 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002958 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2959 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002960 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2961
2962 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002963 answer.reset(CreateRemoteAnswer(offer));
2964 answer->set_type(JsepSessionDescription::kPrAnswer);
2965 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002966 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2967 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2968 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002969 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2970 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002971 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2972
2973 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002974 answer.reset(CreateRemoteAnswer(offer));
2975 answer->set_type(JsepSessionDescription::kPrAnswer);
2976 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2977 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002978 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2979}
2980
Donald Curtisd4f769d2015-05-28 09:48:21 -07002981// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002982// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002983TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2984 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2985
2986 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002987 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002988
2989 PeerConnectionInterface::RTCOfferAnswerOptions options;
2990 options.use_rtp_mux = true;
2991
2992 SessionDescriptionInterface* offer = CreateRemoteOffer();
2993 SetRemoteDescriptionWithoutError(offer);
2994
htaa2a49d92016-03-04 02:51:39 -08002995 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002996 SetLocalDescriptionWithoutError(answer);
2997
deadbeefcbecd352015-09-23 11:50:27 -07002998 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2999 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003000
deadbeefcbecd352015-09-23 11:50:27 -07003001 cricket::BaseChannel* voice_channel = session_->voice_channel();
3002 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003003
3004 // Checks if one of the transport channels contains a connection using a given
3005 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003006 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07003007 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07003008 session_->GetChannelTransportStats(voice_channel, &stats);
3009 for (auto& kv : stats.transport_stats) {
3010 for (auto& chan_stat : kv.second.channel_stats) {
3011 for (auto& conn_info : chan_stat.connection_infos) {
3012 if (conn_info.remote_candidate.address().port() == port) {
3013 return true;
3014 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003015 }
3016 }
3017 }
3018 return false;
3019 };
3020
3021 EXPECT_FALSE(connection_with_remote_port(5000));
3022 EXPECT_FALSE(connection_with_remote_port(5001));
3023 EXPECT_FALSE(connection_with_remote_port(6000));
3024
3025 // The way the *_WAIT checks work is they only wait if the condition fails,
3026 // which does not help in the case where state is not changing. This is
3027 // problematic in this test since we want to verify that adding a video
3028 // candidate does _not_ change state. So we interleave candidates and assume
3029 // that messages are executed in the order they were posted.
3030
3031 // First audio candidate.
3032 cricket::Candidate candidate0;
3033 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3034 candidate0.set_component(1);
3035 candidate0.set_protocol("udp");
3036 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3037 candidate0);
3038 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3039
3040 // Video candidate.
3041 cricket::Candidate candidate1;
3042 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3043 candidate1.set_component(1);
3044 candidate1.set_protocol("udp");
3045 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3046 candidate1);
3047 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3048
3049 // Second audio candidate.
3050 cricket::Candidate candidate2;
3051 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3052 candidate2.set_component(1);
3053 candidate2.set_protocol("udp");
3054 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3055 candidate2);
3056 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3057
3058 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3059 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3060
3061 // No need here for a _WAIT check since we are checking that state hasn't
3062 // changed: if this is false we would be doing waits for nothing and if this
3063 // is true then there will be no messages processed anyways.
3064 EXPECT_FALSE(connection_with_remote_port(6000));
3065}
3066
deadbeefcbecd352015-09-23 11:50:27 -07003067// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003068TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3069 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003070 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003071
3072 PeerConnectionInterface::RTCOfferAnswerOptions options;
3073 options.use_rtp_mux = true;
3074
3075 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003076 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003077
deadbeefcbecd352015-09-23 11:50:27 -07003078 EXPECT_NE(session_->voice_rtp_transport_channel(),
3079 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003080
deadbeefab9b2d12015-10-14 11:33:11 -07003081 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003082 SessionDescriptionInterface* answer =
3083 CreateRemoteAnswer(session_->local_description());
3084 SetRemoteDescriptionWithoutError(answer);
3085
deadbeefcbecd352015-09-23 11:50:27 -07003086 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3087 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003088}
3089
deadbeefcbecd352015-09-23 11:50:27 -07003090// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003091TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3092 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003093 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003094
Donald Curtis0e209b02015-03-24 09:29:54 -07003095 PeerConnectionInterface::RTCOfferAnswerOptions options;
3096 options.use_rtp_mux = true;
3097
3098 SessionDescriptionInterface* offer = CreateOffer(options);
3099 SetLocalDescriptionWithoutError(offer);
3100
deadbeefcbecd352015-09-23 11:50:27 -07003101 EXPECT_NE(session_->voice_rtp_transport_channel(),
3102 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003103
deadbeefab9b2d12015-10-14 11:33:11 -07003104 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003105
3106 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003107 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003108 CreateRemoteAnswer(session_->local_description()));
3109 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3110 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3111 JsepSessionDescription* modified_answer =
3112 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3113 modified_answer->Initialize(answer_copy, "1", "1");
3114 SetRemoteDescriptionWithoutError(modified_answer); //
3115
deadbeefcbecd352015-09-23 11:50:27 -07003116 EXPECT_NE(session_->voice_rtp_transport_channel(),
3117 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003118}
3119
3120// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3121TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3122 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003123 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003124
3125 PeerConnectionInterface::RTCOfferAnswerOptions options;
3126 options.use_rtp_mux = true;
3127
3128 SessionDescriptionInterface* offer = CreateOffer(options);
3129 SetLocalDescriptionWithoutError(offer);
3130
deadbeefcbecd352015-09-23 11:50:27 -07003131 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3132 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003133
deadbeefab9b2d12015-10-14 11:33:11 -07003134 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003135 SessionDescriptionInterface* answer =
3136 CreateRemoteAnswer(session_->local_description());
3137 SetRemoteDescriptionWithoutError(answer);
3138
deadbeefcbecd352015-09-23 11:50:27 -07003139 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3140 session_->video_rtp_transport_channel());
3141}
3142
3143// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3144// audio content in the answer.
3145TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3146 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003147 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003148
3149 PeerConnectionInterface::RTCOfferAnswerOptions options;
3150 options.use_rtp_mux = true;
3151
3152 SessionDescriptionInterface* offer = CreateOffer(options);
3153 SetLocalDescriptionWithoutError(offer);
3154
3155 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3156 session_->video_rtp_transport_channel());
3157
deadbeefab9b2d12015-10-14 11:33:11 -07003158 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003159 cricket::MediaSessionOptions recv_options;
3160 recv_options.recv_audio = false;
3161 recv_options.recv_video = true;
3162 SessionDescriptionInterface* answer =
3163 CreateRemoteAnswer(session_->local_description(), recv_options);
3164 SetRemoteDescriptionWithoutError(answer);
3165
deadbeefd59daf82015-10-14 15:02:44 -07003166 EXPECT_TRUE(nullptr == session_->voice_channel());
3167 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003168
deadbeefd59daf82015-10-14 15:02:44 -07003169 session_->Close();
3170 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3171 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3172 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3173 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003174}
3175
3176// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3177TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3178 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003179 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003180
Donald Curtis0e209b02015-03-24 09:29:54 -07003181 PeerConnectionInterface::RTCOfferAnswerOptions options;
3182 options.use_rtp_mux = true;
3183
3184 SessionDescriptionInterface* offer = CreateOffer(options);
3185 SetLocalDescriptionWithoutError(offer);
3186
deadbeefcbecd352015-09-23 11:50:27 -07003187 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3188 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003189
deadbeefab9b2d12015-10-14 11:33:11 -07003190 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003191
3192 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003193 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003194 CreateRemoteAnswer(session_->local_description()));
3195 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3196 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3197 JsepSessionDescription* modified_answer =
3198 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3199 modified_answer->Initialize(answer_copy, "1", "1");
3200 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003201
deadbeefcbecd352015-09-23 11:50:27 -07003202 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3203 session_->video_rtp_transport_channel());
3204}
3205
3206// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3207TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3208 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003209 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003210
3211 SessionDescriptionInterface* offer = CreateRemoteOffer();
3212 SetRemoteDescriptionWithoutError(offer);
3213
3214 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3215 session_->video_rtp_transport_channel());
3216
deadbeefab9b2d12015-10-14 11:33:11 -07003217 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003218 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003219 SetLocalDescriptionWithoutError(answer);
3220
3221 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3222 session_->video_rtp_transport_channel());
3223}
3224
3225// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3226TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3227 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003228 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003229
3230 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003231 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003232 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3233 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3234 JsepSessionDescription* modified_offer =
3235 new JsepSessionDescription(JsepSessionDescription::kOffer);
3236 modified_offer->Initialize(offer_copy, "1", "1");
3237
3238 // Expect an error when applying the remote description
3239 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3240 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003241}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003242
Peter Thatcher4eddf182015-04-30 10:55:59 -07003243// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003244TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3245 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003246 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003247
Donald Curtis0e209b02015-03-24 09:29:54 -07003248 PeerConnectionInterface::RTCOfferAnswerOptions options;
3249 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003250
Donald Curtis0e209b02015-03-24 09:29:54 -07003251 SessionDescriptionInterface* offer = CreateOffer(options);
3252 SetLocalDescriptionWithoutError(offer);
3253
deadbeefcbecd352015-09-23 11:50:27 -07003254 EXPECT_NE(session_->voice_rtp_transport_channel(),
3255 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003256
deadbeefab9b2d12015-10-14 11:33:11 -07003257 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003258 SessionDescriptionInterface* answer =
3259 CreateRemoteAnswer(session_->local_description());
3260 SetRemoteDescriptionWithoutError(answer);
3261
3262 // This should lead to an audio-only call but isn't implemented
3263 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003264 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3265 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003266}
3267
deadbeefcbecd352015-09-23 11:50:27 -07003268// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003269TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3270 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003271 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003272 PeerConnectionInterface::RTCOfferAnswerOptions options;
3273 options.use_rtp_mux = true;
3274
3275 SessionDescriptionInterface* offer = CreateOffer(options);
3276 SetLocalDescriptionWithoutError(offer);
3277
deadbeefcbecd352015-09-23 11:50:27 -07003278 EXPECT_NE(session_->voice_rtp_transport_channel(),
3279 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003280
deadbeefab9b2d12015-10-14 11:33:11 -07003281 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003282
3283 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003284 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003285 CreateRemoteAnswer(session_->local_description()));
3286 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3287 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3288 JsepSessionDescription* modified_answer =
3289 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3290 modified_answer->Initialize(answer_copy, "1", "1");
3291 SetRemoteDescriptionWithoutError(modified_answer); //
3292
deadbeefcbecd352015-09-23 11:50:27 -07003293 EXPECT_NE(session_->voice_rtp_transport_channel(),
3294 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003295}
3296
Peter Thatcher4eddf182015-04-30 10:55:59 -07003297// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3298TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3299 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003300 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003301
3302 PeerConnectionInterface::RTCOfferAnswerOptions options;
3303 options.use_rtp_mux = true;
3304
3305 SessionDescriptionInterface* offer = CreateOffer(options);
3306 SetRemoteDescriptionWithoutError(offer);
3307
deadbeefcbecd352015-09-23 11:50:27 -07003308 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3309 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003310}
3311
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003312TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3313 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003314 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003315
3316 PeerConnectionInterface::RTCOfferAnswerOptions options;
3317 SessionDescriptionInterface* offer = CreateOffer(options);
3318 SetLocalDescriptionWithoutError(offer);
3319
deadbeefcbecd352015-09-23 11:50:27 -07003320 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3321 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003322
deadbeefab9b2d12015-10-14 11:33:11 -07003323 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003324 SessionDescriptionInterface* answer =
3325 CreateRemoteAnswer(session_->local_description());
3326 SetRemoteDescriptionWithoutError(answer);
3327
deadbeefcbecd352015-09-23 11:50:27 -07003328 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3329 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003330}
3331
3332TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3333 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003334 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003335
3336 PeerConnectionInterface::RTCOfferAnswerOptions options;
3337 SessionDescriptionInterface* offer = CreateOffer(options);
3338 SetLocalDescriptionWithoutError(offer);
3339
deadbeefcbecd352015-09-23 11:50:27 -07003340 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3341 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003342
deadbeefab9b2d12015-10-14 11:33:11 -07003343 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003344 SessionDescriptionInterface* answer =
3345 CreateRemoteAnswer(session_->local_description());
3346 SetRemoteDescriptionWithoutError(answer);
3347
deadbeefcbecd352015-09-23 11:50:27 -07003348 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3349 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003350}
3351
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003352// This test verifies that SetLocalDescription and SetRemoteDescription fails
3353// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3354TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003355 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003356 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003357
3358 PeerConnectionInterface::RTCOfferAnswerOptions options;
3359 options.use_rtp_mux = true;
3360
3361 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003362 std::string offer_str;
3363 offer->ToString(&offer_str);
3364 // Disable rtcp-mux
3365 const std::string rtcp_mux = "rtcp-mux";
3366 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003367 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003368 xrtcp_mux.c_str(), xrtcp_mux.length(),
3369 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003370 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003371 new JsepSessionDescription(JsepSessionDescription::kOffer);
3372 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003373 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003374 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003375 new JsepSessionDescription(JsepSessionDescription::kOffer);
3376 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003377 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003378 // Trying unmodified SDP.
3379 SetLocalDescriptionWithoutError(offer);
3380}
3381
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003382TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003383 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003384 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003385 CreateAndSetRemoteOfferAndLocalAnswer();
3386 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3387 ASSERT_TRUE(channel != NULL);
3388 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003389 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003390 double volume;
3391 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3392 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003393 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003394 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3395 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003396 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003397 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3398 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003399}
3400
skvlade0d46372016-04-07 22:59:22 -07003401TEST_F(WebRtcSessionTest, SetAudioMaxSendBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003402 Init();
3403 SendAudioVideoStream1();
3404 CreateAndSetRemoteOfferAndLocalAnswer();
3405 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3406 ASSERT_TRUE(channel != NULL);
3407 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
skvlade0d46372016-04-07 22:59:22 -07003408 EXPECT_EQ(-1, channel->max_bps());
skvladdc1c62c2016-03-16 19:07:43 -07003409 webrtc::RtpParameters params = session_->GetAudioRtpParameters(send_ssrc);
skvlade0d46372016-04-07 22:59:22 -07003410 EXPECT_EQ(1, params.encodings.size());
3411 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3412 params.encodings[0].max_bitrate_bps = 1000;
3413 EXPECT_TRUE(session_->SetAudioRtpParameters(send_ssrc, params));
skvladdc1c62c2016-03-16 19:07:43 -07003414
skvlade0d46372016-04-07 22:59:22 -07003415 // Read back the parameters and verify they have been changed.
3416 params = session_->GetAudioRtpParameters(send_ssrc);
3417 EXPECT_EQ(1, params.encodings.size());
3418 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3419
3420 // Verify that the audio channel received the new parameters.
3421 params = channel->GetRtpParameters(send_ssrc);
3422 EXPECT_EQ(1, params.encodings.size());
3423 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3424
3425 // Verify that the global bitrate limit has not been changed.
3426 EXPECT_EQ(-1, channel->max_bps());
skvladdc1c62c2016-03-16 19:07:43 -07003427}
3428
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003429TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003430 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003431 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003432 CreateAndSetRemoteOfferAndLocalAnswer();
3433 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3434 ASSERT_TRUE(channel != NULL);
3435 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003436 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003437 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3438
3439 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003440 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003441
kwibergd1fe2812016-04-27 06:47:29 -07003442 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003443 session_->SetAudioSend(send_ssrc, false, options, source.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003444 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003445 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003446 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003447
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003448 // This will trigger SetSink(nullptr) to the |source|.
3449 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003450 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003451 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003452 EXPECT_TRUE(source->sink() == nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003453}
3454
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003455TEST_F(WebRtcSessionTest, AudioSourceForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003456 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003457 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003458 CreateAndSetRemoteOfferAndLocalAnswer();
3459 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3460 ASSERT_TRUE(channel != NULL);
3461 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003462 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003463
kwibergd1fe2812016-04-27 06:47:29 -07003464 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003465 cricket::AudioOptions options;
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003466 session_->SetAudioSend(send_ssrc, true, options, source.get());
3467 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003468
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003469 // Delete the |source| and it will trigger OnClose() to the sink, and this
3470 // will invalidate the |source_| pointer in the sink and prevent getting a
3471 // SetSink(nullptr) callback afterwards.
3472 source.reset();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003473
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003474 // This will trigger SetSink(nullptr) if no OnClose() callback.
3475 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476}
3477
3478TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003479 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003480 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003481 CreateAndSetRemoteOfferAndLocalAnswer();
3482 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3483 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003484 ASSERT_LT(0u, channel->sinks().size());
3485 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003486 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003487 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003488 cricket::FakeVideoRenderer renderer;
3489 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003490 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003491 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003492 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003493}
3494
skvladdc1c62c2016-03-16 19:07:43 -07003495TEST_F(WebRtcSessionTest, SetVideoMaxSendBitrate) {
3496 Init();
3497 SendAudioVideoStream1();
3498 CreateAndSetRemoteOfferAndLocalAnswer();
3499 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3500 ASSERT_TRUE(channel != NULL);
3501 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
3502 EXPECT_EQ(-1, channel->max_bps());
3503 webrtc::RtpParameters params = session_->GetVideoRtpParameters(send_ssrc);
3504 EXPECT_EQ(1, params.encodings.size());
3505 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3506 params.encodings[0].max_bitrate_bps = 1000;
3507 EXPECT_TRUE(session_->SetVideoRtpParameters(send_ssrc, params));
3508
3509 // Read back the parameters and verify they have been changed.
3510 params = session_->GetVideoRtpParameters(send_ssrc);
3511 EXPECT_EQ(1, params.encodings.size());
3512 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3513
3514 // Verify that the video channel received the new parameters.
3515 params = channel->GetRtpParameters(send_ssrc);
3516 EXPECT_EQ(1, params.encodings.size());
3517 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3518
3519 // Verify that the global bitrate limit has not been changed.
3520 EXPECT_EQ(-1, channel->max_bps());
3521}
3522
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003523TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003524 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003525 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003526 CreateAndSetRemoteOfferAndLocalAnswer();
3527 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3528 ASSERT_TRUE(channel != NULL);
3529 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003530 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003531 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3532 cricket::VideoOptions* options = NULL;
3533 session_->SetVideoSend(send_ssrc, false, options);
3534 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3535 session_->SetVideoSend(send_ssrc, true, options);
3536 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3537}
3538
3539TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3540 TestCanInsertDtmf(false);
3541}
3542
3543TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3544 TestCanInsertDtmf(true);
3545}
3546
3547TEST_F(WebRtcSessionTest, InsertDtmf) {
3548 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003549 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003550 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003551 CreateAndSetRemoteOfferAndLocalAnswer();
3552 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3553 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3554
3555 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003556 const int expected_duration = 90;
3557 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3558 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3559 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3560
3561 // Verify
3562 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003563 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003564 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003565 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003566 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003567 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003568 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003569 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003570}
3571
deadbeefd59daf82015-10-14 15:02:44 -07003572// This test verifies the |initial_offerer| flag when session initiates the
3573// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003574TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003575 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003576 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003577 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003578 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3579 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003580 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003581 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003582 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003583}
3584
deadbeefd59daf82015-10-14 15:02:44 -07003585// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003586TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003587 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003588 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003589 SessionDescriptionInterface* offer = CreateRemoteOffer();
3590 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003591 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003592
deadbeefd59daf82015-10-14 15:02:44 -07003593 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003594 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003595 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003596}
3597
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003598// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3599TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003600 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003601 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003602 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003603 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003604 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003605 CreateRemoteAnswer(session_->local_description()));
3606
3607 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3608 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003609 JsepSessionDescription* modified_answer =
3610 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003611
3612 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3613 answer->session_id(),
3614 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003615 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003616
wu@webrtc.org4e393072014-04-07 17:04:35 +00003617 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003618 std::string sdp;
3619 EXPECT_TRUE(answer->ToString(&sdp));
3620 const std::string kAudioMid = "a=mid:audio";
3621 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003622 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003623 kAudioMidReplaceStr.c_str(),
3624 kAudioMidReplaceStr.length(),
3625 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003626 SessionDescriptionInterface* modified_answer1 =
3627 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003628 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003629
wu@webrtc.org4e393072014-04-07 17:04:35 +00003630 // Different media types.
3631 EXPECT_TRUE(answer->ToString(&sdp));
3632 const std::string kAudioMline = "m=audio";
3633 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003634 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003635 kAudioMlineReplaceStr.c_str(),
3636 kAudioMlineReplaceStr.length(),
3637 &sdp);
3638 SessionDescriptionInterface* modified_answer2 =
3639 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3640 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3641
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003642 SetRemoteDescriptionWithoutError(answer.release());
3643}
3644
3645// Verifying remote offer and local answer have matching m-lines as per
3646// RFC 3264.
3647TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003648 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003649 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003650 SessionDescriptionInterface* offer = CreateRemoteOffer();
3651 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003652 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003653
3654 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3655 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003656 JsepSessionDescription* modified_answer =
3657 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003658
3659 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3660 answer->session_id(),
3661 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003662 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003663 SetLocalDescriptionWithoutError(answer);
3664}
3665
3666// This test verifies that WebRtcSession does not start candidate allocation
3667// before SetLocalDescription is called.
3668TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003669 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003670 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003671 SessionDescriptionInterface* offer = CreateRemoteOffer();
3672 cricket::Candidate candidate;
3673 candidate.set_component(1);
3674 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3675 candidate);
3676 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3677 cricket::Candidate candidate1;
3678 candidate1.set_component(1);
3679 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3680 candidate1);
3681 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3682 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003683 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3684 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003685
3686 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003687 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003688 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3689 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3690
htaa2a49d92016-03-04 02:51:39 -08003691 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003692 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003693 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3694}
3695
3696// This test verifies that crypto parameter is updated in local session
3697// description as per security policy set in MediaSessionDescriptionFactory.
3698TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003699 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003700 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003701 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003702
3703 // Making sure SetLocalDescription correctly sets crypto value in
3704 // SessionDescription object after de-serialization of sdp string. The value
3705 // will be set as per MediaSessionDescriptionFactory.
3706 std::string offer_str;
3707 offer->ToString(&offer_str);
3708 SessionDescriptionInterface* jsep_offer_str =
3709 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3710 SetLocalDescriptionWithoutError(jsep_offer_str);
3711 EXPECT_TRUE(session_->voice_channel()->secure_required());
3712 EXPECT_TRUE(session_->video_channel()->secure_required());
3713}
3714
3715// This test verifies the crypto parameter when security is disabled.
3716TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003717 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003718 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003719 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003720 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003721
3722 // Making sure SetLocalDescription correctly sets crypto value in
3723 // SessionDescription object after de-serialization of sdp string. The value
3724 // will be set as per MediaSessionDescriptionFactory.
3725 std::string offer_str;
3726 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003727 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003728 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3729 SetLocalDescriptionWithoutError(jsep_offer_str);
3730 EXPECT_FALSE(session_->voice_channel()->secure_required());
3731 EXPECT_FALSE(session_->video_channel()->secure_required());
3732}
3733
3734// This test verifies that an answer contains new ufrag and password if an offer
3735// with new ufrag and password is received.
3736TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003737 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003738 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003739 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003740 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003741 SetRemoteDescriptionWithoutError(offer.release());
3742
deadbeefab9b2d12015-10-14 11:33:11 -07003743 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003744 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003745 SetLocalDescriptionWithoutError(answer.release());
3746
3747 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003748 for (const cricket::ContentInfo& content :
3749 session_->local_description()->description()->contents()) {
3750 options.transport_options[content.name].ice_restart = true;
3751 }
kwibergd1fe2812016-04-27 06:47:29 -07003752 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003753 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003754 SetRemoteDescriptionWithoutError(updated_offer1.release());
3755
kwibergd1fe2812016-04-27 06:47:29 -07003756 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003757
deadbeef0ed85b22016-02-23 17:24:52 -08003758 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3759 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003760
deadbeef0ed85b22016-02-23 17:24:52 -08003761 // Even a second answer (created before the description is set) should have
3762 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003763 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003764
3765 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3766 session_->local_description()->description()));
3767
3768 SetLocalDescriptionWithoutError(updated_answer2.release());
3769}
3770
3771// This test verifies that an answer contains new ufrag and password if an offer
3772// that changes either the ufrag or password (but not both) is received.
3773// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3774// a=ice-pwd attributes compared to the previous SDP from the peer, it
3775// indicates that ICE is restarting for this media stream."
3776TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3777 Init();
3778 cricket::MediaSessionOptions options;
3779 options.recv_audio = true;
3780 options.recv_video = true;
3781 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003782 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003783 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3784 SetRemoteDescriptionWithoutError(offer.release());
3785
3786 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003787 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003788 SetLocalDescriptionWithoutError(answer.release());
3789
3790 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003791 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003792 CreateRemoteOffer(options, session_->remote_description()));
3793 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3794 "original_password12345");
3795 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3796
kwibergd1fe2812016-04-27 06:47:29 -07003797 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003798 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3799 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003800 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003801
3802 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003803 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003804 CreateRemoteOffer(options, session_->remote_description()));
3805 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3806 "modified_password12345");
3807 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3808
kwibergd1fe2812016-04-27 06:47:29 -07003809 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003810 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3811 session_->local_description()->description()));
3812 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003813}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003814
wu@webrtc.org91053e72013-08-10 07:18:04 +00003815// This test verifies that an answer contains old ufrag and password if an offer
3816// with old ufrag and password is received.
3817TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003818 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003819 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003820 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003821 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003822 SetRemoteDescriptionWithoutError(offer.release());
3823
deadbeefab9b2d12015-10-14 11:33:11 -07003824 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003825 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003826 SetLocalDescriptionWithoutError(answer.release());
3827
3828 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003829 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003830 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003831 SetRemoteDescriptionWithoutError(updated_offer2.release());
3832
kwibergd1fe2812016-04-27 06:47:29 -07003833 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003834
deadbeef0ed85b22016-02-23 17:24:52 -08003835 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3836 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003837
3838 SetLocalDescriptionWithoutError(updated_answer2.release());
3839}
3840
deadbeef0ed85b22016-02-23 17:24:52 -08003841// This test verifies that if an offer does an ICE restart on some, but not all
3842// media sections, the answer will change the ufrag/password in the correct
3843// media sections.
3844TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3845 Init();
3846 cricket::MediaSessionOptions options;
3847 options.recv_video = true;
3848 options.recv_audio = true;
3849 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003850 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003851
3852 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3853 "aaaaaaaaaaaaaaaaaaaaaa");
3854 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3855 "bbbbbbbbbbbbbbbbbbbbbb");
3856 SetRemoteDescriptionWithoutError(offer.release());
3857
3858 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003859 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003860 SetLocalDescriptionWithoutError(answer.release());
3861
3862 // Receive an offer with new ufrag and password, but only for the video media
3863 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003864 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003865 CreateRemoteOffer(options, session_->remote_description()));
3866 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3867 "cccccccccccccccccccccc");
3868 SetRemoteDescriptionWithoutError(updated_offer.release());
3869
kwibergd1fe2812016-04-27 06:47:29 -07003870 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003871
3872 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3873 session_->local_description()->description(),
3874 cricket::MEDIA_TYPE_AUDIO));
3875
3876 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3877 session_->local_description()->description(),
3878 cricket::MEDIA_TYPE_VIDEO));
3879
3880 SetLocalDescriptionWithoutError(updated_answer.release());
3881}
3882
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003883TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003884 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003885 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003886 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003887 const std::string session_id_orig = offer->session_id();
3888 const std::string session_version_orig = offer->session_version();
3889 SetLocalDescriptionWithoutError(offer);
3890
3891 video_channel_ = media_engine_->GetVideoChannel(0);
3892 video_channel_->set_fail_set_send_codecs(true);
3893
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003894 SessionDescriptionInterface* answer =
3895 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003896 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003897
3898 // Test that after a content error, setting any description will
3899 // result in an error.
3900 video_channel_->set_fail_set_send_codecs(false);
3901 answer = CreateRemoteAnswer(session_->local_description());
3902 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3903 offer = CreateRemoteOffer();
3904 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003905}
3906
3907// Runs the loopback call test with BUNDLE and STUN disabled.
3908TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3909 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003910 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003911 cricket::PORTALLOCATOR_DISABLE_STUN |
3912 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003913 TestLoopbackCall();
3914}
3915
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003916TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003917 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003918 cricket::PORTALLOCATOR_DISABLE_STUN |
3919 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3920 cricket::PORTALLOCATOR_DISABLE_RELAY);
3921
3922 // best connection is IPv6 since it has higher network preference.
3923 LoopbackNetworkConfiguration config;
3924 config.test_ipv6_network_ = true;
3925 config.best_connection_after_initial_ice_converged_ =
3926 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3927
3928 TestLoopbackCall(config);
3929}
3930
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003931// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003932TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003933 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3934 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003935 TestLoopbackCall();
3936}
3937
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003938TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003939 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003940 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003941 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003942 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003943 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3944}
3945
Henrik Boström87713d02015-08-25 09:53:21 +02003946TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003947 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003948
htaa2a49d92016-03-04 02:51:39 -08003949 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003950 options_.disable_sctp_data_channels = false;
3951
Henrik Boström87713d02015-08-25 09:53:21 +02003952 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003953
3954 SetLocalDescriptionWithDataChannel();
3955 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3956}
3957
Henrik Boström87713d02015-08-25 09:53:21 +02003958TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003959 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003960
Henrik Boström87713d02015-08-25 09:53:21 +02003961 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003962
kwibergd1fe2812016-04-27 06:47:29 -07003963 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003964 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003965 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3966}
3967
Henrik Boström87713d02015-08-25 09:53:21 +02003968TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003969 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003970 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003971 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003972
3973 // Create remote offer with SCTP.
3974 cricket::MediaSessionOptions options;
3975 options.data_channel_type = cricket::DCT_SCTP;
3976 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003977 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003978 SetRemoteDescriptionWithoutError(offer);
3979
3980 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003981 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003982 EXPECT_TRUE(answer != NULL);
3983 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3984 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003985}
3986
Henrik Boström87713d02015-08-25 09:53:21 +02003987TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003988 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003989 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003990
3991 SetLocalDescriptionWithDataChannel();
3992 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3993}
3994
Henrik Boström87713d02015-08-25 09:53:21 +02003995TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003996 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003997
Henrik Boström87713d02015-08-25 09:53:21 +02003998 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003999
4000 SetLocalDescriptionWithDataChannel();
4001 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4002}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004003
Henrik Boström87713d02015-08-25 09:53:21 +02004004TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004005 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00004006 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02004007 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004008
4009 SetLocalDescriptionWithDataChannel();
4010 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
4011}
4012
Henrik Boström87713d02015-08-25 09:53:21 +02004013TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004014 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004015 const int new_send_port = 9998;
4016 const int new_recv_port = 7775;
4017
Henrik Boström87713d02015-08-25 09:53:21 +02004018 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004019 SetFactoryDtlsSrtp();
4020
4021 // By default, don't actually add the codecs to desc_factory_; they don't
4022 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
4023 // let the session description get parsed. That'll get the proper codecs
4024 // into the stream.
4025 cricket::MediaSessionOptions options;
4026 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
4027 "stream1", new_send_port, options);
4028
4029 // SetRemoteDescription will take the ownership of the offer.
4030 SetRemoteDescriptionWithoutError(offer);
4031
htaa2a49d92016-03-04 02:51:39 -08004032 SessionDescriptionInterface* answer =
4033 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004034 ASSERT_TRUE(answer != NULL);
4035
4036 // Now set the local description, which'll take ownership of the answer.
4037 SetLocalDescriptionWithoutError(answer);
4038
4039 // TEST PLAN: Set the port number to something new, set it in the SDP,
4040 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004041 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07004042 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004043
4044 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
4045 int portnum = -1;
4046 ASSERT_TRUE(ch != NULL);
4047 ASSERT_EQ(1UL, ch->send_codecs().size());
4048 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004049 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004050 ch->send_codecs()[0].name.c_str()));
4051 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
4052 &portnum));
4053 EXPECT_EQ(new_send_port, portnum);
4054
4055 ASSERT_EQ(1UL, ch->recv_codecs().size());
4056 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004057 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004058 ch->recv_codecs()[0].name.c_str()));
4059 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
4060 &portnum));
4061 EXPECT_EQ(new_recv_port, portnum);
4062}
4063
deadbeefab9b2d12015-10-14 11:33:11 -07004064// Verifies that when a session's DataChannel receives an OPEN message,
4065// WebRtcSession signals the DataChannel creation request with the expected
4066// config.
4067TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
4068 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4069
4070 InitWithDtls(GetParam());
4071
4072 SetLocalDescriptionWithDataChannel();
4073 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4074
4075 webrtc::DataChannelInit config;
4076 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004077 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004078 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4079 cricket::ReceiveDataParams params;
4080 params.ssrc = config.id;
4081 params.type = cricket::DMT_CONTROL;
4082
4083 cricket::DataChannel* data_channel = session_->data_channel();
4084 data_channel->SignalDataReceived(data_channel, params, payload);
4085
4086 EXPECT_EQ("a", last_data_channel_label_);
4087 EXPECT_EQ(config.id, last_data_channel_config_.id);
4088 EXPECT_FALSE(last_data_channel_config_.negotiated);
4089 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4090 last_data_channel_config_.open_handshake_role);
4091}
4092
4093TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004094 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
4095 FakeDtlsIdentityStore::GenerateCertificate();
4096
htaa2a49d92016-03-04 02:51:39 -08004097 configuration_.certificates.push_back(certificate);
4098 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004099 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4100
4101 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4102}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004103
Henrik Boström87713d02015-08-25 09:53:21 +02004104// Verifies that CreateOffer succeeds when CreateOffer is called before async
4105// identity generation is finished (even if a certificate is provided this is
4106// an async op).
4107TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4108 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4109 InitWithDtls(GetParam());
4110
Henrik Boströmd8281982015-08-27 10:12:24 +02004111 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004112 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004113 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004114
wu@webrtc.org91053e72013-08-10 07:18:04 +00004115 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004116 VerifyNoCryptoParams(offer->description(), true);
4117 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004118}
4119
4120// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004121// identity generation is finished (even if a certificate is provided this is
4122// an async op).
4123TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004124 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004125 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004126 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004127
4128 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004129 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004130 std::unique_ptr<JsepSessionDescription> offer(
4131 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004132 ASSERT_TRUE(offer.get() != NULL);
4133 SetRemoteDescriptionWithoutError(offer.release());
4134
kwibergd1fe2812016-04-27 06:47:29 -07004135 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004136 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004137 VerifyNoCryptoParams(answer->description(), true);
4138 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004139}
4140
4141// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004142// identity generation is finished (even if a certificate is provided this is
4143// an async op).
4144TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004145 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004146 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004147
Henrik Boströmd8281982015-08-27 10:12:24 +02004148 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004149
kwibergd1fe2812016-04-27 06:47:29 -07004150 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004151 EXPECT_TRUE(offer != NULL);
4152}
4153
4154// Verifies that CreateOffer fails when CreateOffer is called after async
4155// identity generation fails.
4156TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004157 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004158 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004159
Henrik Boströmd8281982015-08-27 10:12:24 +02004160 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004161
kwibergd1fe2812016-04-27 06:47:29 -07004162 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004163 EXPECT_TRUE(offer == NULL);
4164}
4165
4166// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4167// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004168TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004169 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004170 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004171 VerifyMultipleAsyncCreateDescription(GetParam(),
4172 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004173}
4174
4175// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4176// before async identity generation fails.
4177TEST_F(WebRtcSessionTest,
4178 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004179 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004180 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4181 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004182}
4183
4184// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4185// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004186TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004187 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004188 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004189 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004190 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004191}
4192
4193// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4194// before async identity generation fails.
4195TEST_F(WebRtcSessionTest,
4196 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004197 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004198 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4199 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004200}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004201
4202// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4203// offer has no SDES crypto but only DTLS fingerprint.
4204TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4205 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004206 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004207 // Create a remote offer with secured transport disabled.
4208 cricket::MediaSessionOptions options;
4209 JsepSessionDescription* offer(CreateRemoteOffer(
4210 options, cricket::SEC_DISABLED));
4211 // Adds a DTLS fingerprint to the remote offer.
4212 cricket::SessionDescription* sdp = offer->description();
4213 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4214 ASSERT_TRUE(audio != NULL);
4215 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4216 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004217 rtc::SSLFingerprint::CreateFromRfc4572(
4218 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004219 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004220 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004221}
4222
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004223TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004224 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004225 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004226 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004227 SessionDescriptionInterface* offer = CreateOffer();
4228
4229 SetLocalDescriptionWithoutError(offer);
4230
4231 voice_channel_ = media_engine_->GetVoiceChannel(0);
4232
4233 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004234 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004235 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004236}
4237
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004238// Tests that we can renegotiate new media content with ICE candidates in the
4239// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004240TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004241 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004242 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004243 SetFactoryDtlsSrtp();
4244
deadbeefab9b2d12015-10-14 11:33:11 -07004245 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004246 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004247 SetLocalDescriptionWithoutError(offer);
4248
4249 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4250 SetRemoteDescriptionWithoutError(answer);
4251
4252 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004253 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004254 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4255
4256 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004257 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004258 candidate1.set_component(1);
4259 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4260 candidate1);
4261 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4262 SetRemoteDescriptionWithoutError(offer);
4263
htaa2a49d92016-03-04 02:51:39 -08004264 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004265 SetLocalDescriptionWithoutError(answer);
4266}
4267
4268// Tests that we can renegotiate new media content with ICE candidates separated
4269// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004270TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004271 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004272 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004273 SetFactoryDtlsSrtp();
4274
deadbeefab9b2d12015-10-14 11:33:11 -07004275 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004276 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004277 SetLocalDescriptionWithoutError(offer);
4278
4279 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4280 SetRemoteDescriptionWithoutError(answer);
4281
4282 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004283 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004284 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4285 SetRemoteDescriptionWithoutError(offer);
4286
4287 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004288 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004289 candidate1.set_component(1);
4290 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4291 candidate1);
4292 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4293
htaa2a49d92016-03-04 02:51:39 -08004294 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004295 SetLocalDescriptionWithoutError(answer);
4296}
honghaiz7f777492016-02-02 21:54:01 -08004297
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004298// Tests that RTX codec is removed from the answer when it isn't supported
4299// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004300TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004301 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004302 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004303 std::string offer_sdp(kSdpWithRtx);
4304
4305 SessionDescriptionInterface* offer =
4306 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4307 EXPECT_TRUE(offer->ToString(&offer_sdp));
4308
4309 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004310 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004311 SetRemoteDescriptionWithoutError(offer);
4312
htaa2a49d92016-03-04 02:51:39 -08004313 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004314 // Answer SDP does not contain the RTX codec.
4315 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004316 SetLocalDescriptionWithoutError(answer);
4317}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004318
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004319// This verifies that the voice channel after bundle has both options from video
4320// and voice channels.
4321TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4322 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004323 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004324
4325 PeerConnectionInterface::RTCOfferAnswerOptions options;
4326 options.use_rtp_mux = true;
4327
4328 SessionDescriptionInterface* offer = CreateOffer(options);
4329 SetLocalDescriptionWithoutError(offer);
4330
4331 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4332 rtc::Socket::Option::OPT_SNDBUF, 4000);
4333
4334 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4335 rtc::Socket::Option::OPT_RCVBUF, 8000);
4336
4337 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004338 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004339 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4340 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004341 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004342 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4343
deadbeefcbecd352015-09-23 11:50:27 -07004344 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004345 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4346 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004347 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004348 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4349
deadbeefcbecd352015-09-23 11:50:27 -07004350 EXPECT_NE(session_->voice_rtp_transport_channel(),
4351 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004352
deadbeefab9b2d12015-10-14 11:33:11 -07004353 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004354 SessionDescriptionInterface* answer =
4355 CreateRemoteAnswer(session_->local_description());
4356 SetRemoteDescriptionWithoutError(answer);
4357
deadbeefcbecd352015-09-23 11:50:27 -07004358 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004359 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4360 EXPECT_EQ(4000, option_val);
4361
deadbeefcbecd352015-09-23 11:50:27 -07004362 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004363 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4364 EXPECT_EQ(8000, option_val);
4365}
4366
tommi0f620f42015-07-09 03:25:02 -07004367// Test creating a session, request multiple offers, destroy the session
4368// and make sure we got success/failure callbacks for all of the requests.
4369// Background: crbug.com/507307
4370TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4371 Init();
4372
4373 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4374 PeerConnectionInterface::RTCOfferAnswerOptions options;
4375 options.offer_to_receive_audio =
4376 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004377 cricket::MediaSessionOptions session_options;
4378 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004379
4380 for (auto& o : observers) {
4381 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004382 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004383 }
4384
4385 session_.reset();
4386
tommi0f620f42015-07-09 03:25:02 -07004387 for (auto& o : observers) {
4388 // We expect to have received a notification now even if the session was
4389 // terminated. The offer creation may or may not have succeeded, but we
4390 // must have received a notification which, so the only invalid state
4391 // is kInit.
4392 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4393 }
4394}
4395
stefanc1aeaf02015-10-15 07:26:07 -07004396TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4397 TestPacketOptions();
4398}
4399
deadbeef057ecf02016-01-20 14:30:43 -08004400// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4401// is destroyed.
4402TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4403 Init();
4404 session_.reset();
4405 EXPECT_TRUE(session_destroyed_);
4406}
4407
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004408// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4409// currently fails because upon disconnection and reconnection OnIceComplete is
4410// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004411
deadbeefcbecd352015-09-23 11:50:27 -07004412INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4413 WebRtcSessionTest,
4414 testing::Values(ALREADY_GENERATED,
4415 DTLS_IDENTITY_STORE));