blob: 24e830eed9ee201a822fa39ea2224bc6a09579f7 [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(
194 const std::vector<cricket::Candidate>& candidates) {
195 num_candidates_removed_ += candidates.size();
196 }
197
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 bool oncandidatesready_;
199 std::vector<cricket::Candidate> mline_0_candidates_;
200 std::vector<cricket::Candidate> mline_1_candidates_;
201 PeerConnectionInterface::IceConnectionState ice_connection_state_;
202 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
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
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001116 // Helper class to configure loopback network and verify Best
1117 // Connection using right IP protocol for TestLoopbackCall
1118 // method. LoopbackNetworkManager applies firewall rules to block
1119 // all ping traffic once ICE completed, and remove them to observe
1120 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1121 // verifies the best connection is using the right IP protocol after
1122 // initial ICE convergences.
1123
1124 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001125 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001126 LoopbackNetworkConfiguration()
1127 : test_ipv6_network_(false),
1128 test_extra_ipv4_network_(false),
1129 best_connection_after_initial_ice_converged_(1, 0) {}
1130
1131 // Used to track the expected best connection count in each IP protocol.
1132 struct ExpectedBestConnection {
1133 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1134 : ipv4_count_(ipv4_count),
1135 ipv6_count_(ipv6_count) {}
1136
1137 int ipv4_count_;
1138 int ipv6_count_;
1139 };
1140
1141 bool test_ipv6_network_;
1142 bool test_extra_ipv4_network_;
1143 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1144
1145 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001146 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001147 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1148 }
1149
1150 private:
jbauchac8869e2015-07-03 01:36:14 -07001151 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001152 const ExpectedBestConnection& expected) const {
1153 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001154 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1155 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001156 expected.ipv4_count_);
1157 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001158 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1159 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001160 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001161 // This is used in the loopback call so there is only single host to host
1162 // candidate pair.
1163 EXPECT_EQ(metrics_observer->GetEnumCounter(
1164 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1165 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001166 0);
1167 EXPECT_EQ(metrics_observer->GetEnumCounter(
1168 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1169 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001170 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001171 }
1172 };
1173
1174 class LoopbackNetworkManager {
1175 public:
1176 LoopbackNetworkManager(WebRtcSessionTest* session,
1177 const LoopbackNetworkConfiguration& config)
1178 : config_(config) {
1179 session->AddInterface(
1180 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1181 if (config_.test_extra_ipv4_network_) {
1182 session->AddInterface(
1183 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1184 }
1185 if (config_.test_ipv6_network_) {
1186 session->AddInterface(
1187 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1188 }
1189 }
1190
1191 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1192 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1193 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1194 if (config_.test_extra_ipv4_network_) {
1195 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1196 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1197 }
1198 if (config_.test_ipv6_network_) {
1199 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1200 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1201 }
1202 }
1203
1204 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1205
1206 private:
1207 LoopbackNetworkConfiguration config_;
1208 };
1209
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001210 // The method sets up a call from the session to itself, in a loopback
1211 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001212 // disconnection, and then a permanent disconnection.
1213 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001214 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1215 // While running the call, this method also checks if the session goes through
1216 // the correct sequence of ICE states when a connection is established,
1217 // broken, and re-established.
1218 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001219 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1220 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001221 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001222
stefanc1aeaf02015-10-15 07:26:07 -07001223 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001224 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001225 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001226 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001227
1228 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1229 observer_.ice_gathering_state_);
1230 SetLocalDescriptionWithoutError(offer);
1231 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1232 observer_.ice_connection_state_);
1233 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001234 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1236 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001237 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001238
1239 std::string sdp;
1240 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001241 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1242 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001243 ASSERT_TRUE(desc != NULL);
1244 SetRemoteDescriptionWithoutError(desc);
1245
1246 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001247 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001248
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001249 // The ice connection state is "Connected" too briefly to catch in a test.
1250 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001251 observer_.ice_connection_state_, kIceCandidatesTimeout);
1252 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001253
stefanc1aeaf02015-10-15 07:26:07 -07001254 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1255 LoopbackNetworkManager loopback_network_manager(this, config);
1256 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001257 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258 // Adding firewall rule to block ping requests, which should cause
1259 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001260
1261 loopback_network_manager.ApplyFirewallRules(fss_.get());
1262
1263 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1265 observer_.ice_connection_state_,
1266 kIceCandidatesTimeout);
1267
jbauchac8869e2015-07-03 01:36:14 -07001268 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001269
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001271 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001273 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001274 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 observer_.ice_connection_state_,
1276 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001277
1278 // Now we block ping requests and wait until the ICE connection transitions
1279 // to the Failed state. This will take at least 30 seconds because it must
1280 // wait for the Port to timeout.
1281 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001282
1283 loopback_network_manager.ApplyFirewallRules(fss_.get());
1284 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001285 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001286 observer_.ice_connection_state_,
1287 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 }
1289
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001290 void TestLoopbackCall() {
1291 LoopbackNetworkConfiguration config;
1292 TestLoopbackCall(config);
1293 }
1294
stefanc1aeaf02015-10-15 07:26:07 -07001295 void TestPacketOptions() {
1296 media_controller_.reset(
1297 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1298 LoopbackNetworkConfiguration config;
1299 LoopbackNetworkManager loopback_network_manager(this, config);
1300
1301 SetupLoopbackCall();
1302
1303 uint8_t test_packet[15] = {0};
1304 rtc::PacketOptions options;
1305 options.packet_id = 10;
1306 media_engine_->GetVideoChannel(0)
1307 ->SendRtp(test_packet, sizeof(test_packet), options);
1308
1309 const int kPacketTimeout = 2000;
1310 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1311 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1312 }
1313
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1315 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001316 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1317 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001318
1319 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1321 codecs.push_back(kCNCodec1);
1322 codecs.push_back(kCNCodec2);
1323 media_engine_->SetAudioCodecs(codecs);
1324 desc_factory_->set_audio_codecs(codecs);
1325 }
1326
1327 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1328 const cricket::ContentDescription* description = content->description;
1329 ASSERT(description != NULL);
1330 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001331 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001332 ASSERT(audio_content_desc != NULL);
1333 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1334 if (audio_content_desc->codecs()[i].name == "CN")
1335 return false;
1336 }
1337 return true;
1338 }
1339
deadbeefab9b2d12015-10-14 11:33:11 -07001340 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001341 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001342 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001343 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1344 data_channel_ = DataChannel::Create(
1345 session_.get(), session_->data_channel_type(), "datachannel", dci);
1346 }
1347
1348 void SetLocalDescriptionWithDataChannel() {
1349 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001350 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001351 SetLocalDescriptionWithoutError(offer);
1352 }
1353
wu@webrtc.org91053e72013-08-10 07:18:04 +00001354 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001355 RTCCertificateGenerationMethod cert_gen_method,
1356 CreateSessionDescriptionRequest::Type type) {
1357 InitWithDtls(cert_gen_method);
1358 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1359 }
1360
1361 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1362 CreateSessionDescriptionRequest::Type type) {
1363 InitWithDtlsIdentityGenFail();
1364 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1365 }
1366
1367 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001368 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001369 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001370 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001371 if (type == CreateSessionDescriptionRequest::kAnswer) {
1372 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001373 std::unique_ptr<JsepSessionDescription> offer(
1374 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001375 ASSERT_TRUE(offer.get() != NULL);
1376 SetRemoteDescriptionWithoutError(offer.release());
1377 }
1378
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001379 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001380 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001381 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001382 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001383 observers[kNumber];
1384 for (int i = 0; i < kNumber; ++i) {
1385 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1386 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001387 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001388 } else {
htaa2a49d92016-03-04 02:51:39 -08001389 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001390 }
1391 }
1392
1393 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1394 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1395 WebRtcSessionCreateSDPObserverForTest::kFailed;
1396
1397 for (int i = 0; i < kNumber; ++i) {
1398 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1399 if (success) {
1400 EXPECT_TRUE(observers[i]->description() != NULL);
1401 } else {
1402 EXPECT_TRUE(observers[i]->description() == NULL);
1403 }
1404 }
1405 }
1406
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001407 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001408 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001409 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001410 turn_server.credentials = credentials;
1411 turn_server.ports.push_back(
1412 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1413 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001414 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001415 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001416 }
1417
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001418 cricket::FakeMediaEngine* media_engine_;
1419 cricket::FakeDataEngine* data_engine_;
kwibergd1fe2812016-04-27 06:47:29 -07001420 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001421 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001422 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1423 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1424 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1425 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1426 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1427 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001428 rtc::SocketServerScope ss_scope_;
1429 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001430 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001431 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001432 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001433 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001434 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001435 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001436 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001437 MockIceObserver observer_;
1438 cricket::FakeVideoMediaChannel* video_channel_;
1439 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001440 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001441 // The following flags affect options created for CreateOffer/CreateAnswer.
1442 bool send_stream_1_ = false;
1443 bool send_stream_2_ = false;
1444 bool send_audio_ = false;
1445 bool send_video_ = false;
1446 rtc::scoped_refptr<DataChannel> data_channel_;
1447 // Last values received from data channel creation signal.
1448 std::string last_data_channel_label_;
1449 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001450 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451};
1452
Henrik Boström87713d02015-08-25 09:53:21 +02001453TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1454 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001455 // SDES is disabled when DTLS is on.
1456 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001457}
1458
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001459TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001460 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001461 // SDES is required if DTLS is off.
1462 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001463}
1464
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1466 TestSessionCandidatesWithBundleRtcpMux(false, false);
1467}
1468
1469// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1470// with rtcp-mux and/or bundle.
1471TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1472 TestSessionCandidatesWithBundleRtcpMux(false, true);
1473}
1474
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1476 TestSessionCandidatesWithBundleRtcpMux(true, true);
1477}
1478
1479TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001480 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1481 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001482 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001483 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001484 InitiateCall();
1485 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1486 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1487 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1488}
1489
minyuec8930ba2016-01-22 06:17:46 -08001490// Crashes on Win only. See webrtc:5411.
1491#if defined(WEBRTC_WIN)
1492#define MAYBE_TestStunError DISABLED_TestStunError
1493#else
1494#define MAYBE_TestStunError TestStunError
1495#endif
1496TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001497 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1498 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001499 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001500 rtc::FP_UDP,
1501 rtc::FD_ANY,
1502 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001503 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001504 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001505 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001506 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1508 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1509 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1510}
1511
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001512// Test session delivers no candidates gathered when constraint set to "none".
1513TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1514 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001515 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001516 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001517 InitiateCall();
1518 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1519 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1520 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1521}
1522
1523// Test session delivers only relay candidates gathered when constaint set to
1524// "relay".
1525TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1526 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1527 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001528 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001529 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001530 InitiateCall();
1531 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1532 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1533 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1534 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1535 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1536 observer_.mline_0_candidates_[i].type());
1537 }
1538 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1539 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1540 observer_.mline_1_candidates_[i].type());
1541 }
1542}
1543
1544// Test session delivers all candidates gathered when constaint set to "all".
1545TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1546 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001547 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001548 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001549 InitiateCall();
1550 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1551 // Host + STUN. By default allocator is disabled to gather relay candidates.
1552 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1553 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1554}
1555
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001556TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001557 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001558 SessionDescriptionInterface* offer = NULL;
1559 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1560 std::string unknown_action;
1561 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1562 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1563}
1564
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565// Test creating offers and receive answers and make sure the
1566// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001567TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001568 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001569 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001570 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 const std::string session_id_orig = offer->session_id();
1572 const std::string session_version_orig = offer->session_version();
1573 SetLocalDescriptionWithoutError(offer);
1574
deadbeefab9b2d12015-10-14 11:33:11 -07001575 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 SessionDescriptionInterface* answer =
1577 CreateRemoteAnswer(session_->local_description());
1578 SetRemoteDescriptionWithoutError(answer);
1579
1580 video_channel_ = media_engine_->GetVideoChannel(0);
1581 voice_channel_ = media_engine_->GetVoiceChannel(0);
1582
1583 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1584 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1585
1586 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1587 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1588
1589 ASSERT_EQ(1u, video_channel_->send_streams().size());
1590 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1591 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1592 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1593
1594 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001595 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001596 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597
1598 // Verify the session id is the same and the session version is
1599 // increased.
1600 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001601 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1602 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603
1604 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001605 EXPECT_EQ(0u, video_channel_->send_streams().size());
1606 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607
deadbeefab9b2d12015-10-14 11:33:11 -07001608 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001609 answer = CreateRemoteAnswer(session_->local_description());
1610 SetRemoteDescriptionWithoutError(answer);
1611
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 // Make sure the receive streams have not changed.
1613 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1614 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1615 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1616 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1617}
1618
1619// Test receiving offers and creating answers and make sure the
1620// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001621TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001622 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001623 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001624 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001625 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 SetRemoteDescriptionWithoutError(offer);
1627
deadbeefab9b2d12015-10-14 11:33:11 -07001628 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001629 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001630 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 SetLocalDescriptionWithoutError(answer);
1632
1633 const std::string session_id_orig = answer->session_id();
1634 const std::string session_version_orig = answer->session_version();
1635
1636 video_channel_ = media_engine_->GetVideoChannel(0);
1637 voice_channel_ = media_engine_->GetVoiceChannel(0);
1638
htaa2a49d92016-03-04 02:51:39 -08001639 ASSERT_TRUE(video_channel_);
1640 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1642 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1643
1644 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1645 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1646
1647 ASSERT_EQ(1u, video_channel_->send_streams().size());
1648 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1649 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1650 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1651
deadbeefab9b2d12015-10-14 11:33:11 -07001652 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001653 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 SetRemoteDescriptionWithoutError(offer);
1655
1656 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001657 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001658 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659
1660 // Verify the session id is the same and the session version is
1661 // increased.
1662 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001663 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1664 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 SetLocalDescriptionWithoutError(answer);
1666
1667 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1668 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1669 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1670 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1671 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1672 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1673
1674 // Make sure we have no send streams.
1675 EXPECT_EQ(0u, video_channel_->send_streams().size());
1676 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1677}
1678
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001679TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001680 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001681 media_engine_->set_fail_create_channel(true);
1682
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001683 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001684 ASSERT_TRUE(offer != NULL);
1685 // SetRemoteDescription and SetLocalDescription will take the ownership of
1686 // the offer.
1687 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001688 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001689 ASSERT_TRUE(offer != NULL);
1690 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1691}
1692
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001693//
1694// Tests for creating/setting SDP under different SDES/DTLS polices:
1695//
1696// --DTLS off and SDES on
1697// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1698// set local/remote offer/answer with crypto --> success
1699// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1700// failure
1701// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1702// failure
1703// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1704// failure
1705//
1706// --DTLS on and SDES off
1707// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1708// set local/remote offer/answer with DTLS fingerprint --> success
1709// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1710// fingerprint --> failure
1711// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1712// --> failure
1713// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1714// --> failure
1715//
1716// --Encryption disabled: DTLS off and SDES off
1717// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1718// answer without SDES or DTLS --> success
1719// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1720// answer without SDES or DTLS --> success
1721//
1722
1723// Test that we return a failure when applying a remote/local offer that doesn't
1724// have cryptos enabled when DTLS is off.
1725TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001726 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001728 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729 JsepSessionDescription* offer = CreateRemoteOffer(
1730 options, cricket::SEC_DISABLED);
1731 ASSERT_TRUE(offer != NULL);
1732 VerifyNoCryptoParams(offer->description(), false);
1733 // SetRemoteDescription and SetLocalDescription will take the ownership of
1734 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001735 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1737 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001738 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739}
1740
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001741// Test that we return a failure when applying a local answer that doesn't have
1742// cryptos enabled when DTLS is off.
1743TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001744 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 SessionDescriptionInterface* offer = NULL;
1746 SessionDescriptionInterface* answer = NULL;
1747 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1748 // SetRemoteDescription and SetLocalDescription will take the ownership of
1749 // the offer.
1750 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001751 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752}
1753
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001754// Test we will return fail when apply an remote answer that doesn't have
1755// crypto enabled when DTLS is off.
1756TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001757 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 SessionDescriptionInterface* offer = NULL;
1759 SessionDescriptionInterface* answer = NULL;
1760 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1761 // SetRemoteDescription and SetLocalDescription will take the ownership of
1762 // the offer.
1763 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001764 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765}
1766
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001767// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1768// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001769TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001770 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001771 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001772 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773 SetFactoryDtlsSrtp();
1774 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001775 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001776 JsepSessionDescription* offer =
1777 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 ASSERT_TRUE(offer != NULL);
1779 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001780 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781
1782 // SetRemoteDescription will take the ownership of the offer.
1783 SetRemoteDescriptionWithoutError(offer);
1784
1785 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001786 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 ASSERT_TRUE(answer != NULL);
1788 VerifyFingerprintStatus(answer->description(), true);
1789 // Check that we don't have an a=crypto line in the answer.
1790 VerifyNoCryptoParams(answer->description(), true);
1791
1792 // Now set the local description, which should work, even without a=crypto.
1793 SetLocalDescriptionWithoutError(answer);
1794}
1795
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001796// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1797// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001798TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001799 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001800 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001801 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001802 SetFactoryDtlsSrtp();
1803
1804 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001805 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001806 ASSERT_TRUE(offer != NULL);
1807 VerifyFingerprintStatus(offer->description(), true);
1808 // Check that we don't have an a=crypto line in the offer.
1809 VerifyNoCryptoParams(offer->description(), true);
1810
1811 // Now set the local description, which should work, even without a=crypto.
1812 SetLocalDescriptionWithoutError(offer);
1813
1814 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001815 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001816 JsepSessionDescription* answer =
1817 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1818 ASSERT_TRUE(answer != NULL);
1819 VerifyFingerprintStatus(answer->description(), true);
1820 VerifyNoCryptoParams(answer->description(), true);
1821
1822 // SetRemoteDescription will take the ownership of the answer.
1823 SetRemoteDescriptionWithoutError(answer);
1824}
1825
1826// Test that if we support DTLS and the other side didn't offer a fingerprint,
1827// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001828TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001829 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001830 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001832 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001833 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001834 JsepSessionDescription* offer = CreateRemoteOffer(
1835 options, cricket::SEC_REQUIRED);
1836 ASSERT_TRUE(offer != NULL);
1837 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001838 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001840 // SetRemoteDescription will take the ownership of the offer.
1841 SetRemoteDescriptionOfferExpectError(
1842 kSdpWithoutDtlsFingerprint, offer);
1843
1844 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1845 // SetLocalDescription will take the ownership of the offer.
1846 SetLocalDescriptionOfferExpectError(
1847 kSdpWithoutDtlsFingerprint, offer);
1848}
1849
1850// Test that we return a failure when applying a local answer that doesn't have
1851// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001852TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001853 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001854 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001855 SessionDescriptionInterface* offer = NULL;
1856 SessionDescriptionInterface* answer = NULL;
1857 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1858
1859 // SetRemoteDescription and SetLocalDescription will take the ownership of
1860 // the offer and answer.
1861 SetRemoteDescriptionWithoutError(offer);
1862 SetLocalDescriptionAnswerExpectError(
1863 kSdpWithoutDtlsFingerprint, answer);
1864}
1865
1866// Test that we return a failure when applying a remote answer that doesn't have
1867// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001868TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001869 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001870 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001871 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001872 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001873 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001874 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001875 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001876 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001877 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001878
1879 // SetRemoteDescription and SetLocalDescription will take the ownership of
1880 // the offer and answer.
1881 SetLocalDescriptionWithoutError(offer);
1882 SetRemoteDescriptionAnswerExpectError(
1883 kSdpWithoutDtlsFingerprint, answer);
1884}
1885
1886// Test that we create a local offer without SDES or DTLS and accept a remote
1887// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001888TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001889 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001890 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001891 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001892
1893 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001894 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001895 ASSERT_TRUE(offer != NULL);
1896 VerifyFingerprintStatus(offer->description(), false);
1897 // Check that we don't have an a=crypto line in the offer.
1898 VerifyNoCryptoParams(offer->description(), false);
1899
1900 // Now set the local description, which should work, even without a=crypto.
1901 SetLocalDescriptionWithoutError(offer);
1902
1903 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001904 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001905 JsepSessionDescription* answer =
1906 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1907 ASSERT_TRUE(answer != NULL);
1908 VerifyFingerprintStatus(answer->description(), false);
1909 VerifyNoCryptoParams(answer->description(), false);
1910
1911 // SetRemoteDescription will take the ownership of the answer.
1912 SetRemoteDescriptionWithoutError(answer);
1913}
1914
1915// Test that we create a local answer without SDES or DTLS and accept a remote
1916// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001917TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001918 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001919 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001920
1921 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001922 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001923 JsepSessionDescription* offer =
1924 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1925 ASSERT_TRUE(offer != NULL);
1926 VerifyFingerprintStatus(offer->description(), false);
1927 VerifyNoCryptoParams(offer->description(), false);
1928
1929 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930 SetRemoteDescriptionWithoutError(offer);
1931
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001932 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001933 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001934 ASSERT_TRUE(answer != NULL);
1935 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001936 // Check that we don't have an a=crypto line in the answer.
1937 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001938
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001939 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001940 SetLocalDescriptionWithoutError(answer);
1941}
1942
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001943// Test that we can create and set an answer correctly when different
1944// SSL roles have been negotiated for different transports.
1945// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1946TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1947 SendAudioVideoStream1();
1948 InitWithDtls(GetParam());
1949 SetFactoryDtlsSrtp();
1950
1951 SessionDescriptionInterface* offer = CreateOffer();
1952 SetLocalDescriptionWithoutError(offer);
1953
1954 cricket::MediaSessionOptions options;
1955 options.recv_video = true;
1956
1957 // First, negotiate different SSL roles.
1958 SessionDescriptionInterface* answer =
1959 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1960 TransportInfo* audio_transport_info =
1961 answer->description()->GetTransportInfoByName("audio");
1962 audio_transport_info->description.connection_role =
1963 cricket::CONNECTIONROLE_ACTIVE;
1964 TransportInfo* video_transport_info =
1965 answer->description()->GetTransportInfoByName("video");
1966 video_transport_info->description.connection_role =
1967 cricket::CONNECTIONROLE_PASSIVE;
1968 SetRemoteDescriptionWithoutError(answer);
1969
1970 // Now create an offer in the reverse direction, and ensure the initial
1971 // offerer responds with an answer with correct SSL roles.
1972 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1973 kSessionVersion,
1974 session_->remote_description());
1975 SetRemoteDescriptionWithoutError(offer);
1976
htaa2a49d92016-03-04 02:51:39 -08001977 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001978 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1979 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1980 audio_transport_info->description.connection_role);
1981 video_transport_info = answer->description()->GetTransportInfoByName("video");
1982 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1983 video_transport_info->description.connection_role);
1984 SetLocalDescriptionWithoutError(answer);
1985
1986 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1987 // audio is transferred over to video in the answer that completes the BUNDLE
1988 // negotiation.
1989 options.bundle_enabled = true;
1990 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1991 kSessionVersion,
1992 session_->remote_description());
1993 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08001994 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001995 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1996 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1997 audio_transport_info->description.connection_role);
1998 video_transport_info = answer->description()->GetTransportInfoByName("video");
1999 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2000 video_transport_info->description.connection_role);
2001 SetLocalDescriptionWithoutError(answer);
2002}
2003
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002005 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002006 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002007 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002008 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009 SetLocalDescriptionWithoutError(offer);
2010
2011 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002012 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013 SetLocalDescriptionWithoutError(offer2);
2014}
2015
2016TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002017 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002018 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002020 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002021 SetRemoteDescriptionWithoutError(offer);
2022
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002023 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024 SetRemoteDescriptionWithoutError(offer2);
2025}
2026
2027TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002028 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002029 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002030 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002032 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002033 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2034 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035}
2036
2037TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002038 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002039 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002040 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002042 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002043 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002044 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045}
2046
2047TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002048 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002049 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002050 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002051 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052
htaa2a49d92016-03-04 02:51:39 -08002053 JsepSessionDescription* pranswer =
2054 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002056 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057
deadbeefab9b2d12015-10-14 11:33:11 -07002058 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002059 JsepSessionDescription* pranswer2 =
2060 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2062
deadbeefd59daf82015-10-14 15:02:44 -07002063 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064
deadbeefab9b2d12015-10-14 11:33:11 -07002065 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002066 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002067 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068}
2069
2070TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002071 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002072 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002073 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002074 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075
2076 JsepSessionDescription* pranswer =
2077 CreateRemoteAnswer(session_->local_description());
2078 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2079
2080 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002081 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082
deadbeefab9b2d12015-10-14 11:33:11 -07002083 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084 JsepSessionDescription* pranswer2 =
2085 CreateRemoteAnswer(session_->local_description());
2086 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2087
2088 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002089 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090
deadbeefab9b2d12015-10-14 11:33:11 -07002091 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092 SessionDescriptionInterface* answer =
2093 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002094 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095}
2096
2097TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002098 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002099 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002100 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002101
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102 SessionDescriptionInterface* answer =
2103 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002104 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2105 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106}
2107
2108TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002109 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002110 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002111 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002112
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002113 SessionDescriptionInterface* answer =
2114 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002115 SetRemoteDescriptionAnswerExpectError(
2116 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117}
2118
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002119// Tests that the remote candidates are added and removed successfully.
2120TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002121 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002122 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002124 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2125 "", "", "host", 0, "");
2126 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2128
deadbeefd59daf82015-10-14 15:02:44 -07002129 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2131
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002132 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002134
2135 // Fail since we have not set a remote description.
2136 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137
2138 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2139 session_->local_description());
2140 SetRemoteDescriptionWithoutError(answer);
2141
deadbeefd59daf82015-10-14 15:02:44 -07002142 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2143 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002144 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002145 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2146 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2147
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148 // Verifying the candidates are copied properly from internal vector.
2149 const SessionDescriptionInterface* remote_desc =
2150 session_->remote_description();
2151 ASSERT_TRUE(remote_desc != NULL);
2152 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2153 const IceCandidateCollection* candidates =
2154 remote_desc->candidates(kMediaContentIndex0);
2155 ASSERT_EQ(2u, candidates->count());
2156 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2157 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2158 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2159 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2160
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002161 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2162 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 candidate.set_component(2);
2164 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2165 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002166 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167
2168 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2169 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002170
2171 // Remove candidate1 and candidate2
2172 std::vector<cricket::Candidate> remote_candidates;
2173 remote_candidates.push_back(ice_candidate1.candidate());
2174 remote_candidates.push_back(ice_candidate2.candidate());
2175 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2176 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177}
2178
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002179// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180// that it is retained if the remote session description is changed.
2181TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002182 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183 cricket::Candidate candidate1;
2184 candidate1.set_component(1);
2185 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2186 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002187 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002188 CreateAndSetRemoteOfferAndLocalAnswer();
2189
2190 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2191 const SessionDescriptionInterface* remote_desc =
2192 session_->remote_description();
2193 ASSERT_TRUE(remote_desc != NULL);
2194 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2195 const IceCandidateCollection* candidates =
2196 remote_desc->candidates(kMediaContentIndex0);
2197 ASSERT_EQ(1u, candidates->count());
2198 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2199
2200 // Update the RemoteSessionDescription with a new session description and
2201 // a candidate and check that the new remote session description contains both
2202 // candidates.
2203 SessionDescriptionInterface* offer = CreateRemoteOffer();
2204 cricket::Candidate candidate2;
2205 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2206 candidate2);
2207 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2208 SetRemoteDescriptionWithoutError(offer);
2209
2210 remote_desc = session_->remote_description();
2211 ASSERT_TRUE(remote_desc != NULL);
2212 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2213 candidates = remote_desc->candidates(kMediaContentIndex0);
2214 ASSERT_EQ(2u, candidates->count());
2215 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2216 // Username and password have be updated with the TransportInfo of the
2217 // SessionDescription, won't be equal to the original one.
2218 candidate2.set_username(candidates->at(0)->candidate().username());
2219 candidate2.set_password(candidates->at(0)->candidate().password());
2220 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2221 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2222 // No need to verify the username and password.
2223 candidate1.set_username(candidates->at(1)->candidate().username());
2224 candidate1.set_password(candidates->at(1)->candidate().password());
2225 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2226
2227 // Test that the candidate is ignored if we can add the same candidate again.
2228 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2229}
2230
2231// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002232// that they are retained if the local session description is changed. And if
2233// continual gathering is enabled, they are removed from the local session
2234// description when the network is down.
2235TEST_F(WebRtcSessionTest,
2236 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002237 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002238 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002239 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002240 CreateAndSetRemoteOfferAndLocalAnswer();
2241
2242 const SessionDescriptionInterface* local_desc = session_->local_description();
2243 const IceCandidateCollection* candidates =
2244 local_desc->candidates(kMediaContentIndex0);
2245 ASSERT_TRUE(candidates != NULL);
2246 EXPECT_EQ(0u, candidates->count());
2247
2248 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2249
2250 local_desc = session_->local_description();
2251 candidates = local_desc->candidates(kMediaContentIndex0);
2252 ASSERT_TRUE(candidates != NULL);
2253 EXPECT_LT(0u, candidates->count());
2254 candidates = local_desc->candidates(1);
2255 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002256 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257
2258 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002259 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260 CreateAndSetRemoteOfferAndLocalAnswer();
2261
2262 local_desc = session_->local_description();
2263 candidates = local_desc->candidates(kMediaContentIndex0);
2264 ASSERT_TRUE(candidates != NULL);
2265 EXPECT_LT(0u, candidates->count());
2266 candidates = local_desc->candidates(1);
2267 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002268 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002269
2270 candidates = local_desc->candidates(kMediaContentIndex0);
2271 size_t num_local_candidates = candidates->count();
2272 // Enable Continual Gathering
2273 session_->SetIceConfig(cricket::IceConfig(-1, -1, true, false, -1));
2274 // Bring down the network interface to trigger candidate removals.
2275 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2276 // Verify that all local candidates are removed.
2277 EXPECT_EQ(0, observer_.num_candidates_removed_);
2278 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2279 kIceCandidatesTimeout);
2280 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2281}
2282
2283// Tests that if continual gathering is disabled, local candidates won't be
2284// removed when the interface is turned down.
2285TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2286 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2287 Init();
2288 SendAudioVideoStream1();
2289 CreateAndSetRemoteOfferAndLocalAnswer();
2290
2291 const SessionDescriptionInterface* local_desc = session_->local_description();
2292 const IceCandidateCollection* candidates =
2293 local_desc->candidates(kMediaContentIndex0);
2294 ASSERT_TRUE(candidates != NULL);
2295 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2296
2297 size_t num_local_candidates = candidates->count();
2298 EXPECT_LT(0u, num_local_candidates);
2299 // By default, Continual Gathering is disabled.
2300 // Bring down the network interface.
2301 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2302 // Verify that the local candidates are not removed.
2303 rtc::Thread::Current()->ProcessMessages(1000);
2304 EXPECT_EQ(0, observer_.num_candidates_removed_);
2305 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306}
2307
2308// Test that we can set a remote session description with remote candidates.
2309TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002310 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311
2312 cricket::Candidate candidate1;
2313 candidate1.set_component(1);
2314 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2315 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002316 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002317 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318
2319 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2320 SetRemoteDescriptionWithoutError(offer);
2321
2322 const SessionDescriptionInterface* remote_desc =
2323 session_->remote_description();
2324 ASSERT_TRUE(remote_desc != NULL);
2325 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2326 const IceCandidateCollection* candidates =
2327 remote_desc->candidates(kMediaContentIndex0);
2328 ASSERT_EQ(1u, candidates->count());
2329 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2330
htaa2a49d92016-03-04 02:51:39 -08002331 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332 SetLocalDescriptionWithoutError(answer);
2333}
2334
2335// Test that offers and answers contains ice candidates when Ice candidates have
2336// been gathered.
2337TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002338 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002339 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002340 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341 // Ice is started but candidates are not provided until SetLocalDescription
2342 // is called.
2343 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2344 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2345 CreateAndSetRemoteOfferAndLocalAnswer();
2346 // Wait until at least one local candidate has been collected.
2347 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2348 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349
kwibergd1fe2812016-04-27 06:47:29 -07002350 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002351
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2353 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354
2355 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2356 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002357 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2359 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360 SetLocalDescriptionWithoutError(answer);
2361}
2362
2363// Verifies TransportProxy and media channels are created with content names
2364// present in the SessionDescription.
2365TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002366 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002367 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002368 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369
2370 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002371 // "video". Goal is to modify these content names and verify transport
2372 // channels
2373 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374 // present in SDP.
2375 std::string sdp;
2376 EXPECT_TRUE(offer->ToString(&sdp));
2377 const std::string kAudioMid = "a=mid:audio";
2378 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2379 const std::string kVideoMid = "a=mid:video";
2380 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2381
2382 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002383 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384 kAudioMidReplaceStr.c_str(),
2385 kAudioMidReplaceStr.length(),
2386 &sdp);
2387 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002388 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389 kVideoMidReplaceStr.c_str(),
2390 kVideoMidReplaceStr.length(),
2391 &sdp);
2392
2393 SessionDescriptionInterface* modified_offer =
2394 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2395
2396 SetRemoteDescriptionWithoutError(modified_offer);
2397
htaa2a49d92016-03-04 02:51:39 -08002398 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399 SetLocalDescriptionWithoutError(answer);
2400
deadbeefcbecd352015-09-23 11:50:27 -07002401 cricket::TransportChannel* voice_transport_channel =
2402 session_->voice_rtp_transport_channel();
2403 EXPECT_TRUE(voice_transport_channel != NULL);
2404 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2405 cricket::TransportChannel* video_transport_channel =
2406 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002407 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002408 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2410 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2411}
2412
2413// Test that an offer contains the correct media content descriptions based on
2414// the send streams when no constraints have been set.
2415TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002416 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002417 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002418
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419 ASSERT_TRUE(offer != NULL);
2420 const cricket::ContentInfo* content =
2421 cricket::GetFirstAudioContent(offer->description());
2422 EXPECT_TRUE(content != NULL);
2423 content = cricket::GetFirstVideoContent(offer->description());
2424 EXPECT_TRUE(content == NULL);
2425}
2426
2427// Test that an offer contains the correct media content descriptions based on
2428// the send streams when no constraints have been set.
2429TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002430 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002432 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002433 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002434
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435 const cricket::ContentInfo* content =
2436 cricket::GetFirstAudioContent(offer->description());
2437 EXPECT_TRUE(content != NULL);
2438 content = cricket::GetFirstVideoContent(offer->description());
2439 EXPECT_TRUE(content == NULL);
2440
2441 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002442 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002443 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444 content = cricket::GetFirstAudioContent(offer->description());
2445 EXPECT_TRUE(content != NULL);
2446 content = cricket::GetFirstVideoContent(offer->description());
2447 EXPECT_TRUE(content != NULL);
2448}
2449
2450// Test that an offer contains no media content descriptions if
2451// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2452TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002453 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002454 PeerConnectionInterface::RTCOfferAnswerOptions options;
2455 options.offer_to_receive_audio = 0;
2456 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002457
kwibergd1fe2812016-04-27 06:47:29 -07002458 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002459
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460 ASSERT_TRUE(offer != NULL);
2461 const cricket::ContentInfo* content =
2462 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 only audio media content descriptions if
2469// kOfferToReceiveAudio constraints are set to true.
2470TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
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 =
2474 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2475
kwibergd1fe2812016-04-27 06:47:29 -07002476 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477
2478 const cricket::ContentInfo* content =
2479 cricket::GetFirstAudioContent(offer->description());
2480 EXPECT_TRUE(content != NULL);
2481 content = cricket::GetFirstVideoContent(offer->description());
2482 EXPECT_TRUE(content == NULL);
2483}
2484
2485// Test that an offer contains audio and video media content descriptions if
2486// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2487TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002488 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002489 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002490 PeerConnectionInterface::RTCOfferAnswerOptions options;
2491 options.offer_to_receive_audio =
2492 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2493 options.offer_to_receive_video =
2494 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2495
kwibergd1fe2812016-04-27 06:47:29 -07002496 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002497
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002498 const cricket::ContentInfo* content =
2499 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002500 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002501
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 content = cricket::GetFirstVideoContent(offer->description());
2503 EXPECT_TRUE(content != NULL);
2504
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002505 // Sets constraints to false and verifies that audio/video contents are
2506 // removed.
2507 options.offer_to_receive_audio = 0;
2508 options.offer_to_receive_video = 0;
2509 offer.reset(CreateOffer(options));
2510
2511 content = cricket::GetFirstAudioContent(offer->description());
2512 EXPECT_TRUE(content == NULL);
2513 content = cricket::GetFirstVideoContent(offer->description());
2514 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515}
2516
2517// Test that an answer can not be created if the last remote description is not
2518// an offer.
2519TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002520 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002521 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002522 SetLocalDescriptionWithoutError(offer);
2523 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2524 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002525 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002526}
2527
2528// Test that an answer contains the correct media content descriptions when no
2529// constraints have been set.
2530TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002531 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002533 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002534 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002535 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002536 const cricket::ContentInfo* content =
2537 cricket::GetFirstAudioContent(answer->description());
2538 ASSERT_TRUE(content != NULL);
2539 EXPECT_FALSE(content->rejected);
2540
2541 content = cricket::GetFirstVideoContent(answer->description());
2542 ASSERT_TRUE(content != NULL);
2543 EXPECT_FALSE(content->rejected);
2544}
2545
2546// Test that an answer contains the correct media content descriptions when no
2547// constraints have been set and the offer only contain audio.
2548TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
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 only.
2551 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002552
kwibergd1fe2812016-04-27 06:47:29 -07002553 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002554 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2555 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2556
2557 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002558 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559 const cricket::ContentInfo* content =
2560 cricket::GetFirstAudioContent(answer->description());
2561 ASSERT_TRUE(content != NULL);
2562 EXPECT_FALSE(content->rejected);
2563
2564 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2565}
2566
2567// Test that an answer contains the correct media content descriptions when no
2568// constraints have been set.
2569TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002570 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002571 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002572 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002573 SetRemoteDescriptionWithoutError(offer.release());
2574 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002575 SendAudioVideoStream1();
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 content = cricket::GetFirstVideoContent(answer->description());
2583 ASSERT_TRUE(content != NULL);
2584 EXPECT_FALSE(content->rejected);
2585}
2586
2587// Test that an answer contains the correct media content descriptions when
2588// constraints have been set but no stream is sent.
2589TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002590 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002591 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002592 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593 SetRemoteDescriptionWithoutError(offer.release());
2594
htaa2a49d92016-03-04 02:51:39 -08002595 cricket::MediaSessionOptions session_options;
2596 session_options.recv_audio = false;
2597 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002598 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002599 CreateAnswer(session_options));
2600
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601 const cricket::ContentInfo* content =
2602 cricket::GetFirstAudioContent(answer->description());
2603 ASSERT_TRUE(content != NULL);
2604 EXPECT_TRUE(content->rejected);
2605
2606 content = cricket::GetFirstVideoContent(answer->description());
2607 ASSERT_TRUE(content != NULL);
2608 EXPECT_TRUE(content->rejected);
2609}
2610
2611// Test that an answer contains the correct media content descriptions when
2612// constraints have been set and streams are sent.
2613TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002614 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002615 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002616 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002617 SetRemoteDescriptionWithoutError(offer.release());
2618
htaa2a49d92016-03-04 02:51:39 -08002619 cricket::MediaSessionOptions options;
2620 options.recv_audio = false;
2621 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002622
2623 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002624 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002625 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626
2627 // TODO(perkj): Should the direction be set to SEND_ONLY?
2628 const cricket::ContentInfo* content =
2629 cricket::GetFirstAudioContent(answer->description());
2630 ASSERT_TRUE(content != NULL);
2631 EXPECT_FALSE(content->rejected);
2632
2633 // TODO(perkj): Should the direction be set to SEND_ONLY?
2634 content = cricket::GetFirstVideoContent(answer->description());
2635 ASSERT_TRUE(content != NULL);
2636 EXPECT_FALSE(content->rejected);
2637}
2638
2639TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2640 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002641 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002642 PeerConnectionInterface::RTCOfferAnswerOptions options;
2643 options.offer_to_receive_audio =
2644 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2645 options.voice_activity_detection = false;
2646
kwibergd1fe2812016-04-27 06:47:29 -07002647 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002648
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002649 const cricket::ContentInfo* content =
2650 cricket::GetFirstAudioContent(offer->description());
2651 EXPECT_TRUE(content != NULL);
2652 EXPECT_TRUE(VerifyNoCNCodecs(content));
2653}
2654
2655TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2656 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002657 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002658 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002659 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002660 SetRemoteDescriptionWithoutError(offer.release());
2661
htaa2a49d92016-03-04 02:51:39 -08002662 cricket::MediaSessionOptions options;
2663 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002664 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002665 const cricket::ContentInfo* content =
2666 cricket::GetFirstAudioContent(answer->description());
2667 ASSERT_TRUE(content != NULL);
2668 EXPECT_TRUE(VerifyNoCNCodecs(content));
2669}
2670
2671// This test verifies the call setup when remote answer with audio only and
2672// later updates with video.
2673TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002674 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002675 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2676 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2677
deadbeefab9b2d12015-10-14 11:33:11 -07002678 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002679 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002680
2681 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002682 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2683
2684 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2685 // and answer;
2686 SetLocalDescriptionWithoutError(offer);
2687 SetRemoteDescriptionWithoutError(answer);
2688
2689 video_channel_ = media_engine_->GetVideoChannel(0);
2690 voice_channel_ = media_engine_->GetVoiceChannel(0);
2691
2692 ASSERT_TRUE(video_channel_ == NULL);
2693
2694 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2695 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2696 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2697
2698 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002699 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002700 CreateAndSetRemoteOfferAndLocalAnswer();
2701
2702 video_channel_ = media_engine_->GetVideoChannel(0);
2703 voice_channel_ = media_engine_->GetVoiceChannel(0);
2704
2705 ASSERT_TRUE(video_channel_ != NULL);
2706 ASSERT_TRUE(voice_channel_ != NULL);
2707
2708 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2709 ASSERT_EQ(1u, video_channel_->send_streams().size());
2710 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2711 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2712 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2713 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2714 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2715 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2716
2717 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002718 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002719 CreateAndSetRemoteOfferAndLocalAnswer();
2720
2721 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2722 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2723 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2724 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2725 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2726}
2727
2728// This test verifies the call setup when remote answer with video only and
2729// later updates with audio.
2730TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002731 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002732 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2733 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002734 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002735 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002736
2737 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002738 options.recv_audio = false;
2739 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002740 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2741 offer, options, cricket::SEC_ENABLED);
2742
2743 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2744 // and answer.
2745 SetLocalDescriptionWithoutError(offer);
2746 SetRemoteDescriptionWithoutError(answer);
2747
2748 video_channel_ = media_engine_->GetVideoChannel(0);
2749 voice_channel_ = media_engine_->GetVoiceChannel(0);
2750
2751 ASSERT_TRUE(voice_channel_ == NULL);
2752 ASSERT_TRUE(video_channel_ != NULL);
2753
2754 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2755 ASSERT_EQ(1u, video_channel_->send_streams().size());
2756 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2757
2758 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002759 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002760 CreateAndSetRemoteOfferAndLocalAnswer();
2761
2762 voice_channel_ = media_engine_->GetVoiceChannel(0);
2763 ASSERT_TRUE(voice_channel_ != NULL);
2764
2765 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2766 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2767 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2768 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2769
2770 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002771 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002772 CreateAndSetRemoteOfferAndLocalAnswer();
2773
2774 video_channel_ = media_engine_->GetVideoChannel(0);
2775 voice_channel_ = media_engine_->GetVoiceChannel(0);
2776
2777 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2778 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2779 ASSERT_EQ(1u, video_channel_->send_streams().size());
2780 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2781}
2782
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002783TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002784 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002785 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002786 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002787 VerifyCryptoParams(offer->description());
2788 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002789 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002790 VerifyCryptoParams(answer->description());
2791}
2792
2793TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002794 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002795 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002796 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002797 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002798 VerifyNoCryptoParams(offer->description(), false);
2799}
2800
2801TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002802 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002803 VerifyAnswerFromNonCryptoOffer();
2804}
2805
2806TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002807 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002808 VerifyAnswerFromCryptoOffer();
2809}
2810
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002811// This test verifies that setLocalDescription fails if
2812// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2813TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002814 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002815 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002816 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002817
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002818 std::string sdp;
2819 RemoveIceUfragPwdLines(offer.get(), &sdp);
2820 SessionDescriptionInterface* modified_offer =
2821 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002822 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002823}
2824
2825// This test verifies that setRemoteDescription fails if
2826// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2827TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002828 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002829 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002830 std::string sdp;
2831 RemoveIceUfragPwdLines(offer.get(), &sdp);
2832 SessionDescriptionInterface* modified_offer =
2833 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002834 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002835}
2836
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002837// This test verifies that setLocalDescription fails if local offer has
2838// too short ice ufrag and pwd strings.
2839TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002840 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002841 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002842 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002843 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2844 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002845 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002846 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002847 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002848
2849 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002850 offer.reset(CreateOffer());
2851 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2852 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002853}
2854
2855// This test verifies that setRemoteDescription fails if remote offer has
2856// too short ice ufrag and pwd strings.
2857TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002858 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002859 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002860 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2861 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002862 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002863 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002864 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002865
deadbeef0ed85b22016-02-23 17:24:52 -08002866 offer.reset(CreateRemoteOffer());
2867 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2868 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002869}
2870
Honghai Zhang04e91462015-12-11 14:26:22 -08002871// Test that if the remote offer indicates the peer requested ICE restart (via
2872// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2873TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002874 Init();
honghaiz503726c2015-07-31 12:37:38 -07002875
2876 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002877 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002878 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002879 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2880 0, "", "", "relay", 0, "");
2881 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2882 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002883 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2884 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002885 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2886
2887 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002888 offer.reset(CreateRemoteOffer());
2889 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002890 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2891 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2892 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002893 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2894 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002895 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2896
2897 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002898 offer.reset(CreateRemoteOffer());
2899 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002900 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2901 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2902 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002903 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2904 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002905 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2906
2907 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002908 offer.reset(CreateRemoteOffer());
2909 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2910 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002911 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2912}
2913
Honghai Zhang04e91462015-12-11 14:26:22 -08002914// Test that if the remote answer indicates the peer requested ICE restart (via
2915// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2916TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2917 Init();
2918 SessionDescriptionInterface* offer = CreateOffer();
2919 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002920
2921 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002922 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002923 answer->set_type(JsepSessionDescription::kPrAnswer);
2924 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002925 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2926 0, "", "", "relay", 0, "");
2927 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2928 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002929 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2930 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002931 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2932
2933 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002934 answer.reset(CreateRemoteAnswer(offer));
2935 answer->set_type(JsepSessionDescription::kPrAnswer);
2936 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002937 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2938 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2939 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002940 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2941 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002942 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2943
2944 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002945 answer.reset(CreateRemoteAnswer(offer));
2946 answer->set_type(JsepSessionDescription::kPrAnswer);
2947 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002948 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2949 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2950 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002951 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2952 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002953 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2954
2955 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002956 answer.reset(CreateRemoteAnswer(offer));
2957 answer->set_type(JsepSessionDescription::kPrAnswer);
2958 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2959 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002960 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2961}
2962
Donald Curtisd4f769d2015-05-28 09:48:21 -07002963// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002964// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002965TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2966 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2967
2968 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002969 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002970
2971 PeerConnectionInterface::RTCOfferAnswerOptions options;
2972 options.use_rtp_mux = true;
2973
2974 SessionDescriptionInterface* offer = CreateRemoteOffer();
2975 SetRemoteDescriptionWithoutError(offer);
2976
htaa2a49d92016-03-04 02:51:39 -08002977 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002978 SetLocalDescriptionWithoutError(answer);
2979
deadbeefcbecd352015-09-23 11:50:27 -07002980 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2981 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002982
deadbeefcbecd352015-09-23 11:50:27 -07002983 cricket::BaseChannel* voice_channel = session_->voice_channel();
2984 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002985
2986 // Checks if one of the transport channels contains a connection using a given
2987 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002988 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002989 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002990 session_->GetChannelTransportStats(voice_channel, &stats);
2991 for (auto& kv : stats.transport_stats) {
2992 for (auto& chan_stat : kv.second.channel_stats) {
2993 for (auto& conn_info : chan_stat.connection_infos) {
2994 if (conn_info.remote_candidate.address().port() == port) {
2995 return true;
2996 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002997 }
2998 }
2999 }
3000 return false;
3001 };
3002
3003 EXPECT_FALSE(connection_with_remote_port(5000));
3004 EXPECT_FALSE(connection_with_remote_port(5001));
3005 EXPECT_FALSE(connection_with_remote_port(6000));
3006
3007 // The way the *_WAIT checks work is they only wait if the condition fails,
3008 // which does not help in the case where state is not changing. This is
3009 // problematic in this test since we want to verify that adding a video
3010 // candidate does _not_ change state. So we interleave candidates and assume
3011 // that messages are executed in the order they were posted.
3012
3013 // First audio candidate.
3014 cricket::Candidate candidate0;
3015 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3016 candidate0.set_component(1);
3017 candidate0.set_protocol("udp");
3018 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3019 candidate0);
3020 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3021
3022 // Video candidate.
3023 cricket::Candidate candidate1;
3024 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3025 candidate1.set_component(1);
3026 candidate1.set_protocol("udp");
3027 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3028 candidate1);
3029 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3030
3031 // Second audio candidate.
3032 cricket::Candidate candidate2;
3033 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3034 candidate2.set_component(1);
3035 candidate2.set_protocol("udp");
3036 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3037 candidate2);
3038 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3039
3040 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3041 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3042
3043 // No need here for a _WAIT check since we are checking that state hasn't
3044 // changed: if this is false we would be doing waits for nothing and if this
3045 // is true then there will be no messages processed anyways.
3046 EXPECT_FALSE(connection_with_remote_port(6000));
3047}
3048
deadbeefcbecd352015-09-23 11:50:27 -07003049// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003050TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3051 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003052 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003053
3054 PeerConnectionInterface::RTCOfferAnswerOptions options;
3055 options.use_rtp_mux = true;
3056
3057 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003058 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003059
deadbeefcbecd352015-09-23 11:50:27 -07003060 EXPECT_NE(session_->voice_rtp_transport_channel(),
3061 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003062
deadbeefab9b2d12015-10-14 11:33:11 -07003063 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003064 SessionDescriptionInterface* answer =
3065 CreateRemoteAnswer(session_->local_description());
3066 SetRemoteDescriptionWithoutError(answer);
3067
deadbeefcbecd352015-09-23 11:50:27 -07003068 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3069 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003070}
3071
deadbeefcbecd352015-09-23 11:50:27 -07003072// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003073TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3074 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003075 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003076
Donald Curtis0e209b02015-03-24 09:29:54 -07003077 PeerConnectionInterface::RTCOfferAnswerOptions options;
3078 options.use_rtp_mux = true;
3079
3080 SessionDescriptionInterface* offer = CreateOffer(options);
3081 SetLocalDescriptionWithoutError(offer);
3082
deadbeefcbecd352015-09-23 11:50:27 -07003083 EXPECT_NE(session_->voice_rtp_transport_channel(),
3084 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003085
deadbeefab9b2d12015-10-14 11:33:11 -07003086 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003087
3088 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003089 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003090 CreateRemoteAnswer(session_->local_description()));
3091 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3092 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3093 JsepSessionDescription* modified_answer =
3094 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3095 modified_answer->Initialize(answer_copy, "1", "1");
3096 SetRemoteDescriptionWithoutError(modified_answer); //
3097
deadbeefcbecd352015-09-23 11:50:27 -07003098 EXPECT_NE(session_->voice_rtp_transport_channel(),
3099 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003100}
3101
3102// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3103TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3104 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003105 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003106
3107 PeerConnectionInterface::RTCOfferAnswerOptions options;
3108 options.use_rtp_mux = true;
3109
3110 SessionDescriptionInterface* offer = CreateOffer(options);
3111 SetLocalDescriptionWithoutError(offer);
3112
deadbeefcbecd352015-09-23 11:50:27 -07003113 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3114 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003115
deadbeefab9b2d12015-10-14 11:33:11 -07003116 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003117 SessionDescriptionInterface* answer =
3118 CreateRemoteAnswer(session_->local_description());
3119 SetRemoteDescriptionWithoutError(answer);
3120
deadbeefcbecd352015-09-23 11:50:27 -07003121 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3122 session_->video_rtp_transport_channel());
3123}
3124
3125// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3126// audio content in the answer.
3127TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3128 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003129 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003130
3131 PeerConnectionInterface::RTCOfferAnswerOptions options;
3132 options.use_rtp_mux = true;
3133
3134 SessionDescriptionInterface* offer = CreateOffer(options);
3135 SetLocalDescriptionWithoutError(offer);
3136
3137 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3138 session_->video_rtp_transport_channel());
3139
deadbeefab9b2d12015-10-14 11:33:11 -07003140 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003141 cricket::MediaSessionOptions recv_options;
3142 recv_options.recv_audio = false;
3143 recv_options.recv_video = true;
3144 SessionDescriptionInterface* answer =
3145 CreateRemoteAnswer(session_->local_description(), recv_options);
3146 SetRemoteDescriptionWithoutError(answer);
3147
deadbeefd59daf82015-10-14 15:02:44 -07003148 EXPECT_TRUE(nullptr == session_->voice_channel());
3149 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003150
deadbeefd59daf82015-10-14 15:02:44 -07003151 session_->Close();
3152 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3153 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3154 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3155 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003156}
3157
3158// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3159TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3160 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003161 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003162
Donald Curtis0e209b02015-03-24 09:29:54 -07003163 PeerConnectionInterface::RTCOfferAnswerOptions options;
3164 options.use_rtp_mux = true;
3165
3166 SessionDescriptionInterface* offer = CreateOffer(options);
3167 SetLocalDescriptionWithoutError(offer);
3168
deadbeefcbecd352015-09-23 11:50:27 -07003169 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3170 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003171
deadbeefab9b2d12015-10-14 11:33:11 -07003172 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003173
3174 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003175 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003176 CreateRemoteAnswer(session_->local_description()));
3177 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3178 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3179 JsepSessionDescription* modified_answer =
3180 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3181 modified_answer->Initialize(answer_copy, "1", "1");
3182 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003183
deadbeefcbecd352015-09-23 11:50:27 -07003184 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3185 session_->video_rtp_transport_channel());
3186}
3187
3188// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3189TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3190 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003191 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003192
3193 SessionDescriptionInterface* offer = CreateRemoteOffer();
3194 SetRemoteDescriptionWithoutError(offer);
3195
3196 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3197 session_->video_rtp_transport_channel());
3198
deadbeefab9b2d12015-10-14 11:33:11 -07003199 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003200 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003201 SetLocalDescriptionWithoutError(answer);
3202
3203 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3204 session_->video_rtp_transport_channel());
3205}
3206
3207// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3208TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3209 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003210 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003211
3212 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003213 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003214 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3215 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3216 JsepSessionDescription* modified_offer =
3217 new JsepSessionDescription(JsepSessionDescription::kOffer);
3218 modified_offer->Initialize(offer_copy, "1", "1");
3219
3220 // Expect an error when applying the remote description
3221 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3222 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003223}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003224
Peter Thatcher4eddf182015-04-30 10:55:59 -07003225// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003226TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3227 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003228 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003229
Donald Curtis0e209b02015-03-24 09:29:54 -07003230 PeerConnectionInterface::RTCOfferAnswerOptions options;
3231 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003232
Donald Curtis0e209b02015-03-24 09:29:54 -07003233 SessionDescriptionInterface* offer = CreateOffer(options);
3234 SetLocalDescriptionWithoutError(offer);
3235
deadbeefcbecd352015-09-23 11:50:27 -07003236 EXPECT_NE(session_->voice_rtp_transport_channel(),
3237 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003238
deadbeefab9b2d12015-10-14 11:33:11 -07003239 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003240 SessionDescriptionInterface* answer =
3241 CreateRemoteAnswer(session_->local_description());
3242 SetRemoteDescriptionWithoutError(answer);
3243
3244 // This should lead to an audio-only call but isn't implemented
3245 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003246 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3247 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003248}
3249
deadbeefcbecd352015-09-23 11:50:27 -07003250// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003251TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3252 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003253 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003254 PeerConnectionInterface::RTCOfferAnswerOptions options;
3255 options.use_rtp_mux = true;
3256
3257 SessionDescriptionInterface* offer = CreateOffer(options);
3258 SetLocalDescriptionWithoutError(offer);
3259
deadbeefcbecd352015-09-23 11:50:27 -07003260 EXPECT_NE(session_->voice_rtp_transport_channel(),
3261 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003262
deadbeefab9b2d12015-10-14 11:33:11 -07003263 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003264
3265 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003266 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003267 CreateRemoteAnswer(session_->local_description()));
3268 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3269 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3270 JsepSessionDescription* modified_answer =
3271 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3272 modified_answer->Initialize(answer_copy, "1", "1");
3273 SetRemoteDescriptionWithoutError(modified_answer); //
3274
deadbeefcbecd352015-09-23 11:50:27 -07003275 EXPECT_NE(session_->voice_rtp_transport_channel(),
3276 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003277}
3278
Peter Thatcher4eddf182015-04-30 10:55:59 -07003279// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3280TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3281 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003282 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003283
3284 PeerConnectionInterface::RTCOfferAnswerOptions options;
3285 options.use_rtp_mux = true;
3286
3287 SessionDescriptionInterface* offer = CreateOffer(options);
3288 SetRemoteDescriptionWithoutError(offer);
3289
deadbeefcbecd352015-09-23 11:50:27 -07003290 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3291 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003292}
3293
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003294TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3295 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003296 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003297
3298 PeerConnectionInterface::RTCOfferAnswerOptions options;
3299 SessionDescriptionInterface* offer = CreateOffer(options);
3300 SetLocalDescriptionWithoutError(offer);
3301
deadbeefcbecd352015-09-23 11:50:27 -07003302 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3303 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003304
deadbeefab9b2d12015-10-14 11:33:11 -07003305 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003306 SessionDescriptionInterface* answer =
3307 CreateRemoteAnswer(session_->local_description());
3308 SetRemoteDescriptionWithoutError(answer);
3309
deadbeefcbecd352015-09-23 11:50:27 -07003310 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3311 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003312}
3313
3314TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3315 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003316 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003317
3318 PeerConnectionInterface::RTCOfferAnswerOptions options;
3319 SessionDescriptionInterface* offer = CreateOffer(options);
3320 SetLocalDescriptionWithoutError(offer);
3321
deadbeefcbecd352015-09-23 11:50:27 -07003322 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3323 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003324
deadbeefab9b2d12015-10-14 11:33:11 -07003325 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003326 SessionDescriptionInterface* answer =
3327 CreateRemoteAnswer(session_->local_description());
3328 SetRemoteDescriptionWithoutError(answer);
3329
deadbeefcbecd352015-09-23 11:50:27 -07003330 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3331 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003332}
3333
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003334// This test verifies that SetLocalDescription and SetRemoteDescription fails
3335// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3336TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003337 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003338 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003339
3340 PeerConnectionInterface::RTCOfferAnswerOptions options;
3341 options.use_rtp_mux = true;
3342
3343 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003344 std::string offer_str;
3345 offer->ToString(&offer_str);
3346 // Disable rtcp-mux
3347 const std::string rtcp_mux = "rtcp-mux";
3348 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003349 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003350 xrtcp_mux.c_str(), xrtcp_mux.length(),
3351 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003352 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003353 new JsepSessionDescription(JsepSessionDescription::kOffer);
3354 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003355 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003356 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003357 new JsepSessionDescription(JsepSessionDescription::kOffer);
3358 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003359 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003360 // Trying unmodified SDP.
3361 SetLocalDescriptionWithoutError(offer);
3362}
3363
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003364TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003365 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003366 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003367 CreateAndSetRemoteOfferAndLocalAnswer();
3368 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3369 ASSERT_TRUE(channel != NULL);
3370 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003371 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003372 double volume;
3373 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3374 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003375 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003376 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3377 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003378 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003379 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3380 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003381}
3382
skvlade0d46372016-04-07 22:59:22 -07003383TEST_F(WebRtcSessionTest, SetAudioMaxSendBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003384 Init();
3385 SendAudioVideoStream1();
3386 CreateAndSetRemoteOfferAndLocalAnswer();
3387 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3388 ASSERT_TRUE(channel != NULL);
3389 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
skvlade0d46372016-04-07 22:59:22 -07003390 EXPECT_EQ(-1, channel->max_bps());
skvladdc1c62c2016-03-16 19:07:43 -07003391 webrtc::RtpParameters params = session_->GetAudioRtpParameters(send_ssrc);
skvlade0d46372016-04-07 22:59:22 -07003392 EXPECT_EQ(1, params.encodings.size());
3393 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3394 params.encodings[0].max_bitrate_bps = 1000;
3395 EXPECT_TRUE(session_->SetAudioRtpParameters(send_ssrc, params));
skvladdc1c62c2016-03-16 19:07:43 -07003396
skvlade0d46372016-04-07 22:59:22 -07003397 // Read back the parameters and verify they have been changed.
3398 params = session_->GetAudioRtpParameters(send_ssrc);
3399 EXPECT_EQ(1, params.encodings.size());
3400 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3401
3402 // Verify that the audio channel received the new parameters.
3403 params = channel->GetRtpParameters(send_ssrc);
3404 EXPECT_EQ(1, params.encodings.size());
3405 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3406
3407 // Verify that the global bitrate limit has not been changed.
3408 EXPECT_EQ(-1, channel->max_bps());
skvladdc1c62c2016-03-16 19:07:43 -07003409}
3410
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003411TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003412 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003413 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003414 CreateAndSetRemoteOfferAndLocalAnswer();
3415 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3416 ASSERT_TRUE(channel != NULL);
3417 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003418 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003419 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3420
3421 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003422 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003423
kwibergd1fe2812016-04-27 06:47:29 -07003424 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003425 session_->SetAudioSend(send_ssrc, false, options, source.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003426 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003427 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003428 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003429
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003430 // This will trigger SetSink(nullptr) to the |source|.
3431 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003432 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003433 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003434 EXPECT_TRUE(source->sink() == nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003435}
3436
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003437TEST_F(WebRtcSessionTest, AudioSourceForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003438 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003439 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003440 CreateAndSetRemoteOfferAndLocalAnswer();
3441 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3442 ASSERT_TRUE(channel != NULL);
3443 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003444 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003445
kwibergd1fe2812016-04-27 06:47:29 -07003446 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003447 cricket::AudioOptions options;
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003448 session_->SetAudioSend(send_ssrc, true, options, source.get());
3449 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003450
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003451 // Delete the |source| and it will trigger OnClose() to the sink, and this
3452 // will invalidate the |source_| pointer in the sink and prevent getting a
3453 // SetSink(nullptr) callback afterwards.
3454 source.reset();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003455
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003456 // This will trigger SetSink(nullptr) if no OnClose() callback.
3457 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003458}
3459
3460TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003461 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003462 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003463 CreateAndSetRemoteOfferAndLocalAnswer();
3464 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3465 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003466 ASSERT_LT(0u, channel->sinks().size());
3467 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003468 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003469 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003470 cricket::FakeVideoRenderer renderer;
3471 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003472 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003473 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003474 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003475}
3476
skvladdc1c62c2016-03-16 19:07:43 -07003477TEST_F(WebRtcSessionTest, SetVideoMaxSendBitrate) {
3478 Init();
3479 SendAudioVideoStream1();
3480 CreateAndSetRemoteOfferAndLocalAnswer();
3481 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3482 ASSERT_TRUE(channel != NULL);
3483 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
3484 EXPECT_EQ(-1, channel->max_bps());
3485 webrtc::RtpParameters params = session_->GetVideoRtpParameters(send_ssrc);
3486 EXPECT_EQ(1, params.encodings.size());
3487 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3488 params.encodings[0].max_bitrate_bps = 1000;
3489 EXPECT_TRUE(session_->SetVideoRtpParameters(send_ssrc, params));
3490
3491 // Read back the parameters and verify they have been changed.
3492 params = session_->GetVideoRtpParameters(send_ssrc);
3493 EXPECT_EQ(1, params.encodings.size());
3494 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3495
3496 // Verify that the video channel received the new parameters.
3497 params = channel->GetRtpParameters(send_ssrc);
3498 EXPECT_EQ(1, params.encodings.size());
3499 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3500
3501 // Verify that the global bitrate limit has not been changed.
3502 EXPECT_EQ(-1, channel->max_bps());
3503}
3504
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003505TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003506 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003507 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003508 CreateAndSetRemoteOfferAndLocalAnswer();
3509 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3510 ASSERT_TRUE(channel != NULL);
3511 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003512 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003513 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3514 cricket::VideoOptions* options = NULL;
3515 session_->SetVideoSend(send_ssrc, false, options);
3516 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3517 session_->SetVideoSend(send_ssrc, true, options);
3518 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3519}
3520
3521TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3522 TestCanInsertDtmf(false);
3523}
3524
3525TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3526 TestCanInsertDtmf(true);
3527}
3528
3529TEST_F(WebRtcSessionTest, InsertDtmf) {
3530 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003531 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003532 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003533 CreateAndSetRemoteOfferAndLocalAnswer();
3534 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3535 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3536
3537 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003538 const int expected_duration = 90;
3539 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3540 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3541 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3542
3543 // Verify
3544 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003545 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003546 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003547 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003548 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003549 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003550 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003551 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003552}
3553
deadbeefd59daf82015-10-14 15:02:44 -07003554// This test verifies the |initial_offerer| flag when session initiates the
3555// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003556TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003557 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003558 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003559 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003560 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3561 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003562 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003563 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003564 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003565}
3566
deadbeefd59daf82015-10-14 15:02:44 -07003567// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003568TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003569 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003570 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003571 SessionDescriptionInterface* offer = CreateRemoteOffer();
3572 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003573 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003574
deadbeefd59daf82015-10-14 15:02:44 -07003575 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003576 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003577 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003578}
3579
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3581TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003582 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003583 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003584 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003585 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003586 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003587 CreateRemoteAnswer(session_->local_description()));
3588
3589 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3590 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003591 JsepSessionDescription* modified_answer =
3592 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003593
3594 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3595 answer->session_id(),
3596 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003597 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003598
wu@webrtc.org4e393072014-04-07 17:04:35 +00003599 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003600 std::string sdp;
3601 EXPECT_TRUE(answer->ToString(&sdp));
3602 const std::string kAudioMid = "a=mid:audio";
3603 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003604 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003605 kAudioMidReplaceStr.c_str(),
3606 kAudioMidReplaceStr.length(),
3607 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003608 SessionDescriptionInterface* modified_answer1 =
3609 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003610 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003611
wu@webrtc.org4e393072014-04-07 17:04:35 +00003612 // Different media types.
3613 EXPECT_TRUE(answer->ToString(&sdp));
3614 const std::string kAudioMline = "m=audio";
3615 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003616 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003617 kAudioMlineReplaceStr.c_str(),
3618 kAudioMlineReplaceStr.length(),
3619 &sdp);
3620 SessionDescriptionInterface* modified_answer2 =
3621 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3622 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3623
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003624 SetRemoteDescriptionWithoutError(answer.release());
3625}
3626
3627// Verifying remote offer and local answer have matching m-lines as per
3628// RFC 3264.
3629TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003630 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003631 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003632 SessionDescriptionInterface* offer = CreateRemoteOffer();
3633 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003634 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003635
3636 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3637 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003638 JsepSessionDescription* modified_answer =
3639 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003640
3641 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3642 answer->session_id(),
3643 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003644 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003645 SetLocalDescriptionWithoutError(answer);
3646}
3647
3648// This test verifies that WebRtcSession does not start candidate allocation
3649// before SetLocalDescription is called.
3650TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003651 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003652 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003653 SessionDescriptionInterface* offer = CreateRemoteOffer();
3654 cricket::Candidate candidate;
3655 candidate.set_component(1);
3656 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3657 candidate);
3658 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3659 cricket::Candidate candidate1;
3660 candidate1.set_component(1);
3661 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3662 candidate1);
3663 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3664 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003665 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3666 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003667
3668 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003669 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003670 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3671 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3672
htaa2a49d92016-03-04 02:51:39 -08003673 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003674 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003675 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3676}
3677
3678// This test verifies that crypto parameter is updated in local session
3679// description as per security policy set in MediaSessionDescriptionFactory.
3680TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003681 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003682 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003683 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003684
3685 // Making sure SetLocalDescription correctly sets crypto value in
3686 // SessionDescription object after de-serialization of sdp string. The value
3687 // will be set as per MediaSessionDescriptionFactory.
3688 std::string offer_str;
3689 offer->ToString(&offer_str);
3690 SessionDescriptionInterface* jsep_offer_str =
3691 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3692 SetLocalDescriptionWithoutError(jsep_offer_str);
3693 EXPECT_TRUE(session_->voice_channel()->secure_required());
3694 EXPECT_TRUE(session_->video_channel()->secure_required());
3695}
3696
3697// This test verifies the crypto parameter when security is disabled.
3698TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003699 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003700 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003701 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003702 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003703
3704 // Making sure SetLocalDescription correctly sets crypto value in
3705 // SessionDescription object after de-serialization of sdp string. The value
3706 // will be set as per MediaSessionDescriptionFactory.
3707 std::string offer_str;
3708 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003709 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003710 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3711 SetLocalDescriptionWithoutError(jsep_offer_str);
3712 EXPECT_FALSE(session_->voice_channel()->secure_required());
3713 EXPECT_FALSE(session_->video_channel()->secure_required());
3714}
3715
3716// This test verifies that an answer contains new ufrag and password if an offer
3717// with new ufrag and password is received.
3718TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003719 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003720 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003721 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003722 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003723 SetRemoteDescriptionWithoutError(offer.release());
3724
deadbeefab9b2d12015-10-14 11:33:11 -07003725 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003726 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003727 SetLocalDescriptionWithoutError(answer.release());
3728
3729 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003730 for (const cricket::ContentInfo& content :
3731 session_->local_description()->description()->contents()) {
3732 options.transport_options[content.name].ice_restart = true;
3733 }
kwibergd1fe2812016-04-27 06:47:29 -07003734 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003735 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003736 SetRemoteDescriptionWithoutError(updated_offer1.release());
3737
kwibergd1fe2812016-04-27 06:47:29 -07003738 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003739
deadbeef0ed85b22016-02-23 17:24:52 -08003740 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3741 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003742
deadbeef0ed85b22016-02-23 17:24:52 -08003743 // Even a second answer (created before the description is set) should have
3744 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003745 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003746
3747 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3748 session_->local_description()->description()));
3749
3750 SetLocalDescriptionWithoutError(updated_answer2.release());
3751}
3752
3753// This test verifies that an answer contains new ufrag and password if an offer
3754// that changes either the ufrag or password (but not both) is received.
3755// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3756// a=ice-pwd attributes compared to the previous SDP from the peer, it
3757// indicates that ICE is restarting for this media stream."
3758TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3759 Init();
3760 cricket::MediaSessionOptions options;
3761 options.recv_audio = true;
3762 options.recv_video = true;
3763 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003764 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003765 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3766 SetRemoteDescriptionWithoutError(offer.release());
3767
3768 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003769 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003770 SetLocalDescriptionWithoutError(answer.release());
3771
3772 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003773 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003774 CreateRemoteOffer(options, session_->remote_description()));
3775 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3776 "original_password12345");
3777 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3778
kwibergd1fe2812016-04-27 06:47:29 -07003779 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003780 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3781 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003782 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003783
3784 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003785 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003786 CreateRemoteOffer(options, session_->remote_description()));
3787 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3788 "modified_password12345");
3789 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3790
kwibergd1fe2812016-04-27 06:47:29 -07003791 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003792 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3793 session_->local_description()->description()));
3794 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003795}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003796
wu@webrtc.org91053e72013-08-10 07:18:04 +00003797// This test verifies that an answer contains old ufrag and password if an offer
3798// with old ufrag and password is received.
3799TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003800 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003801 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003802 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003803 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003804 SetRemoteDescriptionWithoutError(offer.release());
3805
deadbeefab9b2d12015-10-14 11:33:11 -07003806 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003807 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003808 SetLocalDescriptionWithoutError(answer.release());
3809
3810 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003811 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003812 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003813 SetRemoteDescriptionWithoutError(updated_offer2.release());
3814
kwibergd1fe2812016-04-27 06:47:29 -07003815 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003816
deadbeef0ed85b22016-02-23 17:24:52 -08003817 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3818 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003819
3820 SetLocalDescriptionWithoutError(updated_answer2.release());
3821}
3822
deadbeef0ed85b22016-02-23 17:24:52 -08003823// This test verifies that if an offer does an ICE restart on some, but not all
3824// media sections, the answer will change the ufrag/password in the correct
3825// media sections.
3826TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3827 Init();
3828 cricket::MediaSessionOptions options;
3829 options.recv_video = true;
3830 options.recv_audio = true;
3831 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003832 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003833
3834 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3835 "aaaaaaaaaaaaaaaaaaaaaa");
3836 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3837 "bbbbbbbbbbbbbbbbbbbbbb");
3838 SetRemoteDescriptionWithoutError(offer.release());
3839
3840 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003841 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003842 SetLocalDescriptionWithoutError(answer.release());
3843
3844 // Receive an offer with new ufrag and password, but only for the video media
3845 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003846 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003847 CreateRemoteOffer(options, session_->remote_description()));
3848 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3849 "cccccccccccccccccccccc");
3850 SetRemoteDescriptionWithoutError(updated_offer.release());
3851
kwibergd1fe2812016-04-27 06:47:29 -07003852 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003853
3854 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3855 session_->local_description()->description(),
3856 cricket::MEDIA_TYPE_AUDIO));
3857
3858 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3859 session_->local_description()->description(),
3860 cricket::MEDIA_TYPE_VIDEO));
3861
3862 SetLocalDescriptionWithoutError(updated_answer.release());
3863}
3864
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003865TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003866 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003867 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003868 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003869 const std::string session_id_orig = offer->session_id();
3870 const std::string session_version_orig = offer->session_version();
3871 SetLocalDescriptionWithoutError(offer);
3872
3873 video_channel_ = media_engine_->GetVideoChannel(0);
3874 video_channel_->set_fail_set_send_codecs(true);
3875
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003876 SessionDescriptionInterface* answer =
3877 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003878 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003879
3880 // Test that after a content error, setting any description will
3881 // result in an error.
3882 video_channel_->set_fail_set_send_codecs(false);
3883 answer = CreateRemoteAnswer(session_->local_description());
3884 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3885 offer = CreateRemoteOffer();
3886 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003887}
3888
3889// Runs the loopback call test with BUNDLE and STUN disabled.
3890TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3891 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003892 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003893 cricket::PORTALLOCATOR_DISABLE_STUN |
3894 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003895 TestLoopbackCall();
3896}
3897
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003898TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003899 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003900 cricket::PORTALLOCATOR_DISABLE_STUN |
3901 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3902 cricket::PORTALLOCATOR_DISABLE_RELAY);
3903
3904 // best connection is IPv6 since it has higher network preference.
3905 LoopbackNetworkConfiguration config;
3906 config.test_ipv6_network_ = true;
3907 config.best_connection_after_initial_ice_converged_ =
3908 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3909
3910 TestLoopbackCall(config);
3911}
3912
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003913// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003914TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003915 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3916 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003917 TestLoopbackCall();
3918}
3919
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003920TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003921 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003922 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003923 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003924 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003925 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3926}
3927
Henrik Boström87713d02015-08-25 09:53:21 +02003928TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003929 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003930
htaa2a49d92016-03-04 02:51:39 -08003931 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003932 options_.disable_sctp_data_channels = false;
3933
Henrik Boström87713d02015-08-25 09:53:21 +02003934 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003935
3936 SetLocalDescriptionWithDataChannel();
3937 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3938}
3939
Henrik Boström87713d02015-08-25 09:53:21 +02003940TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003941 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003942
Henrik Boström87713d02015-08-25 09:53:21 +02003943 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003944
kwibergd1fe2812016-04-27 06:47:29 -07003945 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003946 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003947 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3948}
3949
Henrik Boström87713d02015-08-25 09:53:21 +02003950TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003951 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003952 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003953 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003954
3955 // Create remote offer with SCTP.
3956 cricket::MediaSessionOptions options;
3957 options.data_channel_type = cricket::DCT_SCTP;
3958 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003959 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003960 SetRemoteDescriptionWithoutError(offer);
3961
3962 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003963 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003964 EXPECT_TRUE(answer != NULL);
3965 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3966 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003967}
3968
Henrik Boström87713d02015-08-25 09:53:21 +02003969TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003970 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003971 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003972
3973 SetLocalDescriptionWithDataChannel();
3974 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3975}
3976
Henrik Boström87713d02015-08-25 09:53:21 +02003977TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003978 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003979
Henrik Boström87713d02015-08-25 09:53:21 +02003980 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003981
3982 SetLocalDescriptionWithDataChannel();
3983 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3984}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003985
Henrik Boström87713d02015-08-25 09:53:21 +02003986TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003987 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003988 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003989 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +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, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003996 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003997 const int new_send_port = 9998;
3998 const int new_recv_port = 7775;
3999
Henrik Boström87713d02015-08-25 09:53:21 +02004000 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004001 SetFactoryDtlsSrtp();
4002
4003 // By default, don't actually add the codecs to desc_factory_; they don't
4004 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
4005 // let the session description get parsed. That'll get the proper codecs
4006 // into the stream.
4007 cricket::MediaSessionOptions options;
4008 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
4009 "stream1", new_send_port, options);
4010
4011 // SetRemoteDescription will take the ownership of the offer.
4012 SetRemoteDescriptionWithoutError(offer);
4013
htaa2a49d92016-03-04 02:51:39 -08004014 SessionDescriptionInterface* answer =
4015 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004016 ASSERT_TRUE(answer != NULL);
4017
4018 // Now set the local description, which'll take ownership of the answer.
4019 SetLocalDescriptionWithoutError(answer);
4020
4021 // TEST PLAN: Set the port number to something new, set it in the SDP,
4022 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004023 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07004024 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004025
4026 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
4027 int portnum = -1;
4028 ASSERT_TRUE(ch != NULL);
4029 ASSERT_EQ(1UL, ch->send_codecs().size());
4030 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004031 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004032 ch->send_codecs()[0].name.c_str()));
4033 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
4034 &portnum));
4035 EXPECT_EQ(new_send_port, portnum);
4036
4037 ASSERT_EQ(1UL, ch->recv_codecs().size());
4038 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004039 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004040 ch->recv_codecs()[0].name.c_str()));
4041 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
4042 &portnum));
4043 EXPECT_EQ(new_recv_port, portnum);
4044}
4045
deadbeefab9b2d12015-10-14 11:33:11 -07004046// Verifies that when a session's DataChannel receives an OPEN message,
4047// WebRtcSession signals the DataChannel creation request with the expected
4048// config.
4049TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
4050 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4051
4052 InitWithDtls(GetParam());
4053
4054 SetLocalDescriptionWithDataChannel();
4055 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4056
4057 webrtc::DataChannelInit config;
4058 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004059 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004060 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4061 cricket::ReceiveDataParams params;
4062 params.ssrc = config.id;
4063 params.type = cricket::DMT_CONTROL;
4064
4065 cricket::DataChannel* data_channel = session_->data_channel();
4066 data_channel->SignalDataReceived(data_channel, params, payload);
4067
4068 EXPECT_EQ("a", last_data_channel_label_);
4069 EXPECT_EQ(config.id, last_data_channel_config_.id);
4070 EXPECT_FALSE(last_data_channel_config_.negotiated);
4071 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4072 last_data_channel_config_.open_handshake_role);
4073}
4074
4075TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004076 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
4077 FakeDtlsIdentityStore::GenerateCertificate();
4078
htaa2a49d92016-03-04 02:51:39 -08004079 configuration_.certificates.push_back(certificate);
4080 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004081 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4082
4083 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4084}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004085
Henrik Boström87713d02015-08-25 09:53:21 +02004086// Verifies that CreateOffer succeeds when CreateOffer is called before async
4087// identity generation is finished (even if a certificate is provided this is
4088// an async op).
4089TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4090 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4091 InitWithDtls(GetParam());
4092
Henrik Boströmd8281982015-08-27 10:12:24 +02004093 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004094 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004095 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004096
wu@webrtc.org91053e72013-08-10 07:18:04 +00004097 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004098 VerifyNoCryptoParams(offer->description(), true);
4099 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004100}
4101
4102// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004103// identity generation is finished (even if a certificate is provided this is
4104// an async op).
4105TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004106 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004107 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004108 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004109
4110 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004111 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004112 std::unique_ptr<JsepSessionDescription> offer(
4113 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004114 ASSERT_TRUE(offer.get() != NULL);
4115 SetRemoteDescriptionWithoutError(offer.release());
4116
kwibergd1fe2812016-04-27 06:47:29 -07004117 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004118 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004119 VerifyNoCryptoParams(answer->description(), true);
4120 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004121}
4122
4123// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004124// identity generation is finished (even if a certificate is provided this is
4125// an async op).
4126TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004127 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004128 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004129
Henrik Boströmd8281982015-08-27 10:12:24 +02004130 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004131
kwibergd1fe2812016-04-27 06:47:29 -07004132 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004133 EXPECT_TRUE(offer != NULL);
4134}
4135
4136// Verifies that CreateOffer fails when CreateOffer is called after async
4137// identity generation fails.
4138TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004139 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004140 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004141
Henrik Boströmd8281982015-08-27 10:12:24 +02004142 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004143
kwibergd1fe2812016-04-27 06:47:29 -07004144 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004145 EXPECT_TRUE(offer == NULL);
4146}
4147
4148// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4149// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004150TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004151 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004152 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004153 VerifyMultipleAsyncCreateDescription(GetParam(),
4154 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004155}
4156
4157// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4158// before async identity generation fails.
4159TEST_F(WebRtcSessionTest,
4160 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004161 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004162 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4163 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004164}
4165
4166// Verifies that CreateAnswer succeeds when Multiple CreateAnswer 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 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004170 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004171 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004172 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004173}
4174
4175// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4176// before async identity generation fails.
4177TEST_F(WebRtcSessionTest,
4178 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
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::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004182}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004183
4184// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4185// offer has no SDES crypto but only DTLS fingerprint.
4186TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4187 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004188 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004189 // Create a remote offer with secured transport disabled.
4190 cricket::MediaSessionOptions options;
4191 JsepSessionDescription* offer(CreateRemoteOffer(
4192 options, cricket::SEC_DISABLED));
4193 // Adds a DTLS fingerprint to the remote offer.
4194 cricket::SessionDescription* sdp = offer->description();
4195 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4196 ASSERT_TRUE(audio != NULL);
4197 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4198 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004199 rtc::SSLFingerprint::CreateFromRfc4572(
4200 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004201 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004202 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004203}
4204
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004205TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004206 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004207 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004208 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004209 SessionDescriptionInterface* offer = CreateOffer();
4210
4211 SetLocalDescriptionWithoutError(offer);
4212
4213 voice_channel_ = media_engine_->GetVoiceChannel(0);
4214
4215 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004216 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004217 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004218}
4219
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004220// Tests that we can renegotiate new media content with ICE candidates in the
4221// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004222TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004223 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004224 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004225 SetFactoryDtlsSrtp();
4226
deadbeefab9b2d12015-10-14 11:33:11 -07004227 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004228 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004229 SetLocalDescriptionWithoutError(offer);
4230
4231 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4232 SetRemoteDescriptionWithoutError(answer);
4233
4234 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004235 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004236 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4237
4238 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004239 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004240 candidate1.set_component(1);
4241 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4242 candidate1);
4243 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4244 SetRemoteDescriptionWithoutError(offer);
4245
htaa2a49d92016-03-04 02:51:39 -08004246 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004247 SetLocalDescriptionWithoutError(answer);
4248}
4249
4250// Tests that we can renegotiate new media content with ICE candidates separated
4251// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004252TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004253 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004254 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004255 SetFactoryDtlsSrtp();
4256
deadbeefab9b2d12015-10-14 11:33:11 -07004257 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004258 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004259 SetLocalDescriptionWithoutError(offer);
4260
4261 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4262 SetRemoteDescriptionWithoutError(answer);
4263
4264 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004265 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004266 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4267 SetRemoteDescriptionWithoutError(offer);
4268
4269 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004270 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004271 candidate1.set_component(1);
4272 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4273 candidate1);
4274 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4275
htaa2a49d92016-03-04 02:51:39 -08004276 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004277 SetLocalDescriptionWithoutError(answer);
4278}
honghaiz7f777492016-02-02 21:54:01 -08004279
4280// Flaky on Win and Mac only. See webrtc:4943
4281#if defined(WEBRTC_WIN) || defined(WEBRTC_MAC)
4282#define MAYBE_TestRtxRemovedByCreateAnswer DISABLED_TestRtxRemovedByCreateAnswer
4283#else
4284#define MAYBE_TestRtxRemovedByCreateAnswer TestRtxRemovedByCreateAnswer
4285#endif
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004286// Tests that RTX codec is removed from the answer when it isn't supported
4287// by local side.
honghaiz7f777492016-02-02 21:54:01 -08004288TEST_F(WebRtcSessionTest, MAYBE_TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004289 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004290 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004291 std::string offer_sdp(kSdpWithRtx);
4292
4293 SessionDescriptionInterface* offer =
4294 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4295 EXPECT_TRUE(offer->ToString(&offer_sdp));
4296
4297 // Offer SDP contains the RTX codec.
4298 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4299 SetRemoteDescriptionWithoutError(offer);
4300
htaa2a49d92016-03-04 02:51:39 -08004301 SessionDescriptionInterface* answer = CreateAnswer();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004302 std::string answer_sdp;
4303 answer->ToString(&answer_sdp);
4304 // Answer SDP removes the unsupported RTX codec.
4305 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4306 SetLocalDescriptionWithoutError(answer);
4307}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004308
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004309// This verifies that the voice channel after bundle has both options from video
4310// and voice channels.
4311TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4312 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004313 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004314
4315 PeerConnectionInterface::RTCOfferAnswerOptions options;
4316 options.use_rtp_mux = true;
4317
4318 SessionDescriptionInterface* offer = CreateOffer(options);
4319 SetLocalDescriptionWithoutError(offer);
4320
4321 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4322 rtc::Socket::Option::OPT_SNDBUF, 4000);
4323
4324 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4325 rtc::Socket::Option::OPT_RCVBUF, 8000);
4326
4327 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004328 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004329 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4330 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004331 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004332 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4333
deadbeefcbecd352015-09-23 11:50:27 -07004334 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004335 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4336 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004337 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004338 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4339
deadbeefcbecd352015-09-23 11:50:27 -07004340 EXPECT_NE(session_->voice_rtp_transport_channel(),
4341 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004342
deadbeefab9b2d12015-10-14 11:33:11 -07004343 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004344 SessionDescriptionInterface* answer =
4345 CreateRemoteAnswer(session_->local_description());
4346 SetRemoteDescriptionWithoutError(answer);
4347
deadbeefcbecd352015-09-23 11:50:27 -07004348 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004349 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4350 EXPECT_EQ(4000, option_val);
4351
deadbeefcbecd352015-09-23 11:50:27 -07004352 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004353 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4354 EXPECT_EQ(8000, option_val);
4355}
4356
tommi0f620f42015-07-09 03:25:02 -07004357// Test creating a session, request multiple offers, destroy the session
4358// and make sure we got success/failure callbacks for all of the requests.
4359// Background: crbug.com/507307
4360TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4361 Init();
4362
4363 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4364 PeerConnectionInterface::RTCOfferAnswerOptions options;
4365 options.offer_to_receive_audio =
4366 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004367 cricket::MediaSessionOptions session_options;
4368 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004369
4370 for (auto& o : observers) {
4371 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004372 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004373 }
4374
4375 session_.reset();
4376
tommi0f620f42015-07-09 03:25:02 -07004377 for (auto& o : observers) {
4378 // We expect to have received a notification now even if the session was
4379 // terminated. The offer creation may or may not have succeeded, but we
4380 // must have received a notification which, so the only invalid state
4381 // is kInit.
4382 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4383 }
4384}
4385
stefanc1aeaf02015-10-15 07:26:07 -07004386TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4387 TestPacketOptions();
4388}
4389
deadbeef057ecf02016-01-20 14:30:43 -08004390// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4391// is destroyed.
4392TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4393 Init();
4394 session_.reset();
4395 EXPECT_TRUE(session_destroyed_);
4396}
4397
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004398// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4399// currently fails because upon disconnection and reconnection OnIceComplete is
4400// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004401
deadbeefcbecd352015-09-23 11:50:27 -07004402INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4403 WebRtcSessionTest,
4404 testing::Values(ALREADY_GENERATED,
4405 DTLS_IDENTITY_STORE));