blob: 34d82582c61ad54df6aa99641ae819e18dd74e6d [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
jbauch555604a2016-04-26 03:13:22 -070011#include <memory>
kwiberg0eb15ed2015-12-17 03:04:15 -080012#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070013#include <vector>
14
Henrik Kjellander15583c12016-02-10 10:53:12 +010015#include "webrtc/api/audiotrack.h"
16#include "webrtc/api/fakemediacontroller.h"
17#include "webrtc/api/fakemetricsobserver.h"
18#include "webrtc/api/jsepicecandidate.h"
19#include "webrtc/api/jsepsessiondescription.h"
20#include "webrtc/api/peerconnection.h"
21#include "webrtc/api/sctputils.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010022#include "webrtc/api/test/fakedtlsidentitystore.h"
23#include "webrtc/api/videotrack.h"
24#include "webrtc/api/webrtcsession.h"
25#include "webrtc/api/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000026#include "webrtc/base/fakenetwork.h"
27#include "webrtc/base/firewallsocketserver.h"
28#include "webrtc/base/gunit.h"
29#include "webrtc/base/logging.h"
30#include "webrtc/base/network.h"
31#include "webrtc/base/physicalsocketserver.h"
32#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020033#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000034#include "webrtc/base/sslstreamadapter.h"
35#include "webrtc/base/stringutils.h"
36#include "webrtc/base/thread.h"
37#include "webrtc/base/virtualsocketserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080038#include "webrtc/media/base/fakemediaengine.h"
39#include "webrtc/media/base/fakevideorenderer.h"
40#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010041#include "webrtc/media/engine/fakewebrtccall.h"
kjellandera96e2d72016-02-04 23:52:28 -080042#include "webrtc/p2p/base/stunserver.h"
43#include "webrtc/p2p/base/teststunserver.h"
44#include "webrtc/p2p/base/testturnserver.h"
45#include "webrtc/p2p/base/transportchannel.h"
46#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010047#include "webrtc/pc/channelmanager.h"
48#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
50#define MAYBE_SKIP_TEST(feature) \
51 if (!(feature())) { \
52 LOG(LS_INFO) << "Feature disabled... skipping"; \
53 return; \
54 }
55
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000058using rtc::SocketAddress;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000059using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000061using webrtc::CreateSessionDescriptionObserver;
62using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070063using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020064using webrtc::DtlsIdentityStoreInterface;
jbauchac8869e2015-07-03 01:36:14 -070065using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070067using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068using webrtc::JsepIceCandidate;
69using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000070using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071using webrtc::PeerConnectionInterface;
72using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070073using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000075using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000076using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000077using webrtc::kCreateChannelFailed;
78using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000080using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000081using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000082using webrtc::kSdpWithoutDtlsFingerprint;
83using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000085using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000086using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000088typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
89
wu@webrtc.org364f2042013-11-20 21:49:41 +000090static const int kClientAddrPort = 0;
91static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000092static const char kClientIPv6AddrHost1[] =
93 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000094static const char kClientAddrHost2[] = "22.22.22.22";
95static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000096static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
97static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000098static const char kTurnUsername[] = "test";
99static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
101static const char kSessionVersion[] = "1";
102
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103// Media index of candidates belonging to the first media content.
104static const int kMediaContentIndex0 = 0;
105static const char kMediaContentName0[] = "audio";
106
107// Media index of candidates belonging to the second media content.
108static const int kMediaContentIndex1 = 1;
109static const char kMediaContentName1[] = "video";
110
111static const int kIceCandidatesTimeout = 10000;
112
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000113static const char kFakeDtlsFingerprint[] =
114 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
115 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
116
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000117static const char kTooLongIceUfragPwd[] =
118 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
119 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
120 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
121 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
122
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000123static const char kSdpWithRtx[] =
124 "v=0\r\n"
125 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
126 "s=-\r\n"
127 "t=0 0\r\n"
128 "a=msid-semantic: WMS stream1\r\n"
129 "m=video 9 RTP/SAVPF 0 96\r\n"
130 "c=IN IP4 0.0.0.0\r\n"
131 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
132 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
133 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
134 "a=mid:video\r\n"
135 "a=sendrecv\r\n"
136 "a=rtcp-mux\r\n"
137 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
138 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
139 "a=rtpmap:0 fake_video_codec/90000\r\n"
140 "a=rtpmap:96 rtx/90000\r\n"
141 "a=fmtp:96 apt=0\r\n";
142
deadbeefab9b2d12015-10-14 11:33:11 -0700143static const char kStream1[] = "stream1";
144static const char kVideoTrack1[] = "video1";
145static const char kAudioTrack1[] = "audio1";
146
147static const char kStream2[] = "stream2";
148static const char kVideoTrack2[] = "video2";
149static const char kAudioTrack2[] = "audio2";
150
Henrik Boström87713d02015-08-25 09:53:21 +0200151enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
152
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153class MockIceObserver : public webrtc::IceObserver {
154 public:
155 MockIceObserver()
156 : oncandidatesready_(false),
157 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
158 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
159 }
160
perkjdfb769d2016-02-09 03:09:43 -0800161 void OnIceConnectionChange(
162 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 ice_connection_state_ = new_state;
164 }
perkjdfb769d2016-02-09 03:09:43 -0800165 void OnIceGatheringChange(
166 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 // We can never transition back to "new".
168 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
169 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800170 oncandidatesready_ =
171 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 }
173
174 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800175 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000176 switch (candidate->sdp_mline_index()) {
177 case kMediaContentIndex0:
178 mline_0_candidates_.push_back(candidate->candidate());
179 break;
180 case kMediaContentIndex1:
181 mline_1_candidates_.push_back(candidate->candidate());
182 break;
183 default:
184 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000186
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 // The ICE gathering state should always be Gathering when a candidate is
188 // received (or possibly Completed in the case of the final candidate).
189 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
190 }
191
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700192 // Some local candidates are removed.
193 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700194 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700195 num_candidates_removed_ += candidates.size();
196 }
197
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 bool oncandidatesready_;
199 std::vector<cricket::Candidate> mline_0_candidates_;
200 std::vector<cricket::Candidate> mline_1_candidates_;
201 PeerConnectionInterface::IceConnectionState ice_connection_state_;
202 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700203 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204};
205
206class WebRtcSessionForTest : public webrtc::WebRtcSession {
207 public:
stefanc1aeaf02015-10-15 07:26:07 -0700208 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000209 rtc::Thread* signaling_thread,
210 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700212 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700213 : WebRtcSession(media_controller,
214 signaling_thread,
215 worker_thread,
216 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 RegisterIceObserver(ice_observer);
218 }
219 virtual ~WebRtcSessionForTest() {}
220
deadbeefcbecd352015-09-23 11:50:27 -0700221 // Note that these methods are only safe to use if the signaling thread
222 // is the same as the worker thread
223 cricket::TransportChannel* voice_rtp_transport_channel() {
224 return rtp_transport_channel(voice_channel());
225 }
226
227 cricket::TransportChannel* voice_rtcp_transport_channel() {
228 return rtcp_transport_channel(voice_channel());
229 }
230
231 cricket::TransportChannel* video_rtp_transport_channel() {
232 return rtp_transport_channel(video_channel());
233 }
234
235 cricket::TransportChannel* video_rtcp_transport_channel() {
236 return rtcp_transport_channel(video_channel());
237 }
238
239 cricket::TransportChannel* data_rtp_transport_channel() {
240 return rtp_transport_channel(data_channel());
241 }
242
243 cricket::TransportChannel* data_rtcp_transport_channel() {
244 return rtcp_transport_channel(data_channel());
245 }
246
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 using webrtc::WebRtcSession::SetAudioPlayout;
248 using webrtc::WebRtcSession::SetAudioSend;
nisse2ded9b12016-04-08 02:23:55 -0700249 using webrtc::WebRtcSession::SetSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 using webrtc::WebRtcSession::SetVideoPlayout;
251 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700252
253 private:
254 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
255 if (!ch) {
256 return nullptr;
257 }
258 return ch->transport_channel();
259 }
260
261 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
262 if (!ch) {
263 return nullptr;
264 }
265 return ch->rtcp_transport_channel();
266 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267};
268
wu@webrtc.org91053e72013-08-10 07:18:04 +0000269class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000270 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000272 enum State {
273 kInit,
274 kFailed,
275 kSucceeded,
276 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000277 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000278
279 // CreateSessionDescriptionObserver implementation.
280 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000281 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000282 state_ = kSucceeded;
283 }
284 virtual void OnFailure(const std::string& error) {
285 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286 }
287
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000288 SessionDescriptionInterface* description() { return description_.get(); }
289
290 SessionDescriptionInterface* ReleaseDescription() {
291 return description_.release();
292 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293
wu@webrtc.org91053e72013-08-10 07:18:04 +0000294 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295
wu@webrtc.org91053e72013-08-10 07:18:04 +0000296 protected:
297 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298
299 private:
kwibergd1fe2812016-04-27 06:47:29 -0700300 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000301 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302};
303
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800304class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000305 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800306 FakeAudioSource() : sink_(NULL) {}
307 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000308 if (sink_)
309 sink_->OnClose();
310 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000311
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000312 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000313
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800314 const cricket::AudioSource::Sink* sink() const { return sink_; }
315
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000316 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800317 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000318};
319
Henrik Boström87713d02015-08-25 09:53:21 +0200320class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700321 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
322 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323 protected:
324 // TODO Investigate why ChannelManager crashes, if it's created
325 // after stun_server.
326 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700327 : media_engine_(new cricket::FakeMediaEngine()),
328 data_engine_(new cricket::FakeDataEngine()),
329 channel_manager_(
330 new cricket::ChannelManager(media_engine_,
331 data_engine_,
stefanc1aeaf02015-10-15 07:26:07 -0700332 rtc::Thread::Current())),
333 fake_call_(webrtc::Call::Config()),
334 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800335 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
336 rtc::Thread::Current(),
stefanc1aeaf02015-10-15 07:26:07 -0700337 channel_manager_.get())),
338 tdesc_factory_(new cricket::TransportDescriptionFactory()),
339 desc_factory_(
340 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
341 tdesc_factory_.get())),
342 pss_(new rtc::PhysicalSocketServer),
343 vss_(new rtc::VirtualSocketServer(pss_.get())),
344 fss_(new rtc::FirewallSocketServer(vss_.get())),
345 ss_scope_(fss_.get()),
346 stun_socket_addr_(
347 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
348 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
349 stun_socket_addr_)),
350 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
351 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000352 cricket::ServerAddresses stun_servers;
353 stun_servers.insert(stun_socket_addr_);
354 allocator_.reset(new cricket::BasicPortAllocator(
355 &network_manager_,
356 stun_servers,
357 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000358 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700359 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 EXPECT_TRUE(channel_manager_->Init());
361 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000362 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 }
364
365 void AddInterface(const SocketAddress& addr) {
366 network_manager_.AddInterface(addr);
367 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700368 void RemoveInterface(const SocketAddress& addr) {
369 network_manager_.RemoveInterface(addr);
370 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371
Henrik Boström87713d02015-08-25 09:53:21 +0200372 // If |dtls_identity_store| != null or |rtc_configuration| contains
373 // |certificates| then DTLS will be enabled unless explicitly disabled by
374 // |rtc_configuration| options. When DTLS is enabled a certificate will be
375 // used if provided, otherwise one will be generated using the
376 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000377 void Init(
kwibergd1fe2812016-04-27 06:47:29 -0700378 std::unique_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 ASSERT_TRUE(session_.get() == NULL);
380 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700381 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700382 allocator_.get(), &observer_));
383 session_->SignalDataChannelOpenMessage.connect(
384 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800385 session_->GetOnDestroyedSignal()->connect(
386 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387
388 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
389 observer_.ice_connection_state_);
390 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
391 observer_.ice_gathering_state_);
392
htaa2a49d92016-03-04 02:51:39 -0800393 EXPECT_TRUE(session_->Initialize(options_, std::move(dtls_identity_store),
394 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700395 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000396 }
397
deadbeefab9b2d12015-10-14 11:33:11 -0700398 void OnDataChannelOpenMessage(const std::string& label,
399 const InternalDataChannelInit& config) {
400 last_data_channel_label_ = label;
401 last_data_channel_config_ = config;
402 }
403
deadbeef057ecf02016-01-20 14:30:43 -0800404 void OnSessionDestroyed() { session_destroyed_ = true; }
405
htaa2a49d92016-03-04 02:51:39 -0800406 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000407
408 void InitWithIceTransport(
409 PeerConnectionInterface::IceTransportsType ice_transport_type) {
htaa2a49d92016-03-04 02:51:39 -0800410 configuration_.type = ice_transport_type;
411 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000412 }
413
414 void InitWithBundlePolicy(
415 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800416 configuration_.bundle_policy = bundle_policy;
417 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700418 }
419
420 void InitWithRtcpMuxPolicy(
421 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
422 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800423 configuration_.rtcp_mux_policy = rtcp_mux_policy;
424 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000425 }
426
Henrik Boström87713d02015-08-25 09:53:21 +0200427 // Successfully init with DTLS; with a certificate generated and supplied or
428 // with a store that generates it for us.
429 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
kwibergd1fe2812016-04-27 06:47:29 -0700430 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store;
Henrik Boström87713d02015-08-25 09:53:21 +0200431 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800432 configuration_.certificates.push_back(
Henrik Boström87713d02015-08-25 09:53:21 +0200433 FakeDtlsIdentityStore::GenerateCertificate());
434 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
435 dtls_identity_store.reset(new FakeDtlsIdentityStore());
436 dtls_identity_store->set_should_fail(false);
437 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700438 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200439 }
htaa2a49d92016-03-04 02:51:39 -0800440 Init(std::move(dtls_identity_store));
Henrik Boström87713d02015-08-25 09:53:21 +0200441 }
442
443 // Init with DTLS with a store that will fail to generate a certificate.
444 void InitWithDtlsIdentityGenFail() {
kwibergd1fe2812016-04-27 06:47:29 -0700445 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store(
Henrik Boström5e56c592015-08-11 10:33:13 +0200446 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200447 dtls_identity_store->set_should_fail(true);
htaa2a49d92016-03-04 02:51:39 -0800448 Init(std::move(dtls_identity_store));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000449 }
450
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451 void InitWithDtmfCodec() {
452 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700453 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
454 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455 std::vector<cricket::AudioCodec> codecs;
456 codecs.push_back(kTelephoneEventCodec);
457 media_engine_->SetAudioCodecs(codecs);
458 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000459 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460 }
461
deadbeefab9b2d12015-10-14 11:33:11 -0700462 void SendAudioVideoStream1() {
463 send_stream_1_ = true;
464 send_stream_2_ = false;
465 send_audio_ = true;
466 send_video_ = true;
467 }
468
469 void SendAudioVideoStream2() {
470 send_stream_1_ = false;
471 send_stream_2_ = true;
472 send_audio_ = true;
473 send_video_ = true;
474 }
475
476 void SendAudioVideoStream1And2() {
477 send_stream_1_ = true;
478 send_stream_2_ = true;
479 send_audio_ = true;
480 send_video_ = true;
481 }
482
483 void SendNothing() {
484 send_stream_1_ = false;
485 send_stream_2_ = false;
486 send_audio_ = false;
487 send_video_ = false;
488 }
489
490 void SendAudioOnlyStream2() {
491 send_stream_1_ = false;
492 send_stream_2_ = true;
493 send_audio_ = true;
494 send_video_ = false;
495 }
496
497 void SendVideoOnlyStream2() {
498 send_stream_1_ = false;
499 send_stream_2_ = true;
500 send_audio_ = false;
501 send_video_ = true;
502 }
503
504 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
505 if (send_stream_1_ && send_audio_) {
506 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
507 kStream1);
508 }
509 if (send_stream_1_ && send_video_) {
510 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
511 kStream1);
512 }
513 if (send_stream_2_ && send_audio_) {
514 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
515 kStream2);
516 }
517 if (send_stream_2_ && send_video_) {
518 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
519 kStream2);
520 }
521 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
522 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
523 data_channel_->label(),
524 data_channel_->label());
525 }
526 }
527
528 void GetOptionsForOffer(
529 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
530 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800531 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700532
deadbeefc80741f2015-10-22 13:14:45 -0700533 AddStreamsToOptions(session_options);
534 if (rtc_options.offer_to_receive_audio ==
535 RTCOfferAnswerOptions::kUndefined) {
536 session_options->recv_audio =
537 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
538 }
539 if (rtc_options.offer_to_receive_video ==
540 RTCOfferAnswerOptions::kUndefined) {
541 session_options->recv_video =
542 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
543 }
544 session_options->bundle_enabled =
545 session_options->bundle_enabled &&
546 (session_options->has_audio() || session_options->has_video() ||
547 session_options->has_data());
548
deadbeefab9b2d12015-10-14 11:33:11 -0700549 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
550 session_options->data_channel_type = cricket::DCT_SCTP;
551 }
552 }
553
htaa2a49d92016-03-04 02:51:39 -0800554 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
555 // ParseConstraintsForAnswer is used to set some defaults.
556 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700557
deadbeefc80741f2015-10-22 13:14:45 -0700558 AddStreamsToOptions(session_options);
559 session_options->bundle_enabled =
560 session_options->bundle_enabled &&
561 (session_options->has_audio() || session_options->has_video() ||
562 session_options->has_data());
563
deadbeefab9b2d12015-10-14 11:33:11 -0700564 if (session_->data_channel_type() == cricket::DCT_SCTP) {
565 session_options->data_channel_type = cricket::DCT_SCTP;
566 }
567 }
568
569 // Creates a local offer and applies it. Starts ICE.
570 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 // to decide which streams to create.
572 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000573 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000574 SetLocalDescriptionWithoutError(offer);
575 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
576 observer_.ice_gathering_state_,
577 kIceCandidatesTimeout);
578 }
579
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000580 SessionDescriptionInterface* CreateOffer() {
581 PeerConnectionInterface::RTCOfferAnswerOptions options;
582 options.offer_to_receive_audio =
583 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
584
585 return CreateOffer(options);
586 }
587
wu@webrtc.org91053e72013-08-10 07:18:04 +0000588 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800589 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000590 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000591 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700592 cricket::MediaSessionOptions session_options;
593 GetOptionsForOffer(options, &session_options);
594 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000595 EXPECT_TRUE_WAIT(
596 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000597 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000598 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000599 }
600
601 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800602 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000603 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000604 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800605 cricket::MediaSessionOptions session_options = options;
606 GetOptionsForAnswer(&session_options);
607 // Overwrite recv_audio and recv_video with passed-in values.
608 session_options.recv_video = options.recv_video;
609 session_options.recv_audio = options.recv_audio;
610 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000611 EXPECT_TRUE_WAIT(
612 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000613 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000614 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000615 }
616
htaa2a49d92016-03-04 02:51:39 -0800617 SessionDescriptionInterface* CreateAnswer() {
618 cricket::MediaSessionOptions options;
619 options.recv_video = true;
620 options.recv_audio = true;
621 return CreateAnswer(options);
622 }
623
wu@webrtc.org364f2042013-11-20 21:49:41 +0000624 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000625 return (session_->voice_channel() != NULL &&
626 session_->video_channel() != NULL);
627 }
628
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000629 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
630 ASSERT_TRUE(session_.get() != NULL);
631 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
632 ASSERT_TRUE(content != NULL);
633 const cricket::AudioContentDescription* audio_content =
634 static_cast<const cricket::AudioContentDescription*>(
635 content->description);
636 ASSERT_TRUE(audio_content != NULL);
637 ASSERT_EQ(1U, audio_content->cryptos().size());
638 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
639 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
640 audio_content->cryptos()[0].cipher_suite);
641 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
642 audio_content->protocol());
643
644 content = cricket::GetFirstVideoContent(sdp);
645 ASSERT_TRUE(content != NULL);
646 const cricket::VideoContentDescription* video_content =
647 static_cast<const cricket::VideoContentDescription*>(
648 content->description);
649 ASSERT_TRUE(video_content != NULL);
650 ASSERT_EQ(1U, video_content->cryptos().size());
651 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
652 video_content->cryptos()[0].cipher_suite);
653 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
654 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
655 video_content->protocol());
656 }
657
658 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
659 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
660 ASSERT_TRUE(content != NULL);
661 const cricket::AudioContentDescription* audio_content =
662 static_cast<const cricket::AudioContentDescription*>(
663 content->description);
664 ASSERT_TRUE(audio_content != NULL);
665 ASSERT_EQ(0U, audio_content->cryptos().size());
666
667 content = cricket::GetFirstVideoContent(sdp);
668 ASSERT_TRUE(content != NULL);
669 const cricket::VideoContentDescription* video_content =
670 static_cast<const cricket::VideoContentDescription*>(
671 content->description);
672 ASSERT_TRUE(video_content != NULL);
673 ASSERT_EQ(0U, video_content->cryptos().size());
674
675 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700676 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000677 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700678 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679 video_content->protocol());
680 } else {
681 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
682 audio_content->protocol());
683 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
684 video_content->protocol());
685 }
686 }
687
688 // Set the internal fake description factories to do DTLS-SRTP.
689 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000690 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000692 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200693 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800694 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700695 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800696 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
698 }
699
700 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
701 bool expected) {
702 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
703 ASSERT_TRUE(audio != NULL);
704 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 const TransportInfo* video = sdp->GetTransportInfoByName("video");
706 ASSERT_TRUE(video != NULL);
707 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 }
709
710 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000711 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000713 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000714 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000716 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000718 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
719 offer);
htaa2a49d92016-03-04 02:51:39 -0800720 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 // Answer should be NULL as no crypto params in offer.
722 ASSERT_TRUE(answer == NULL);
723 }
724
725 void VerifyAnswerFromCryptoOffer() {
726 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000727 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700729 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
731 ASSERT_TRUE(offer.get() != NULL);
732 VerifyCryptoParams(offer->description());
733 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700734 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735 ASSERT_TRUE(answer.get() != NULL);
736 VerifyCryptoParams(answer->description());
737 }
738
deadbeef0ed85b22016-02-23 17:24:52 -0800739 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
740 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800742 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 }
744
745 const cricket::ContentInfos& contents = desc1->contents();
746 cricket::ContentInfos::const_iterator it = contents.begin();
747
748 for (; it != contents.end(); ++it) {
749 const cricket::TransportDescription* transport_desc1 =
750 desc1->GetTransportDescriptionByName(it->name);
751 const cricket::TransportDescription* transport_desc2 =
752 desc2->GetTransportDescriptionByName(it->name);
753 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800754 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755 }
756 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
757 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800758 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 }
760 }
deadbeef0ed85b22016-02-23 17:24:52 -0800761 return true;
762 }
763
764 // Compares ufrag/password only for the specified |media_type|.
765 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
766 const cricket::SessionDescription* desc2,
767 cricket::MediaType media_type) {
768 if (desc1->contents().size() != desc2->contents().size()) {
769 return false;
770 }
771
772 const cricket::ContentInfo* cinfo =
773 cricket::GetFirstMediaContent(desc1->contents(), media_type);
774 const cricket::TransportDescription* transport_desc1 =
775 desc1->GetTransportDescriptionByName(cinfo->name);
776 const cricket::TransportDescription* transport_desc2 =
777 desc2->GetTransportDescriptionByName(cinfo->name);
778 if (!transport_desc1 || !transport_desc2) {
779 return false;
780 }
781 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
782 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
783 return false;
784 }
785 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000787
788 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
789 std::string *sdp) {
790 const cricket::SessionDescription* desc = current_desc->description();
791 EXPECT_TRUE(current_desc->ToString(sdp));
792
793 const cricket::ContentInfos& contents = desc->contents();
794 cricket::ContentInfos::const_iterator it = contents.begin();
795 // Replace ufrag and pwd lines with empty strings.
796 for (; it != contents.end(); ++it) {
797 const cricket::TransportDescription* transport_desc =
798 desc->GetTransportDescriptionByName(it->name);
799 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
800 + "\r\n";
801 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
802 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000803 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000804 "", 0,
805 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000806 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000807 "", 0,
808 sdp);
809 }
810 }
811
deadbeef0ed85b22016-02-23 17:24:52 -0800812 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
813 const std::string& ufrag,
814 const std::string& pwd) {
815 cricket::SessionDescription* desc = current_desc->description();
816 for (TransportInfo& transport_info : desc->transport_infos()) {
817 cricket::TransportDescription& transport_desc =
818 transport_info.description;
819 transport_desc.ice_ufrag = ufrag;
820 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000821 }
822 }
823
deadbeef0ed85b22016-02-23 17:24:52 -0800824 // Sets ufrag/pwd for specified |media_type|.
825 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
826 cricket::MediaType media_type,
827 const std::string& ufrag,
828 const std::string& pwd) {
829 cricket::SessionDescription* desc = current_desc->description();
830 const cricket::ContentInfo* cinfo =
831 cricket::GetFirstMediaContent(desc->contents(), media_type);
832 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
833 cricket::TransportDescription* transport_desc =
834 &transport_info->description;
835 transport_desc->ice_ufrag = ufrag;
836 transport_desc->ice_pwd = pwd;
837 }
838
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 // Creates a remote offer and and applies it as a remote description,
840 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700841 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 // to decide which local and remote streams to create.
843 void CreateAndSetRemoteOfferAndLocalAnswer() {
844 SessionDescriptionInterface* offer = CreateRemoteOffer();
845 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800846 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 SetLocalDescriptionWithoutError(answer);
848 }
849 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
850 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700851 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 }
853 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700854 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 SetLocalDescriptionWithoutError(desc);
856 EXPECT_EQ(expected_state, session_->state());
857 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000858 void SetLocalDescriptionExpectError(const std::string& action,
859 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 SessionDescriptionInterface* desc) {
861 std::string error;
862 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000863 std::string sdp_type = "local ";
864 sdp_type.append(action);
865 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 EXPECT_NE(std::string::npos, error.find(expected_error));
867 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000868 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
869 SessionDescriptionInterface* desc) {
870 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
871 expected_error, desc);
872 }
873 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
874 SessionDescriptionInterface* desc) {
875 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
876 expected_error, desc);
877 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
879 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
880 }
881 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700882 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 SetRemoteDescriptionWithoutError(desc);
884 EXPECT_EQ(expected_state, session_->state());
885 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000886 void SetRemoteDescriptionExpectError(const std::string& action,
887 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 SessionDescriptionInterface* desc) {
889 std::string error;
890 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000891 std::string sdp_type = "remote ";
892 sdp_type.append(action);
893 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 EXPECT_NE(std::string::npos, error.find(expected_error));
895 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000896 void SetRemoteDescriptionOfferExpectError(
897 const std::string& expected_error, SessionDescriptionInterface* desc) {
898 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
899 expected_error, desc);
900 }
901 void SetRemoteDescriptionPranswerExpectError(
902 const std::string& expected_error, SessionDescriptionInterface* desc) {
903 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
904 expected_error, desc);
905 }
906 void SetRemoteDescriptionAnswerExpectError(
907 const std::string& expected_error, SessionDescriptionInterface* desc) {
908 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
909 expected_error, desc);
910 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911
912 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
913 SessionDescriptionInterface** nocrypto_answer) {
914 // Create a SDP without Crypto.
915 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000916 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 options.bundle_enabled = true;
918 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
919 ASSERT_TRUE(*offer != NULL);
920 VerifyCryptoParams((*offer)->description());
921
922 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
923 cricket::SEC_DISABLED);
924 EXPECT_TRUE(*nocrypto_answer != NULL);
925 }
926
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000927 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
928 SessionDescriptionInterface** nodtls_answer) {
929 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000930 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000931 options.bundle_enabled = true;
932
kwibergd1fe2812016-04-27 06:47:29 -0700933 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000934 CreateRemoteOffer(options, cricket::SEC_ENABLED));
935
936 *nodtls_answer =
937 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
938 EXPECT_TRUE(*nodtls_answer != NULL);
939 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
940 VerifyCryptoParams((*nodtls_answer)->description());
941
942 SetFactoryDtlsSrtp();
943 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
944 ASSERT_TRUE(*offer != NULL);
945 VerifyFingerprintStatus((*offer)->description(), true);
946 VerifyCryptoParams((*offer)->description());
947 }
948
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 JsepSessionDescription* CreateRemoteOfferWithVersion(
950 cricket::MediaSessionOptions options,
951 cricket::SecurePolicy secure_policy,
952 const std::string& session_version,
953 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000954 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 const cricket::SessionDescription* cricket_desc = NULL;
956 if (current_desc) {
957 cricket_desc = current_desc->description();
958 session_id = current_desc->session_id();
959 }
960
961 desc_factory_->set_secure(secure_policy);
962 JsepSessionDescription* offer(
963 new JsepSessionDescription(JsepSessionDescription::kOffer));
964 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
965 session_id, session_version)) {
966 delete offer;
967 offer = NULL;
968 }
969 return offer;
970 }
971 JsepSessionDescription* CreateRemoteOffer(
972 cricket::MediaSessionOptions options) {
973 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
974 kSessionVersion, NULL);
975 }
976 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000977 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
978 return CreateRemoteOfferWithVersion(
979 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 }
981 JsepSessionDescription* CreateRemoteOffer(
982 cricket::MediaSessionOptions options,
983 const SessionDescriptionInterface* current_desc) {
984 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
985 kSessionVersion, current_desc);
986 }
987
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000988 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
989 const char* sctp_stream_name, int new_port,
990 cricket::MediaSessionOptions options) {
991 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000992 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
993 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000994 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
995 }
996
997 // Takes ownership of offer_basis (and deletes it).
998 JsepSessionDescription* ChangeSDPSctpPort(
999 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1000 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1001 // SessionDescription from the mutated string.
1002 const char* default_port_str = "5000";
1003 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001004 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001005 std::string offer_str;
1006 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001007 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001008 new_port_str, strlen(new_port_str),
1009 &offer_str);
1010 JsepSessionDescription* offer = new JsepSessionDescription(
1011 offer_basis->type());
1012 delete offer_basis;
1013 offer->Initialize(offer_str, NULL);
1014 return offer;
1015 }
1016
deadbeefab9b2d12015-10-14 11:33:11 -07001017 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018 // before this function to decide which streams to create.
1019 JsepSessionDescription* CreateRemoteOffer() {
1020 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001021 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 return CreateRemoteOffer(options, session_->remote_description());
1023 }
1024
1025 JsepSessionDescription* CreateRemoteAnswer(
1026 const SessionDescriptionInterface* offer,
1027 cricket::MediaSessionOptions options,
1028 cricket::SecurePolicy policy) {
1029 desc_factory_->set_secure(policy);
1030 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001031 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 JsepSessionDescription* answer(
1033 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1034 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1035 options, NULL),
1036 session_id, kSessionVersion)) {
1037 delete answer;
1038 answer = NULL;
1039 }
1040 return answer;
1041 }
1042
1043 JsepSessionDescription* CreateRemoteAnswer(
1044 const SessionDescriptionInterface* offer,
1045 cricket::MediaSessionOptions options) {
1046 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1047 }
1048
deadbeefab9b2d12015-10-14 11:33:11 -07001049 // Creates an answer session description.
1050 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001051 // to decide which streams to create.
1052 JsepSessionDescription* CreateRemoteAnswer(
1053 const SessionDescriptionInterface* offer) {
1054 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001055 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1057 }
1058
1059 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001060 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001061 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001062 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001063
1064 PeerConnectionInterface::RTCOfferAnswerOptions options;
1065 options.use_rtp_mux = bundle;
1066
1067 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1069 // and answer.
1070 SetLocalDescriptionWithoutError(offer);
1071
kwibergd1fe2812016-04-27 06:47:29 -07001072 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001073 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 std::string sdp;
1075 EXPECT_TRUE(answer->ToString(&sdp));
1076
1077 size_t expected_candidate_num = 2;
1078 if (!rtcp_mux) {
1079 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1080 // for rtp and rtcp.
1081 expected_candidate_num = 4;
1082 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 const std::string kRtcpMux = "a=rtcp-mux";
1084 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001085 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001086 kXRtcpMux.c_str(), kXRtcpMux.length(),
1087 &sdp);
1088 }
1089
1090 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1091 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001092
1093 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001094 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001095 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1096 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001097 if (bundle) {
1098 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1099 } else {
1100 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 }
1102 }
1103 // Tests that we can only send DTMF when the dtmf codec is supported.
1104 void TestCanInsertDtmf(bool can) {
1105 if (can) {
1106 InitWithDtmfCodec();
1107 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001108 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001109 }
deadbeefab9b2d12015-10-14 11:33:11 -07001110 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 CreateAndSetRemoteOfferAndLocalAnswer();
1112 EXPECT_FALSE(session_->CanInsertDtmf(""));
1113 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1114 }
1115
zhihuang3a334652016-05-05 18:37:49 -07001116 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1117 const std::string& codec_name) {
1118 for (const auto& content : desc->description()->contents()) {
1119 if (static_cast<cricket::MediaContentDescription*>(content.description)
1120 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1121 const auto* mdesc =
1122 static_cast<cricket::VideoContentDescription*>(content.description);
1123 for (const auto& codec : mdesc->codecs()) {
1124 if (codec.name == codec_name) {
1125 return true;
1126 }
1127 }
1128 }
1129 }
1130 return false;
1131 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001132 // Helper class to configure loopback network and verify Best
1133 // Connection using right IP protocol for TestLoopbackCall
1134 // method. LoopbackNetworkManager applies firewall rules to block
1135 // all ping traffic once ICE completed, and remove them to observe
1136 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1137 // verifies the best connection is using the right IP protocol after
1138 // initial ICE convergences.
1139
1140 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001141 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001142 LoopbackNetworkConfiguration()
1143 : test_ipv6_network_(false),
1144 test_extra_ipv4_network_(false),
1145 best_connection_after_initial_ice_converged_(1, 0) {}
1146
1147 // Used to track the expected best connection count in each IP protocol.
1148 struct ExpectedBestConnection {
1149 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1150 : ipv4_count_(ipv4_count),
1151 ipv6_count_(ipv6_count) {}
1152
1153 int ipv4_count_;
1154 int ipv6_count_;
1155 };
1156
1157 bool test_ipv6_network_;
1158 bool test_extra_ipv4_network_;
1159 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1160
1161 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001162 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001163 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1164 }
1165
1166 private:
jbauchac8869e2015-07-03 01:36:14 -07001167 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001168 const ExpectedBestConnection& expected) const {
1169 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001170 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1171 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001172 expected.ipv4_count_);
1173 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001174 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1175 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001176 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001177 // This is used in the loopback call so there is only single host to host
1178 // candidate pair.
1179 EXPECT_EQ(metrics_observer->GetEnumCounter(
1180 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1181 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001182 0);
1183 EXPECT_EQ(metrics_observer->GetEnumCounter(
1184 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1185 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001186 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001187 }
1188 };
1189
1190 class LoopbackNetworkManager {
1191 public:
1192 LoopbackNetworkManager(WebRtcSessionTest* session,
1193 const LoopbackNetworkConfiguration& config)
1194 : config_(config) {
1195 session->AddInterface(
1196 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1197 if (config_.test_extra_ipv4_network_) {
1198 session->AddInterface(
1199 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1200 }
1201 if (config_.test_ipv6_network_) {
1202 session->AddInterface(
1203 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1204 }
1205 }
1206
1207 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1208 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1209 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1210 if (config_.test_extra_ipv4_network_) {
1211 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1212 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1213 }
1214 if (config_.test_ipv6_network_) {
1215 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1216 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1217 }
1218 }
1219
1220 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1221
1222 private:
1223 LoopbackNetworkConfiguration config_;
1224 };
1225
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001226 // The method sets up a call from the session to itself, in a loopback
1227 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001228 // disconnection, and then a permanent disconnection.
1229 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001230 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1231 // While running the call, this method also checks if the session goes through
1232 // the correct sequence of ICE states when a connection is established,
1233 // broken, and re-established.
1234 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001235 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1236 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001237 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001238
stefanc1aeaf02015-10-15 07:26:07 -07001239 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001240 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001241 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001242 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001243
1244 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1245 observer_.ice_gathering_state_);
1246 SetLocalDescriptionWithoutError(offer);
1247 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1248 observer_.ice_connection_state_);
1249 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001250 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1252 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001253 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001254
1255 std::string sdp;
1256 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001257 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1258 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001259 ASSERT_TRUE(desc != NULL);
1260 SetRemoteDescriptionWithoutError(desc);
1261
1262 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001263 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001264
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001265 // The ice connection state is "Connected" too briefly to catch in a test.
1266 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001267 observer_.ice_connection_state_, kIceCandidatesTimeout);
1268 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001269
stefanc1aeaf02015-10-15 07:26:07 -07001270 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1271 LoopbackNetworkManager loopback_network_manager(this, config);
1272 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001273 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001274 // Adding firewall rule to block ping requests, which should cause
1275 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001276
1277 loopback_network_manager.ApplyFirewallRules(fss_.get());
1278
1279 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1281 observer_.ice_connection_state_,
1282 kIceCandidatesTimeout);
1283
jbauchac8869e2015-07-03 01:36:14 -07001284 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001285
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001286 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001287 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001289 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001290 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291 observer_.ice_connection_state_,
1292 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001293
1294 // Now we block ping requests and wait until the ICE connection transitions
1295 // to the Failed state. This will take at least 30 seconds because it must
1296 // wait for the Port to timeout.
1297 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001298
1299 loopback_network_manager.ApplyFirewallRules(fss_.get());
1300 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001301 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001302 observer_.ice_connection_state_,
1303 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304 }
1305
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001306 void TestLoopbackCall() {
1307 LoopbackNetworkConfiguration config;
1308 TestLoopbackCall(config);
1309 }
1310
stefanc1aeaf02015-10-15 07:26:07 -07001311 void TestPacketOptions() {
1312 media_controller_.reset(
1313 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1314 LoopbackNetworkConfiguration config;
1315 LoopbackNetworkManager loopback_network_manager(this, config);
1316
1317 SetupLoopbackCall();
1318
1319 uint8_t test_packet[15] = {0};
1320 rtc::PacketOptions options;
1321 options.packet_id = 10;
1322 media_engine_->GetVideoChannel(0)
1323 ->SendRtp(test_packet, sizeof(test_packet), options);
1324
1325 const int kPacketTimeout = 2000;
1326 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1327 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1328 }
1329
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1331 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001332 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1333 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001334
1335 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001336 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1337 codecs.push_back(kCNCodec1);
1338 codecs.push_back(kCNCodec2);
1339 media_engine_->SetAudioCodecs(codecs);
1340 desc_factory_->set_audio_codecs(codecs);
1341 }
1342
1343 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1344 const cricket::ContentDescription* description = content->description;
1345 ASSERT(description != NULL);
1346 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001347 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001348 ASSERT(audio_content_desc != NULL);
1349 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1350 if (audio_content_desc->codecs()[i].name == "CN")
1351 return false;
1352 }
1353 return true;
1354 }
1355
deadbeefab9b2d12015-10-14 11:33:11 -07001356 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001357 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001358 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001359 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1360 data_channel_ = DataChannel::Create(
1361 session_.get(), session_->data_channel_type(), "datachannel", dci);
1362 }
1363
1364 void SetLocalDescriptionWithDataChannel() {
1365 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001366 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001367 SetLocalDescriptionWithoutError(offer);
1368 }
1369
wu@webrtc.org91053e72013-08-10 07:18:04 +00001370 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001371 RTCCertificateGenerationMethod cert_gen_method,
1372 CreateSessionDescriptionRequest::Type type) {
1373 InitWithDtls(cert_gen_method);
1374 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1375 }
1376
1377 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1378 CreateSessionDescriptionRequest::Type type) {
1379 InitWithDtlsIdentityGenFail();
1380 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1381 }
1382
1383 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001384 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001385 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001386 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001387 if (type == CreateSessionDescriptionRequest::kAnswer) {
1388 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001389 std::unique_ptr<JsepSessionDescription> offer(
1390 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001391 ASSERT_TRUE(offer.get() != NULL);
1392 SetRemoteDescriptionWithoutError(offer.release());
1393 }
1394
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001395 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001396 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001397 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001398 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001399 observers[kNumber];
1400 for (int i = 0; i < kNumber; ++i) {
1401 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1402 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001403 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001404 } else {
htaa2a49d92016-03-04 02:51:39 -08001405 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001406 }
1407 }
1408
1409 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1410 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1411 WebRtcSessionCreateSDPObserverForTest::kFailed;
1412
1413 for (int i = 0; i < kNumber; ++i) {
1414 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1415 if (success) {
1416 EXPECT_TRUE(observers[i]->description() != NULL);
1417 } else {
1418 EXPECT_TRUE(observers[i]->description() == NULL);
1419 }
1420 }
1421 }
1422
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001423 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001424 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001425 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001426 turn_server.credentials = credentials;
1427 turn_server.ports.push_back(
1428 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1429 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001430 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001431 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001432 }
1433
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001434 cricket::FakeMediaEngine* media_engine_;
1435 cricket::FakeDataEngine* data_engine_;
kwibergd1fe2812016-04-27 06:47:29 -07001436 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001437 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001438 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1439 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1440 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1441 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1442 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1443 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001444 rtc::SocketServerScope ss_scope_;
1445 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001446 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001447 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001448 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001449 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001450 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001451 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001452 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001453 MockIceObserver observer_;
1454 cricket::FakeVideoMediaChannel* video_channel_;
1455 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001456 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001457 // The following flags affect options created for CreateOffer/CreateAnswer.
1458 bool send_stream_1_ = false;
1459 bool send_stream_2_ = false;
1460 bool send_audio_ = false;
1461 bool send_video_ = false;
1462 rtc::scoped_refptr<DataChannel> data_channel_;
1463 // Last values received from data channel creation signal.
1464 std::string last_data_channel_label_;
1465 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001466 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467};
1468
Henrik Boström87713d02015-08-25 09:53:21 +02001469TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1470 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001471 // SDES is disabled when DTLS is on.
1472 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473}
1474
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001475TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001476 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001477 // SDES is required if DTLS is off.
1478 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001479}
1480
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1482 TestSessionCandidatesWithBundleRtcpMux(false, false);
1483}
1484
1485// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1486// with rtcp-mux and/or bundle.
1487TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1488 TestSessionCandidatesWithBundleRtcpMux(false, true);
1489}
1490
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1492 TestSessionCandidatesWithBundleRtcpMux(true, true);
1493}
1494
1495TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001496 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1497 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001498 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001499 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500 InitiateCall();
1501 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1502 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1503 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1504}
1505
minyuec8930ba2016-01-22 06:17:46 -08001506// Crashes on Win only. See webrtc:5411.
1507#if defined(WEBRTC_WIN)
1508#define MAYBE_TestStunError DISABLED_TestStunError
1509#else
1510#define MAYBE_TestStunError TestStunError
1511#endif
1512TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001513 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1514 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001515 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001516 rtc::FP_UDP,
1517 rtc::FD_ANY,
1518 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001519 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001520 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001521 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001522 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1524 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1525 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1526}
1527
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001528// Test session delivers no candidates gathered when constraint set to "none".
1529TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1530 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001531 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001532 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001533 InitiateCall();
1534 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1535 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1536 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1537}
1538
1539// Test session delivers only relay candidates gathered when constaint set to
1540// "relay".
1541TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1542 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1543 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001544 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001545 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001546 InitiateCall();
1547 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1548 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1549 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1550 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1551 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1552 observer_.mline_0_candidates_[i].type());
1553 }
1554 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1555 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1556 observer_.mline_1_candidates_[i].type());
1557 }
1558}
1559
1560// Test session delivers all candidates gathered when constaint set to "all".
1561TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1562 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001563 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001564 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001565 InitiateCall();
1566 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1567 // Host + STUN. By default allocator is disabled to gather relay candidates.
1568 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1569 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1570}
1571
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001572TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001573 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001574 SessionDescriptionInterface* offer = NULL;
1575 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1576 std::string unknown_action;
1577 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1578 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1579}
1580
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581// Test creating offers and receive answers and make sure the
1582// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001583TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001584 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001585 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001586 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 const std::string session_id_orig = offer->session_id();
1588 const std::string session_version_orig = offer->session_version();
1589 SetLocalDescriptionWithoutError(offer);
1590
deadbeefab9b2d12015-10-14 11:33:11 -07001591 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592 SessionDescriptionInterface* answer =
1593 CreateRemoteAnswer(session_->local_description());
1594 SetRemoteDescriptionWithoutError(answer);
1595
1596 video_channel_ = media_engine_->GetVideoChannel(0);
1597 voice_channel_ = media_engine_->GetVoiceChannel(0);
1598
1599 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1600 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1601
1602 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1603 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1604
1605 ASSERT_EQ(1u, video_channel_->send_streams().size());
1606 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1607 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1608 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1609
1610 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001611 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001612 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001613
1614 // Verify the session id is the same and the session version is
1615 // increased.
1616 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001617 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1618 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619
1620 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001621 EXPECT_EQ(0u, video_channel_->send_streams().size());
1622 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623
deadbeefab9b2d12015-10-14 11:33:11 -07001624 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625 answer = CreateRemoteAnswer(session_->local_description());
1626 SetRemoteDescriptionWithoutError(answer);
1627
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628 // Make sure the receive streams have not changed.
1629 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1630 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1631 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1632 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1633}
1634
1635// Test receiving offers and creating answers and make sure the
1636// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001637TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001638 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001639 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001640 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001641 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642 SetRemoteDescriptionWithoutError(offer);
1643
deadbeefab9b2d12015-10-14 11:33:11 -07001644 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001645 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001646 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001647 SetLocalDescriptionWithoutError(answer);
1648
1649 const std::string session_id_orig = answer->session_id();
1650 const std::string session_version_orig = answer->session_version();
1651
1652 video_channel_ = media_engine_->GetVideoChannel(0);
1653 voice_channel_ = media_engine_->GetVoiceChannel(0);
1654
htaa2a49d92016-03-04 02:51:39 -08001655 ASSERT_TRUE(video_channel_);
1656 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1658 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1659
1660 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1661 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1662
1663 ASSERT_EQ(1u, video_channel_->send_streams().size());
1664 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1665 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1666 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1667
deadbeefab9b2d12015-10-14 11:33:11 -07001668 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001669 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670 SetRemoteDescriptionWithoutError(offer);
1671
1672 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001673 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001674 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675
1676 // Verify the session id is the same and the session version is
1677 // increased.
1678 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001679 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1680 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681 SetLocalDescriptionWithoutError(answer);
1682
1683 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1684 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1685 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1686 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1687 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1688 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1689
1690 // Make sure we have no send streams.
1691 EXPECT_EQ(0u, video_channel_->send_streams().size());
1692 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1693}
1694
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001695TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001696 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001697 media_engine_->set_fail_create_channel(true);
1698
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001699 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001700 ASSERT_TRUE(offer != NULL);
1701 // SetRemoteDescription and SetLocalDescription will take the ownership of
1702 // the offer.
1703 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001704 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001705 ASSERT_TRUE(offer != NULL);
1706 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1707}
1708
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001709//
1710// Tests for creating/setting SDP under different SDES/DTLS polices:
1711//
1712// --DTLS off and SDES on
1713// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1714// set local/remote offer/answer with crypto --> success
1715// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1716// failure
1717// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1718// failure
1719// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1720// failure
1721//
1722// --DTLS on and SDES off
1723// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1724// set local/remote offer/answer with DTLS fingerprint --> success
1725// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1726// fingerprint --> failure
1727// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1728// --> failure
1729// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1730// --> failure
1731//
1732// --Encryption disabled: DTLS off and SDES off
1733// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1734// answer without SDES or DTLS --> success
1735// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1736// answer without SDES or DTLS --> success
1737//
1738
1739// Test that we return a failure when applying a remote/local offer that doesn't
1740// have cryptos enabled when DTLS is off.
1741TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001742 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001744 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 JsepSessionDescription* offer = CreateRemoteOffer(
1746 options, cricket::SEC_DISABLED);
1747 ASSERT_TRUE(offer != NULL);
1748 VerifyNoCryptoParams(offer->description(), false);
1749 // SetRemoteDescription and SetLocalDescription will take the ownership of
1750 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001751 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1753 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001754 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755}
1756
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001757// Test that we return a failure when applying a local answer that doesn't have
1758// cryptos enabled when DTLS is off.
1759TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001760 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 SessionDescriptionInterface* offer = NULL;
1762 SessionDescriptionInterface* answer = NULL;
1763 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1764 // SetRemoteDescription and SetLocalDescription will take the ownership of
1765 // the offer.
1766 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001767 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768}
1769
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001770// Test we will return fail when apply an remote answer that doesn't have
1771// crypto enabled when DTLS is off.
1772TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001773 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 SessionDescriptionInterface* offer = NULL;
1775 SessionDescriptionInterface* answer = NULL;
1776 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1777 // SetRemoteDescription and SetLocalDescription will take the ownership of
1778 // the offer.
1779 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001780 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781}
1782
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001783// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1784// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001785TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001786 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001787 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001788 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001789 SetFactoryDtlsSrtp();
1790 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001791 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001792 JsepSessionDescription* offer =
1793 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794 ASSERT_TRUE(offer != NULL);
1795 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001796 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797
1798 // SetRemoteDescription will take the ownership of the offer.
1799 SetRemoteDescriptionWithoutError(offer);
1800
1801 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001802 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 ASSERT_TRUE(answer != NULL);
1804 VerifyFingerprintStatus(answer->description(), true);
1805 // Check that we don't have an a=crypto line in the answer.
1806 VerifyNoCryptoParams(answer->description(), true);
1807
1808 // Now set the local description, which should work, even without a=crypto.
1809 SetLocalDescriptionWithoutError(answer);
1810}
1811
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001812// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1813// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001814TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001815 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001816 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001817 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001818 SetFactoryDtlsSrtp();
1819
1820 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001821 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001822 ASSERT_TRUE(offer != NULL);
1823 VerifyFingerprintStatus(offer->description(), true);
1824 // Check that we don't have an a=crypto line in the offer.
1825 VerifyNoCryptoParams(offer->description(), true);
1826
1827 // Now set the local description, which should work, even without a=crypto.
1828 SetLocalDescriptionWithoutError(offer);
1829
1830 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001831 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001832 JsepSessionDescription* answer =
1833 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1834 ASSERT_TRUE(answer != NULL);
1835 VerifyFingerprintStatus(answer->description(), true);
1836 VerifyNoCryptoParams(answer->description(), true);
1837
1838 // SetRemoteDescription will take the ownership of the answer.
1839 SetRemoteDescriptionWithoutError(answer);
1840}
1841
1842// Test that if we support DTLS and the other side didn't offer a fingerprint,
1843// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001844TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001845 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001846 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001847 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001848 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001849 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001850 JsepSessionDescription* offer = CreateRemoteOffer(
1851 options, cricket::SEC_REQUIRED);
1852 ASSERT_TRUE(offer != NULL);
1853 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001854 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001856 // SetRemoteDescription will take the ownership of the offer.
1857 SetRemoteDescriptionOfferExpectError(
1858 kSdpWithoutDtlsFingerprint, offer);
1859
1860 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1861 // SetLocalDescription will take the ownership of the offer.
1862 SetLocalDescriptionOfferExpectError(
1863 kSdpWithoutDtlsFingerprint, offer);
1864}
1865
1866// Test that we return a failure when applying a local answer that doesn't have
1867// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001868TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
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());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001871 SessionDescriptionInterface* offer = NULL;
1872 SessionDescriptionInterface* answer = NULL;
1873 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1874
1875 // SetRemoteDescription and SetLocalDescription will take the ownership of
1876 // the offer and answer.
1877 SetRemoteDescriptionWithoutError(offer);
1878 SetLocalDescriptionAnswerExpectError(
1879 kSdpWithoutDtlsFingerprint, answer);
1880}
1881
1882// Test that we return a failure when applying a remote answer that doesn't have
1883// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001884TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001885 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001886 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001887 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001888 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001889 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001890 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001891 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001892 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001893 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001894
1895 // SetRemoteDescription and SetLocalDescription will take the ownership of
1896 // the offer and answer.
1897 SetLocalDescriptionWithoutError(offer);
1898 SetRemoteDescriptionAnswerExpectError(
1899 kSdpWithoutDtlsFingerprint, answer);
1900}
1901
1902// Test that we create a local offer without SDES or DTLS and accept a remote
1903// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001904TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001905 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001906 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001907 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001908
1909 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001910 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001911 ASSERT_TRUE(offer != NULL);
1912 VerifyFingerprintStatus(offer->description(), false);
1913 // Check that we don't have an a=crypto line in the offer.
1914 VerifyNoCryptoParams(offer->description(), false);
1915
1916 // Now set the local description, which should work, even without a=crypto.
1917 SetLocalDescriptionWithoutError(offer);
1918
1919 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001920 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001921 JsepSessionDescription* answer =
1922 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1923 ASSERT_TRUE(answer != NULL);
1924 VerifyFingerprintStatus(answer->description(), false);
1925 VerifyNoCryptoParams(answer->description(), false);
1926
1927 // SetRemoteDescription will take the ownership of the answer.
1928 SetRemoteDescriptionWithoutError(answer);
1929}
1930
1931// Test that we create a local answer without SDES or DTLS and accept a remote
1932// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001933TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001934 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001935 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001936
1937 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001938 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001939 JsepSessionDescription* offer =
1940 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1941 ASSERT_TRUE(offer != NULL);
1942 VerifyFingerprintStatus(offer->description(), false);
1943 VerifyNoCryptoParams(offer->description(), false);
1944
1945 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946 SetRemoteDescriptionWithoutError(offer);
1947
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001948 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001949 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950 ASSERT_TRUE(answer != NULL);
1951 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001952 // Check that we don't have an a=crypto line in the answer.
1953 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001955 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956 SetLocalDescriptionWithoutError(answer);
1957}
1958
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001959// Test that we can create and set an answer correctly when different
1960// SSL roles have been negotiated for different transports.
1961// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1962TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1963 SendAudioVideoStream1();
1964 InitWithDtls(GetParam());
1965 SetFactoryDtlsSrtp();
1966
1967 SessionDescriptionInterface* offer = CreateOffer();
1968 SetLocalDescriptionWithoutError(offer);
1969
1970 cricket::MediaSessionOptions options;
1971 options.recv_video = true;
1972
1973 // First, negotiate different SSL roles.
1974 SessionDescriptionInterface* answer =
1975 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1976 TransportInfo* audio_transport_info =
1977 answer->description()->GetTransportInfoByName("audio");
1978 audio_transport_info->description.connection_role =
1979 cricket::CONNECTIONROLE_ACTIVE;
1980 TransportInfo* video_transport_info =
1981 answer->description()->GetTransportInfoByName("video");
1982 video_transport_info->description.connection_role =
1983 cricket::CONNECTIONROLE_PASSIVE;
1984 SetRemoteDescriptionWithoutError(answer);
1985
1986 // Now create an offer in the reverse direction, and ensure the initial
1987 // offerer responds with an answer with correct SSL roles.
1988 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1989 kSessionVersion,
1990 session_->remote_description());
1991 SetRemoteDescriptionWithoutError(offer);
1992
htaa2a49d92016-03-04 02:51:39 -08001993 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001994 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1995 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1996 audio_transport_info->description.connection_role);
1997 video_transport_info = answer->description()->GetTransportInfoByName("video");
1998 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1999 video_transport_info->description.connection_role);
2000 SetLocalDescriptionWithoutError(answer);
2001
2002 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2003 // audio is transferred over to video in the answer that completes the BUNDLE
2004 // negotiation.
2005 options.bundle_enabled = true;
2006 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2007 kSessionVersion,
2008 session_->remote_description());
2009 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002010 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002011 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2012 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2013 audio_transport_info->description.connection_role);
2014 video_transport_info = answer->description()->GetTransportInfoByName("video");
2015 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2016 video_transport_info->description.connection_role);
2017 SetLocalDescriptionWithoutError(answer);
2018}
2019
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002021 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002022 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002024 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 SetLocalDescriptionWithoutError(offer);
2026
2027 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002028 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002029 SetLocalDescriptionWithoutError(offer2);
2030}
2031
2032TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002033 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002034 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002036 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037 SetRemoteDescriptionWithoutError(offer);
2038
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002039 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040 SetRemoteDescriptionWithoutError(offer2);
2041}
2042
2043TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002044 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002045 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002046 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002048 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002049 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2050 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051}
2052
2053TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002054 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002055 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002056 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002058 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002059 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002060 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061}
2062
2063TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002064 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002065 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002066 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002067 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068
htaa2a49d92016-03-04 02:51:39 -08002069 JsepSessionDescription* pranswer =
2070 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002071 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002072 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073
deadbeefab9b2d12015-10-14 11:33:11 -07002074 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002075 JsepSessionDescription* pranswer2 =
2076 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2078
deadbeefd59daf82015-10-14 15:02:44 -07002079 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080
deadbeefab9b2d12015-10-14 11:33:11 -07002081 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002082 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002083 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084}
2085
2086TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002087 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002088 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002089 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002090 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091
2092 JsepSessionDescription* pranswer =
2093 CreateRemoteAnswer(session_->local_description());
2094 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2095
2096 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002097 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098
deadbeefab9b2d12015-10-14 11:33:11 -07002099 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100 JsepSessionDescription* pranswer2 =
2101 CreateRemoteAnswer(session_->local_description());
2102 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2103
2104 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002105 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106
deadbeefab9b2d12015-10-14 11:33:11 -07002107 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108 SessionDescriptionInterface* answer =
2109 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002110 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111}
2112
2113TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002114 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002115 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002116 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002117
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118 SessionDescriptionInterface* answer =
2119 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002120 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2121 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122}
2123
2124TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002125 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002126 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002127 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002128
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 SessionDescriptionInterface* answer =
2130 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002131 SetRemoteDescriptionAnswerExpectError(
2132 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133}
2134
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002135// Tests that the remote candidates are added and removed successfully.
2136TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002137 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002138 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002140 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2141 "", "", "host", 0, "");
2142 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2144
deadbeefd59daf82015-10-14 15:02:44 -07002145 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2147
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002148 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002150
2151 // Fail since we have not set a remote description.
2152 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153
2154 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2155 session_->local_description());
2156 SetRemoteDescriptionWithoutError(answer);
2157
deadbeefd59daf82015-10-14 15:02:44 -07002158 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2159 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002160 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002161 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2162 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2163
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164 // Verifying the candidates are copied properly from internal vector.
2165 const SessionDescriptionInterface* remote_desc =
2166 session_->remote_description();
2167 ASSERT_TRUE(remote_desc != NULL);
2168 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2169 const IceCandidateCollection* candidates =
2170 remote_desc->candidates(kMediaContentIndex0);
2171 ASSERT_EQ(2u, candidates->count());
2172 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2173 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2174 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2175 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2176
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002177 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2178 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179 candidate.set_component(2);
2180 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2181 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002182 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183
2184 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2185 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002186
2187 // Remove candidate1 and candidate2
2188 std::vector<cricket::Candidate> remote_candidates;
2189 remote_candidates.push_back(ice_candidate1.candidate());
2190 remote_candidates.push_back(ice_candidate2.candidate());
2191 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2192 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002193}
2194
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002195// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002196// that it is retained if the remote session description is changed.
2197TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002198 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199 cricket::Candidate candidate1;
2200 candidate1.set_component(1);
2201 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2202 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002203 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002204 CreateAndSetRemoteOfferAndLocalAnswer();
2205
2206 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2207 const SessionDescriptionInterface* remote_desc =
2208 session_->remote_description();
2209 ASSERT_TRUE(remote_desc != NULL);
2210 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2211 const IceCandidateCollection* candidates =
2212 remote_desc->candidates(kMediaContentIndex0);
2213 ASSERT_EQ(1u, candidates->count());
2214 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2215
2216 // Update the RemoteSessionDescription with a new session description and
2217 // a candidate and check that the new remote session description contains both
2218 // candidates.
2219 SessionDescriptionInterface* offer = CreateRemoteOffer();
2220 cricket::Candidate candidate2;
2221 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2222 candidate2);
2223 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2224 SetRemoteDescriptionWithoutError(offer);
2225
2226 remote_desc = session_->remote_description();
2227 ASSERT_TRUE(remote_desc != NULL);
2228 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2229 candidates = remote_desc->candidates(kMediaContentIndex0);
2230 ASSERT_EQ(2u, candidates->count());
2231 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2232 // Username and password have be updated with the TransportInfo of the
2233 // SessionDescription, won't be equal to the original one.
2234 candidate2.set_username(candidates->at(0)->candidate().username());
2235 candidate2.set_password(candidates->at(0)->candidate().password());
2236 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2237 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2238 // No need to verify the username and password.
2239 candidate1.set_username(candidates->at(1)->candidate().username());
2240 candidate1.set_password(candidates->at(1)->candidate().password());
2241 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2242
2243 // Test that the candidate is ignored if we can add the same candidate again.
2244 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2245}
2246
2247// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002248// that they are retained if the local session description is changed. And if
2249// continual gathering is enabled, they are removed from the local session
2250// description when the network is down.
2251TEST_F(WebRtcSessionTest,
2252 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002253 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002254 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002255 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256 CreateAndSetRemoteOfferAndLocalAnswer();
2257
2258 const SessionDescriptionInterface* local_desc = session_->local_description();
2259 const IceCandidateCollection* candidates =
2260 local_desc->candidates(kMediaContentIndex0);
2261 ASSERT_TRUE(candidates != NULL);
2262 EXPECT_EQ(0u, candidates->count());
2263
2264 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2265
2266 local_desc = session_->local_description();
2267 candidates = local_desc->candidates(kMediaContentIndex0);
2268 ASSERT_TRUE(candidates != NULL);
2269 EXPECT_LT(0u, candidates->count());
2270 candidates = local_desc->candidates(1);
2271 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002272 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002273
2274 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002275 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276 CreateAndSetRemoteOfferAndLocalAnswer();
2277
2278 local_desc = session_->local_description();
2279 candidates = local_desc->candidates(kMediaContentIndex0);
2280 ASSERT_TRUE(candidates != NULL);
2281 EXPECT_LT(0u, candidates->count());
2282 candidates = local_desc->candidates(1);
2283 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002284 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002285
2286 candidates = local_desc->candidates(kMediaContentIndex0);
2287 size_t num_local_candidates = candidates->count();
2288 // Enable Continual Gathering
2289 session_->SetIceConfig(cricket::IceConfig(-1, -1, true, false, -1));
2290 // Bring down the network interface to trigger candidate removals.
2291 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2292 // Verify that all local candidates are removed.
2293 EXPECT_EQ(0, observer_.num_candidates_removed_);
2294 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2295 kIceCandidatesTimeout);
2296 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2297}
2298
2299// Tests that if continual gathering is disabled, local candidates won't be
2300// removed when the interface is turned down.
2301TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2302 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2303 Init();
2304 SendAudioVideoStream1();
2305 CreateAndSetRemoteOfferAndLocalAnswer();
2306
2307 const SessionDescriptionInterface* local_desc = session_->local_description();
2308 const IceCandidateCollection* candidates =
2309 local_desc->candidates(kMediaContentIndex0);
2310 ASSERT_TRUE(candidates != NULL);
2311 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2312
2313 size_t num_local_candidates = candidates->count();
2314 EXPECT_LT(0u, num_local_candidates);
2315 // By default, Continual Gathering is disabled.
2316 // Bring down the network interface.
2317 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2318 // Verify that the local candidates are not removed.
2319 rtc::Thread::Current()->ProcessMessages(1000);
2320 EXPECT_EQ(0, observer_.num_candidates_removed_);
2321 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322}
2323
2324// Test that we can set a remote session description with remote candidates.
2325TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002326 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327
2328 cricket::Candidate candidate1;
2329 candidate1.set_component(1);
2330 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2331 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002332 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002333 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002334
2335 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2336 SetRemoteDescriptionWithoutError(offer);
2337
2338 const SessionDescriptionInterface* remote_desc =
2339 session_->remote_description();
2340 ASSERT_TRUE(remote_desc != NULL);
2341 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2342 const IceCandidateCollection* candidates =
2343 remote_desc->candidates(kMediaContentIndex0);
2344 ASSERT_EQ(1u, candidates->count());
2345 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2346
htaa2a49d92016-03-04 02:51:39 -08002347 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348 SetLocalDescriptionWithoutError(answer);
2349}
2350
2351// Test that offers and answers contains ice candidates when Ice candidates have
2352// been gathered.
2353TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002354 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002355 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002356 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357 // Ice is started but candidates are not provided until SetLocalDescription
2358 // is called.
2359 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2360 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2361 CreateAndSetRemoteOfferAndLocalAnswer();
2362 // Wait until at least one local candidate has been collected.
2363 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2364 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365
kwibergd1fe2812016-04-27 06:47:29 -07002366 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002367
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2369 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370
2371 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2372 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002373 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2375 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376 SetLocalDescriptionWithoutError(answer);
2377}
2378
2379// Verifies TransportProxy and media channels are created with content names
2380// present in the SessionDescription.
2381TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002382 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002383 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002384 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002385
2386 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002387 // "video". Goal is to modify these content names and verify transport
2388 // channels
2389 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002390 // present in SDP.
2391 std::string sdp;
2392 EXPECT_TRUE(offer->ToString(&sdp));
2393 const std::string kAudioMid = "a=mid:audio";
2394 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2395 const std::string kVideoMid = "a=mid:video";
2396 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2397
2398 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002399 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400 kAudioMidReplaceStr.c_str(),
2401 kAudioMidReplaceStr.length(),
2402 &sdp);
2403 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002404 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002405 kVideoMidReplaceStr.c_str(),
2406 kVideoMidReplaceStr.length(),
2407 &sdp);
2408
2409 SessionDescriptionInterface* modified_offer =
2410 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2411
2412 SetRemoteDescriptionWithoutError(modified_offer);
2413
htaa2a49d92016-03-04 02:51:39 -08002414 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002415 SetLocalDescriptionWithoutError(answer);
2416
deadbeefcbecd352015-09-23 11:50:27 -07002417 cricket::TransportChannel* voice_transport_channel =
2418 session_->voice_rtp_transport_channel();
2419 EXPECT_TRUE(voice_transport_channel != NULL);
2420 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2421 cricket::TransportChannel* video_transport_channel =
2422 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002423 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002424 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2426 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2427}
2428
2429// Test that an offer contains the correct media content descriptions based on
2430// the send streams when no constraints have been set.
2431TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002432 Init();
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 ASSERT_TRUE(offer != NULL);
2436 const cricket::ContentInfo* content =
2437 cricket::GetFirstAudioContent(offer->description());
2438 EXPECT_TRUE(content != NULL);
2439 content = cricket::GetFirstVideoContent(offer->description());
2440 EXPECT_TRUE(content == NULL);
2441}
2442
2443// Test that an offer contains the correct media content descriptions based on
2444// the send streams when no constraints have been set.
2445TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002446 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002448 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002449 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002450
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002451 const cricket::ContentInfo* content =
2452 cricket::GetFirstAudioContent(offer->description());
2453 EXPECT_TRUE(content != NULL);
2454 content = cricket::GetFirstVideoContent(offer->description());
2455 EXPECT_TRUE(content == NULL);
2456
2457 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002458 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002459 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460 content = cricket::GetFirstAudioContent(offer->description());
2461 EXPECT_TRUE(content != NULL);
2462 content = cricket::GetFirstVideoContent(offer->description());
2463 EXPECT_TRUE(content != NULL);
2464}
2465
2466// Test that an offer contains no media content descriptions if
2467// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2468TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002469 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002470 PeerConnectionInterface::RTCOfferAnswerOptions options;
2471 options.offer_to_receive_audio = 0;
2472 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002473
kwibergd1fe2812016-04-27 06:47:29 -07002474 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002475
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476 ASSERT_TRUE(offer != NULL);
2477 const cricket::ContentInfo* content =
2478 cricket::GetFirstAudioContent(offer->description());
2479 EXPECT_TRUE(content == NULL);
2480 content = cricket::GetFirstVideoContent(offer->description());
2481 EXPECT_TRUE(content == NULL);
2482}
2483
2484// Test that an offer contains only audio media content descriptions if
2485// kOfferToReceiveAudio constraints are set to true.
2486TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002487 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002488 PeerConnectionInterface::RTCOfferAnswerOptions options;
2489 options.offer_to_receive_audio =
2490 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2491
kwibergd1fe2812016-04-27 06:47:29 -07002492 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002493
2494 const cricket::ContentInfo* content =
2495 cricket::GetFirstAudioContent(offer->description());
2496 EXPECT_TRUE(content != NULL);
2497 content = cricket::GetFirstVideoContent(offer->description());
2498 EXPECT_TRUE(content == NULL);
2499}
2500
2501// Test that an offer contains audio and video media content descriptions if
2502// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2503TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002504 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002505 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002506 PeerConnectionInterface::RTCOfferAnswerOptions options;
2507 options.offer_to_receive_audio =
2508 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2509 options.offer_to_receive_video =
2510 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2511
kwibergd1fe2812016-04-27 06:47:29 -07002512 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002513
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002514 const cricket::ContentInfo* content =
2515 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002516 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002517
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002518 content = cricket::GetFirstVideoContent(offer->description());
2519 EXPECT_TRUE(content != NULL);
2520
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002521 // Sets constraints to false and verifies that audio/video contents are
2522 // removed.
2523 options.offer_to_receive_audio = 0;
2524 options.offer_to_receive_video = 0;
2525 offer.reset(CreateOffer(options));
2526
2527 content = cricket::GetFirstAudioContent(offer->description());
2528 EXPECT_TRUE(content == NULL);
2529 content = cricket::GetFirstVideoContent(offer->description());
2530 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002531}
2532
2533// Test that an answer can not be created if the last remote description is not
2534// an offer.
2535TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002536 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002537 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002538 SetLocalDescriptionWithoutError(offer);
2539 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2540 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002541 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542}
2543
2544// Test that an answer contains the correct media content descriptions when no
2545// constraints have been set.
2546TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002547 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002549 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002550 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002551 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002552 const cricket::ContentInfo* content =
2553 cricket::GetFirstAudioContent(answer->description());
2554 ASSERT_TRUE(content != NULL);
2555 EXPECT_FALSE(content->rejected);
2556
2557 content = cricket::GetFirstVideoContent(answer->description());
2558 ASSERT_TRUE(content != NULL);
2559 EXPECT_FALSE(content->rejected);
2560}
2561
2562// Test that an answer contains the correct media content descriptions when no
2563// constraints have been set and the offer only contain audio.
2564TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002565 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566 // Create a remote offer with audio only.
2567 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002568
kwibergd1fe2812016-04-27 06:47:29 -07002569 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002570 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2571 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2572
2573 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002574 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002575 const cricket::ContentInfo* content =
2576 cricket::GetFirstAudioContent(answer->description());
2577 ASSERT_TRUE(content != NULL);
2578 EXPECT_FALSE(content->rejected);
2579
2580 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2581}
2582
2583// Test that an answer contains the correct media content descriptions when no
2584// constraints have been set.
2585TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002586 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002587 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002588 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002589 SetRemoteDescriptionWithoutError(offer.release());
2590 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002591 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002592 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593 const cricket::ContentInfo* content =
2594 cricket::GetFirstAudioContent(answer->description());
2595 ASSERT_TRUE(content != NULL);
2596 EXPECT_FALSE(content->rejected);
2597
2598 content = cricket::GetFirstVideoContent(answer->description());
2599 ASSERT_TRUE(content != NULL);
2600 EXPECT_FALSE(content->rejected);
2601}
2602
2603// Test that an answer contains the correct media content descriptions when
2604// constraints have been set but no stream is sent.
2605TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002606 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002607 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002608 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002609 SetRemoteDescriptionWithoutError(offer.release());
2610
htaa2a49d92016-03-04 02:51:39 -08002611 cricket::MediaSessionOptions session_options;
2612 session_options.recv_audio = false;
2613 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002614 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002615 CreateAnswer(session_options));
2616
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002617 const cricket::ContentInfo* content =
2618 cricket::GetFirstAudioContent(answer->description());
2619 ASSERT_TRUE(content != NULL);
2620 EXPECT_TRUE(content->rejected);
2621
2622 content = cricket::GetFirstVideoContent(answer->description());
2623 ASSERT_TRUE(content != NULL);
2624 EXPECT_TRUE(content->rejected);
2625}
2626
2627// Test that an answer contains the correct media content descriptions when
2628// constraints have been set and streams are sent.
2629TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002630 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002631 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002632 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002633 SetRemoteDescriptionWithoutError(offer.release());
2634
htaa2a49d92016-03-04 02:51:39 -08002635 cricket::MediaSessionOptions options;
2636 options.recv_audio = false;
2637 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002638
2639 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002640 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002641 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002642
2643 // TODO(perkj): Should the direction be set to SEND_ONLY?
2644 const cricket::ContentInfo* content =
2645 cricket::GetFirstAudioContent(answer->description());
2646 ASSERT_TRUE(content != NULL);
2647 EXPECT_FALSE(content->rejected);
2648
2649 // TODO(perkj): Should the direction be set to SEND_ONLY?
2650 content = cricket::GetFirstVideoContent(answer->description());
2651 ASSERT_TRUE(content != NULL);
2652 EXPECT_FALSE(content->rejected);
2653}
2654
2655TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2656 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002657 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002658 PeerConnectionInterface::RTCOfferAnswerOptions options;
2659 options.offer_to_receive_audio =
2660 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2661 options.voice_activity_detection = false;
2662
kwibergd1fe2812016-04-27 06:47:29 -07002663 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002664
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002665 const cricket::ContentInfo* content =
2666 cricket::GetFirstAudioContent(offer->description());
2667 EXPECT_TRUE(content != NULL);
2668 EXPECT_TRUE(VerifyNoCNCodecs(content));
2669}
2670
2671TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2672 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002673 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002674 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002675 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002676 SetRemoteDescriptionWithoutError(offer.release());
2677
htaa2a49d92016-03-04 02:51:39 -08002678 cricket::MediaSessionOptions options;
2679 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002680 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002681 const cricket::ContentInfo* content =
2682 cricket::GetFirstAudioContent(answer->description());
2683 ASSERT_TRUE(content != NULL);
2684 EXPECT_TRUE(VerifyNoCNCodecs(content));
2685}
2686
2687// This test verifies the call setup when remote answer with audio only and
2688// later updates with video.
2689TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002690 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002691 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2692 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2693
deadbeefab9b2d12015-10-14 11:33:11 -07002694 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002695 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002696
2697 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002698 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2699
2700 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2701 // and answer;
2702 SetLocalDescriptionWithoutError(offer);
2703 SetRemoteDescriptionWithoutError(answer);
2704
2705 video_channel_ = media_engine_->GetVideoChannel(0);
2706 voice_channel_ = media_engine_->GetVoiceChannel(0);
2707
2708 ASSERT_TRUE(video_channel_ == NULL);
2709
2710 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2711 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2712 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2713
2714 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002715 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002716 CreateAndSetRemoteOfferAndLocalAnswer();
2717
2718 video_channel_ = media_engine_->GetVideoChannel(0);
2719 voice_channel_ = media_engine_->GetVoiceChannel(0);
2720
2721 ASSERT_TRUE(video_channel_ != NULL);
2722 ASSERT_TRUE(voice_channel_ != NULL);
2723
2724 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2725 ASSERT_EQ(1u, video_channel_->send_streams().size());
2726 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2727 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2728 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2729 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2730 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2731 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2732
2733 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002734 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002735 CreateAndSetRemoteOfferAndLocalAnswer();
2736
2737 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2738 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2739 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2740 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2741 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2742}
2743
2744// This test verifies the call setup when remote answer with video only and
2745// later updates with audio.
2746TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002747 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002748 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2749 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002750 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002751 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002752
2753 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002754 options.recv_audio = false;
2755 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002756 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2757 offer, options, cricket::SEC_ENABLED);
2758
2759 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2760 // and answer.
2761 SetLocalDescriptionWithoutError(offer);
2762 SetRemoteDescriptionWithoutError(answer);
2763
2764 video_channel_ = media_engine_->GetVideoChannel(0);
2765 voice_channel_ = media_engine_->GetVoiceChannel(0);
2766
2767 ASSERT_TRUE(voice_channel_ == NULL);
2768 ASSERT_TRUE(video_channel_ != NULL);
2769
2770 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2771 ASSERT_EQ(1u, video_channel_->send_streams().size());
2772 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2773
2774 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002775 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002776 CreateAndSetRemoteOfferAndLocalAnswer();
2777
2778 voice_channel_ = media_engine_->GetVoiceChannel(0);
2779 ASSERT_TRUE(voice_channel_ != NULL);
2780
2781 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2782 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2783 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2784 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2785
2786 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002787 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002788 CreateAndSetRemoteOfferAndLocalAnswer();
2789
2790 video_channel_ = media_engine_->GetVideoChannel(0);
2791 voice_channel_ = media_engine_->GetVoiceChannel(0);
2792
2793 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2794 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2795 ASSERT_EQ(1u, video_channel_->send_streams().size());
2796 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2797}
2798
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002799TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002800 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002801 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002802 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002803 VerifyCryptoParams(offer->description());
2804 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002805 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002806 VerifyCryptoParams(answer->description());
2807}
2808
2809TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002810 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002811 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002812 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002813 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002814 VerifyNoCryptoParams(offer->description(), false);
2815}
2816
2817TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002818 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002819 VerifyAnswerFromNonCryptoOffer();
2820}
2821
2822TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002823 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002824 VerifyAnswerFromCryptoOffer();
2825}
2826
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002827// This test verifies that setLocalDescription fails if
2828// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2829TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002830 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002831 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002832 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002833
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002834 std::string sdp;
2835 RemoveIceUfragPwdLines(offer.get(), &sdp);
2836 SessionDescriptionInterface* modified_offer =
2837 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002838 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002839}
2840
2841// This test verifies that setRemoteDescription fails if
2842// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2843TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002844 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002845 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002846 std::string sdp;
2847 RemoveIceUfragPwdLines(offer.get(), &sdp);
2848 SessionDescriptionInterface* modified_offer =
2849 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002850 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002851}
2852
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002853// This test verifies that setLocalDescription fails if local offer has
2854// too short ice ufrag and pwd strings.
2855TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002856 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002857 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002858 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002859 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2860 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002861 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002862 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002863 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002864
2865 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002866 offer.reset(CreateOffer());
2867 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2868 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002869}
2870
2871// This test verifies that setRemoteDescription fails if remote offer has
2872// too short ice ufrag and pwd strings.
2873TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002874 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002875 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002876 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2877 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002878 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002879 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002880 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002881
deadbeef0ed85b22016-02-23 17:24:52 -08002882 offer.reset(CreateRemoteOffer());
2883 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2884 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002885}
2886
Honghai Zhang04e91462015-12-11 14:26:22 -08002887// Test that if the remote offer indicates the peer requested ICE restart (via
2888// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2889TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002890 Init();
honghaiz503726c2015-07-31 12:37:38 -07002891
2892 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002893 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002894 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002895 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2896 0, "", "", "relay", 0, "");
2897 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2898 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002899 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2900 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002901 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2902
2903 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002904 offer.reset(CreateRemoteOffer());
2905 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002906 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2907 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2908 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002909 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2910 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002911 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2912
2913 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002914 offer.reset(CreateRemoteOffer());
2915 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002916 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2917 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2918 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002919 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2920 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002921 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2922
2923 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002924 offer.reset(CreateRemoteOffer());
2925 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2926 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002927 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2928}
2929
Honghai Zhang04e91462015-12-11 14:26:22 -08002930// Test that if the remote answer indicates the peer requested ICE restart (via
2931// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2932TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2933 Init();
2934 SessionDescriptionInterface* offer = CreateOffer();
2935 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002936
2937 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002938 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002939 answer->set_type(JsepSessionDescription::kPrAnswer);
2940 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002941 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2942 0, "", "", "relay", 0, "");
2943 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2944 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002945 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2946 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002947 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2948
2949 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002950 answer.reset(CreateRemoteAnswer(offer));
2951 answer->set_type(JsepSessionDescription::kPrAnswer);
2952 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002953 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2954 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2955 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002956 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2957 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002958 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2959
2960 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002961 answer.reset(CreateRemoteAnswer(offer));
2962 answer->set_type(JsepSessionDescription::kPrAnswer);
2963 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002964 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2965 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2966 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002967 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2968 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002969 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2970
2971 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002972 answer.reset(CreateRemoteAnswer(offer));
2973 answer->set_type(JsepSessionDescription::kPrAnswer);
2974 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2975 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002976 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2977}
2978
Donald Curtisd4f769d2015-05-28 09:48:21 -07002979// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002980// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002981TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2982 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2983
2984 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002985 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002986
2987 PeerConnectionInterface::RTCOfferAnswerOptions options;
2988 options.use_rtp_mux = true;
2989
2990 SessionDescriptionInterface* offer = CreateRemoteOffer();
2991 SetRemoteDescriptionWithoutError(offer);
2992
htaa2a49d92016-03-04 02:51:39 -08002993 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002994 SetLocalDescriptionWithoutError(answer);
2995
deadbeefcbecd352015-09-23 11:50:27 -07002996 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2997 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002998
deadbeefcbecd352015-09-23 11:50:27 -07002999 cricket::BaseChannel* voice_channel = session_->voice_channel();
3000 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003001
3002 // Checks if one of the transport channels contains a connection using a given
3003 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003004 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07003005 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07003006 session_->GetChannelTransportStats(voice_channel, &stats);
3007 for (auto& kv : stats.transport_stats) {
3008 for (auto& chan_stat : kv.second.channel_stats) {
3009 for (auto& conn_info : chan_stat.connection_infos) {
3010 if (conn_info.remote_candidate.address().port() == port) {
3011 return true;
3012 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003013 }
3014 }
3015 }
3016 return false;
3017 };
3018
3019 EXPECT_FALSE(connection_with_remote_port(5000));
3020 EXPECT_FALSE(connection_with_remote_port(5001));
3021 EXPECT_FALSE(connection_with_remote_port(6000));
3022
3023 // The way the *_WAIT checks work is they only wait if the condition fails,
3024 // which does not help in the case where state is not changing. This is
3025 // problematic in this test since we want to verify that adding a video
3026 // candidate does _not_ change state. So we interleave candidates and assume
3027 // that messages are executed in the order they were posted.
3028
3029 // First audio candidate.
3030 cricket::Candidate candidate0;
3031 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3032 candidate0.set_component(1);
3033 candidate0.set_protocol("udp");
3034 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3035 candidate0);
3036 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3037
3038 // Video candidate.
3039 cricket::Candidate candidate1;
3040 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3041 candidate1.set_component(1);
3042 candidate1.set_protocol("udp");
3043 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3044 candidate1);
3045 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3046
3047 // Second audio candidate.
3048 cricket::Candidate candidate2;
3049 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3050 candidate2.set_component(1);
3051 candidate2.set_protocol("udp");
3052 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3053 candidate2);
3054 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3055
3056 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3057 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3058
3059 // No need here for a _WAIT check since we are checking that state hasn't
3060 // changed: if this is false we would be doing waits for nothing and if this
3061 // is true then there will be no messages processed anyways.
3062 EXPECT_FALSE(connection_with_remote_port(6000));
3063}
3064
deadbeefcbecd352015-09-23 11:50:27 -07003065// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003066TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3067 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003068 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003069
3070 PeerConnectionInterface::RTCOfferAnswerOptions options;
3071 options.use_rtp_mux = true;
3072
3073 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003074 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003075
deadbeefcbecd352015-09-23 11:50:27 -07003076 EXPECT_NE(session_->voice_rtp_transport_channel(),
3077 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003078
deadbeefab9b2d12015-10-14 11:33:11 -07003079 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003080 SessionDescriptionInterface* answer =
3081 CreateRemoteAnswer(session_->local_description());
3082 SetRemoteDescriptionWithoutError(answer);
3083
deadbeefcbecd352015-09-23 11:50:27 -07003084 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3085 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003086}
3087
deadbeefcbecd352015-09-23 11:50:27 -07003088// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003089TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3090 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003091 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003092
Donald Curtis0e209b02015-03-24 09:29:54 -07003093 PeerConnectionInterface::RTCOfferAnswerOptions options;
3094 options.use_rtp_mux = true;
3095
3096 SessionDescriptionInterface* offer = CreateOffer(options);
3097 SetLocalDescriptionWithoutError(offer);
3098
deadbeefcbecd352015-09-23 11:50:27 -07003099 EXPECT_NE(session_->voice_rtp_transport_channel(),
3100 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003101
deadbeefab9b2d12015-10-14 11:33:11 -07003102 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003103
3104 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003105 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003106 CreateRemoteAnswer(session_->local_description()));
3107 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3108 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3109 JsepSessionDescription* modified_answer =
3110 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3111 modified_answer->Initialize(answer_copy, "1", "1");
3112 SetRemoteDescriptionWithoutError(modified_answer); //
3113
deadbeefcbecd352015-09-23 11:50:27 -07003114 EXPECT_NE(session_->voice_rtp_transport_channel(),
3115 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003116}
3117
3118// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3119TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3120 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003121 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003122
3123 PeerConnectionInterface::RTCOfferAnswerOptions options;
3124 options.use_rtp_mux = true;
3125
3126 SessionDescriptionInterface* offer = CreateOffer(options);
3127 SetLocalDescriptionWithoutError(offer);
3128
deadbeefcbecd352015-09-23 11:50:27 -07003129 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3130 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003131
deadbeefab9b2d12015-10-14 11:33:11 -07003132 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003133 SessionDescriptionInterface* answer =
3134 CreateRemoteAnswer(session_->local_description());
3135 SetRemoteDescriptionWithoutError(answer);
3136
deadbeefcbecd352015-09-23 11:50:27 -07003137 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3138 session_->video_rtp_transport_channel());
3139}
3140
3141// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3142// audio content in the answer.
3143TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3144 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003145 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003146
3147 PeerConnectionInterface::RTCOfferAnswerOptions options;
3148 options.use_rtp_mux = true;
3149
3150 SessionDescriptionInterface* offer = CreateOffer(options);
3151 SetLocalDescriptionWithoutError(offer);
3152
3153 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3154 session_->video_rtp_transport_channel());
3155
deadbeefab9b2d12015-10-14 11:33:11 -07003156 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003157 cricket::MediaSessionOptions recv_options;
3158 recv_options.recv_audio = false;
3159 recv_options.recv_video = true;
3160 SessionDescriptionInterface* answer =
3161 CreateRemoteAnswer(session_->local_description(), recv_options);
3162 SetRemoteDescriptionWithoutError(answer);
3163
deadbeefd59daf82015-10-14 15:02:44 -07003164 EXPECT_TRUE(nullptr == session_->voice_channel());
3165 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003166
deadbeefd59daf82015-10-14 15:02:44 -07003167 session_->Close();
3168 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3169 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3170 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3171 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003172}
3173
3174// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3175TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3176 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003177 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003178
Donald Curtis0e209b02015-03-24 09:29:54 -07003179 PeerConnectionInterface::RTCOfferAnswerOptions options;
3180 options.use_rtp_mux = true;
3181
3182 SessionDescriptionInterface* offer = CreateOffer(options);
3183 SetLocalDescriptionWithoutError(offer);
3184
deadbeefcbecd352015-09-23 11:50:27 -07003185 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3186 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003187
deadbeefab9b2d12015-10-14 11:33:11 -07003188 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003189
3190 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003191 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003192 CreateRemoteAnswer(session_->local_description()));
3193 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3194 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3195 JsepSessionDescription* modified_answer =
3196 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3197 modified_answer->Initialize(answer_copy, "1", "1");
3198 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003199
deadbeefcbecd352015-09-23 11:50:27 -07003200 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3201 session_->video_rtp_transport_channel());
3202}
3203
3204// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3205TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3206 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003207 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003208
3209 SessionDescriptionInterface* offer = CreateRemoteOffer();
3210 SetRemoteDescriptionWithoutError(offer);
3211
3212 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3213 session_->video_rtp_transport_channel());
3214
deadbeefab9b2d12015-10-14 11:33:11 -07003215 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003216 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003217 SetLocalDescriptionWithoutError(answer);
3218
3219 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3220 session_->video_rtp_transport_channel());
3221}
3222
3223// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3224TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3225 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003226 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003227
3228 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003229 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003230 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3231 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3232 JsepSessionDescription* modified_offer =
3233 new JsepSessionDescription(JsepSessionDescription::kOffer);
3234 modified_offer->Initialize(offer_copy, "1", "1");
3235
3236 // Expect an error when applying the remote description
3237 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3238 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003239}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003240
Peter Thatcher4eddf182015-04-30 10:55:59 -07003241// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003242TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3243 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003244 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003245
Donald Curtis0e209b02015-03-24 09:29:54 -07003246 PeerConnectionInterface::RTCOfferAnswerOptions options;
3247 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003248
Donald Curtis0e209b02015-03-24 09:29:54 -07003249 SessionDescriptionInterface* offer = CreateOffer(options);
3250 SetLocalDescriptionWithoutError(offer);
3251
deadbeefcbecd352015-09-23 11:50:27 -07003252 EXPECT_NE(session_->voice_rtp_transport_channel(),
3253 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003254
deadbeefab9b2d12015-10-14 11:33:11 -07003255 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003256 SessionDescriptionInterface* answer =
3257 CreateRemoteAnswer(session_->local_description());
3258 SetRemoteDescriptionWithoutError(answer);
3259
3260 // This should lead to an audio-only call but isn't implemented
3261 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003262 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3263 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003264}
3265
deadbeefcbecd352015-09-23 11:50:27 -07003266// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003267TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3268 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003269 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003270 PeerConnectionInterface::RTCOfferAnswerOptions options;
3271 options.use_rtp_mux = true;
3272
3273 SessionDescriptionInterface* offer = CreateOffer(options);
3274 SetLocalDescriptionWithoutError(offer);
3275
deadbeefcbecd352015-09-23 11:50:27 -07003276 EXPECT_NE(session_->voice_rtp_transport_channel(),
3277 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003278
deadbeefab9b2d12015-10-14 11:33:11 -07003279 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003280
3281 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003282 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003283 CreateRemoteAnswer(session_->local_description()));
3284 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3285 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3286 JsepSessionDescription* modified_answer =
3287 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3288 modified_answer->Initialize(answer_copy, "1", "1");
3289 SetRemoteDescriptionWithoutError(modified_answer); //
3290
deadbeefcbecd352015-09-23 11:50:27 -07003291 EXPECT_NE(session_->voice_rtp_transport_channel(),
3292 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003293}
3294
Peter Thatcher4eddf182015-04-30 10:55:59 -07003295// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3296TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3297 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003298 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003299
3300 PeerConnectionInterface::RTCOfferAnswerOptions options;
3301 options.use_rtp_mux = true;
3302
3303 SessionDescriptionInterface* offer = CreateOffer(options);
3304 SetRemoteDescriptionWithoutError(offer);
3305
deadbeefcbecd352015-09-23 11:50:27 -07003306 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3307 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003308}
3309
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003310TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3311 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003312 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003313
3314 PeerConnectionInterface::RTCOfferAnswerOptions options;
3315 SessionDescriptionInterface* offer = CreateOffer(options);
3316 SetLocalDescriptionWithoutError(offer);
3317
deadbeefcbecd352015-09-23 11:50:27 -07003318 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3319 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003320
deadbeefab9b2d12015-10-14 11:33:11 -07003321 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003322 SessionDescriptionInterface* answer =
3323 CreateRemoteAnswer(session_->local_description());
3324 SetRemoteDescriptionWithoutError(answer);
3325
deadbeefcbecd352015-09-23 11:50:27 -07003326 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3327 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003328}
3329
3330TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3331 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003332 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003333
3334 PeerConnectionInterface::RTCOfferAnswerOptions options;
3335 SessionDescriptionInterface* offer = CreateOffer(options);
3336 SetLocalDescriptionWithoutError(offer);
3337
deadbeefcbecd352015-09-23 11:50:27 -07003338 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3339 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003340
deadbeefab9b2d12015-10-14 11:33:11 -07003341 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003342 SessionDescriptionInterface* answer =
3343 CreateRemoteAnswer(session_->local_description());
3344 SetRemoteDescriptionWithoutError(answer);
3345
deadbeefcbecd352015-09-23 11:50:27 -07003346 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3347 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003348}
3349
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003350// This test verifies that SetLocalDescription and SetRemoteDescription fails
3351// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3352TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003353 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003354 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003355
3356 PeerConnectionInterface::RTCOfferAnswerOptions options;
3357 options.use_rtp_mux = true;
3358
3359 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003360 std::string offer_str;
3361 offer->ToString(&offer_str);
3362 // Disable rtcp-mux
3363 const std::string rtcp_mux = "rtcp-mux";
3364 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003365 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003366 xrtcp_mux.c_str(), xrtcp_mux.length(),
3367 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003368 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003369 new JsepSessionDescription(JsepSessionDescription::kOffer);
3370 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003371 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003372 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003373 new JsepSessionDescription(JsepSessionDescription::kOffer);
3374 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003375 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003376 // Trying unmodified SDP.
3377 SetLocalDescriptionWithoutError(offer);
3378}
3379
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003380TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003381 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003382 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003383 CreateAndSetRemoteOfferAndLocalAnswer();
3384 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3385 ASSERT_TRUE(channel != NULL);
3386 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003387 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003388 double volume;
3389 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3390 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003391 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003392 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3393 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003394 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003395 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3396 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003397}
3398
skvlade0d46372016-04-07 22:59:22 -07003399TEST_F(WebRtcSessionTest, SetAudioMaxSendBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003400 Init();
3401 SendAudioVideoStream1();
3402 CreateAndSetRemoteOfferAndLocalAnswer();
3403 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3404 ASSERT_TRUE(channel != NULL);
3405 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
skvlade0d46372016-04-07 22:59:22 -07003406 EXPECT_EQ(-1, channel->max_bps());
skvladdc1c62c2016-03-16 19:07:43 -07003407 webrtc::RtpParameters params = session_->GetAudioRtpParameters(send_ssrc);
skvlade0d46372016-04-07 22:59:22 -07003408 EXPECT_EQ(1, params.encodings.size());
3409 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3410 params.encodings[0].max_bitrate_bps = 1000;
3411 EXPECT_TRUE(session_->SetAudioRtpParameters(send_ssrc, params));
skvladdc1c62c2016-03-16 19:07:43 -07003412
skvlade0d46372016-04-07 22:59:22 -07003413 // Read back the parameters and verify they have been changed.
3414 params = session_->GetAudioRtpParameters(send_ssrc);
3415 EXPECT_EQ(1, params.encodings.size());
3416 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3417
3418 // Verify that the audio channel received the new parameters.
3419 params = channel->GetRtpParameters(send_ssrc);
3420 EXPECT_EQ(1, params.encodings.size());
3421 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3422
3423 // Verify that the global bitrate limit has not been changed.
3424 EXPECT_EQ(-1, channel->max_bps());
skvladdc1c62c2016-03-16 19:07:43 -07003425}
3426
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003427TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003428 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003429 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003430 CreateAndSetRemoteOfferAndLocalAnswer();
3431 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3432 ASSERT_TRUE(channel != NULL);
3433 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003434 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003435 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3436
3437 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003438 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003439
kwibergd1fe2812016-04-27 06:47:29 -07003440 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003441 session_->SetAudioSend(send_ssrc, false, options, source.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003442 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003443 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003444 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003445
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003446 // This will trigger SetSink(nullptr) to the |source|.
3447 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003448 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003449 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003450 EXPECT_TRUE(source->sink() == nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003451}
3452
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003453TEST_F(WebRtcSessionTest, AudioSourceForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003454 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003455 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003456 CreateAndSetRemoteOfferAndLocalAnswer();
3457 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3458 ASSERT_TRUE(channel != NULL);
3459 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003460 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003461
kwibergd1fe2812016-04-27 06:47:29 -07003462 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003463 cricket::AudioOptions options;
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003464 session_->SetAudioSend(send_ssrc, true, options, source.get());
3465 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003466
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003467 // Delete the |source| and it will trigger OnClose() to the sink, and this
3468 // will invalidate the |source_| pointer in the sink and prevent getting a
3469 // SetSink(nullptr) callback afterwards.
3470 source.reset();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003471
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003472 // This will trigger SetSink(nullptr) if no OnClose() callback.
3473 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003474}
3475
3476TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003477 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003478 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003479 CreateAndSetRemoteOfferAndLocalAnswer();
3480 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3481 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003482 ASSERT_LT(0u, channel->sinks().size());
3483 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003484 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003485 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003486 cricket::FakeVideoRenderer renderer;
3487 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003488 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003489 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003490 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003491}
3492
skvladdc1c62c2016-03-16 19:07:43 -07003493TEST_F(WebRtcSessionTest, SetVideoMaxSendBitrate) {
3494 Init();
3495 SendAudioVideoStream1();
3496 CreateAndSetRemoteOfferAndLocalAnswer();
3497 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3498 ASSERT_TRUE(channel != NULL);
3499 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
3500 EXPECT_EQ(-1, channel->max_bps());
3501 webrtc::RtpParameters params = session_->GetVideoRtpParameters(send_ssrc);
3502 EXPECT_EQ(1, params.encodings.size());
3503 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3504 params.encodings[0].max_bitrate_bps = 1000;
3505 EXPECT_TRUE(session_->SetVideoRtpParameters(send_ssrc, params));
3506
3507 // Read back the parameters and verify they have been changed.
3508 params = session_->GetVideoRtpParameters(send_ssrc);
3509 EXPECT_EQ(1, params.encodings.size());
3510 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3511
3512 // Verify that the video channel received the new parameters.
3513 params = channel->GetRtpParameters(send_ssrc);
3514 EXPECT_EQ(1, params.encodings.size());
3515 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3516
3517 // Verify that the global bitrate limit has not been changed.
3518 EXPECT_EQ(-1, channel->max_bps());
3519}
3520
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003521TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003522 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003523 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003524 CreateAndSetRemoteOfferAndLocalAnswer();
3525 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3526 ASSERT_TRUE(channel != NULL);
3527 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003528 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003529 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3530 cricket::VideoOptions* options = NULL;
3531 session_->SetVideoSend(send_ssrc, false, options);
3532 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3533 session_->SetVideoSend(send_ssrc, true, options);
3534 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3535}
3536
3537TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3538 TestCanInsertDtmf(false);
3539}
3540
3541TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3542 TestCanInsertDtmf(true);
3543}
3544
3545TEST_F(WebRtcSessionTest, InsertDtmf) {
3546 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003547 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003548 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003549 CreateAndSetRemoteOfferAndLocalAnswer();
3550 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3551 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3552
3553 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003554 const int expected_duration = 90;
3555 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3556 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3557 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3558
3559 // Verify
3560 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003561 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003562 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003563 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003564 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003565 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003566 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003567 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003568}
3569
deadbeefd59daf82015-10-14 15:02:44 -07003570// This test verifies the |initial_offerer| flag when session initiates the
3571// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003572TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003573 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003574 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003575 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003576 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3577 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003578 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003579 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003580 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003581}
3582
deadbeefd59daf82015-10-14 15:02:44 -07003583// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003584TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003585 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003586 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003587 SessionDescriptionInterface* offer = CreateRemoteOffer();
3588 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003589 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003590
deadbeefd59daf82015-10-14 15:02:44 -07003591 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003592 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003593 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003594}
3595
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003596// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3597TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003598 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003599 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003600 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003601 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003602 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003603 CreateRemoteAnswer(session_->local_description()));
3604
3605 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3606 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003607 JsepSessionDescription* modified_answer =
3608 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003609
3610 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3611 answer->session_id(),
3612 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003613 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003614
wu@webrtc.org4e393072014-04-07 17:04:35 +00003615 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003616 std::string sdp;
3617 EXPECT_TRUE(answer->ToString(&sdp));
3618 const std::string kAudioMid = "a=mid:audio";
3619 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003620 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003621 kAudioMidReplaceStr.c_str(),
3622 kAudioMidReplaceStr.length(),
3623 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003624 SessionDescriptionInterface* modified_answer1 =
3625 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003626 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003627
wu@webrtc.org4e393072014-04-07 17:04:35 +00003628 // Different media types.
3629 EXPECT_TRUE(answer->ToString(&sdp));
3630 const std::string kAudioMline = "m=audio";
3631 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003632 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003633 kAudioMlineReplaceStr.c_str(),
3634 kAudioMlineReplaceStr.length(),
3635 &sdp);
3636 SessionDescriptionInterface* modified_answer2 =
3637 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3638 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3639
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003640 SetRemoteDescriptionWithoutError(answer.release());
3641}
3642
3643// Verifying remote offer and local answer have matching m-lines as per
3644// RFC 3264.
3645TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003646 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003647 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003648 SessionDescriptionInterface* offer = CreateRemoteOffer();
3649 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003650 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003651
3652 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3653 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003654 JsepSessionDescription* modified_answer =
3655 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003656
3657 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3658 answer->session_id(),
3659 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003660 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003661 SetLocalDescriptionWithoutError(answer);
3662}
3663
3664// This test verifies that WebRtcSession does not start candidate allocation
3665// before SetLocalDescription is called.
3666TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003667 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003668 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003669 SessionDescriptionInterface* offer = CreateRemoteOffer();
3670 cricket::Candidate candidate;
3671 candidate.set_component(1);
3672 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3673 candidate);
3674 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3675 cricket::Candidate candidate1;
3676 candidate1.set_component(1);
3677 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3678 candidate1);
3679 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3680 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003681 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3682 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003683
3684 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003685 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003686 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3687 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3688
htaa2a49d92016-03-04 02:51:39 -08003689 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003690 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003691 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3692}
3693
3694// This test verifies that crypto parameter is updated in local session
3695// description as per security policy set in MediaSessionDescriptionFactory.
3696TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003697 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003698 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003699 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003700
3701 // Making sure SetLocalDescription correctly sets crypto value in
3702 // SessionDescription object after de-serialization of sdp string. The value
3703 // will be set as per MediaSessionDescriptionFactory.
3704 std::string offer_str;
3705 offer->ToString(&offer_str);
3706 SessionDescriptionInterface* jsep_offer_str =
3707 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3708 SetLocalDescriptionWithoutError(jsep_offer_str);
3709 EXPECT_TRUE(session_->voice_channel()->secure_required());
3710 EXPECT_TRUE(session_->video_channel()->secure_required());
3711}
3712
3713// This test verifies the crypto parameter when security is disabled.
3714TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003715 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003716 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003717 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003718 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003719
3720 // Making sure SetLocalDescription correctly sets crypto value in
3721 // SessionDescription object after de-serialization of sdp string. The value
3722 // will be set as per MediaSessionDescriptionFactory.
3723 std::string offer_str;
3724 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003725 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003726 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3727 SetLocalDescriptionWithoutError(jsep_offer_str);
3728 EXPECT_FALSE(session_->voice_channel()->secure_required());
3729 EXPECT_FALSE(session_->video_channel()->secure_required());
3730}
3731
3732// This test verifies that an answer contains new ufrag and password if an offer
3733// with new ufrag and password is received.
3734TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003735 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003736 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003737 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003738 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003739 SetRemoteDescriptionWithoutError(offer.release());
3740
deadbeefab9b2d12015-10-14 11:33:11 -07003741 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003742 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003743 SetLocalDescriptionWithoutError(answer.release());
3744
3745 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003746 for (const cricket::ContentInfo& content :
3747 session_->local_description()->description()->contents()) {
3748 options.transport_options[content.name].ice_restart = true;
3749 }
kwibergd1fe2812016-04-27 06:47:29 -07003750 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003751 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003752 SetRemoteDescriptionWithoutError(updated_offer1.release());
3753
kwibergd1fe2812016-04-27 06:47:29 -07003754 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003755
deadbeef0ed85b22016-02-23 17:24:52 -08003756 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3757 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003758
deadbeef0ed85b22016-02-23 17:24:52 -08003759 // Even a second answer (created before the description is set) should have
3760 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003761 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003762
3763 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3764 session_->local_description()->description()));
3765
3766 SetLocalDescriptionWithoutError(updated_answer2.release());
3767}
3768
3769// This test verifies that an answer contains new ufrag and password if an offer
3770// that changes either the ufrag or password (but not both) is received.
3771// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3772// a=ice-pwd attributes compared to the previous SDP from the peer, it
3773// indicates that ICE is restarting for this media stream."
3774TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3775 Init();
3776 cricket::MediaSessionOptions options;
3777 options.recv_audio = true;
3778 options.recv_video = true;
3779 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003780 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003781 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3782 SetRemoteDescriptionWithoutError(offer.release());
3783
3784 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003785 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003786 SetLocalDescriptionWithoutError(answer.release());
3787
3788 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003789 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003790 CreateRemoteOffer(options, session_->remote_description()));
3791 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3792 "original_password12345");
3793 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3794
kwibergd1fe2812016-04-27 06:47:29 -07003795 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003796 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3797 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003798 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003799
3800 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003801 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003802 CreateRemoteOffer(options, session_->remote_description()));
3803 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3804 "modified_password12345");
3805 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3806
kwibergd1fe2812016-04-27 06:47:29 -07003807 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003808 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3809 session_->local_description()->description()));
3810 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003811}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003812
wu@webrtc.org91053e72013-08-10 07:18:04 +00003813// This test verifies that an answer contains old ufrag and password if an offer
3814// with old ufrag and password is received.
3815TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003816 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003817 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003818 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003819 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003820 SetRemoteDescriptionWithoutError(offer.release());
3821
deadbeefab9b2d12015-10-14 11:33:11 -07003822 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003823 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003824 SetLocalDescriptionWithoutError(answer.release());
3825
3826 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003827 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003828 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003829 SetRemoteDescriptionWithoutError(updated_offer2.release());
3830
kwibergd1fe2812016-04-27 06:47:29 -07003831 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003832
deadbeef0ed85b22016-02-23 17:24:52 -08003833 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3834 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003835
3836 SetLocalDescriptionWithoutError(updated_answer2.release());
3837}
3838
deadbeef0ed85b22016-02-23 17:24:52 -08003839// This test verifies that if an offer does an ICE restart on some, but not all
3840// media sections, the answer will change the ufrag/password in the correct
3841// media sections.
3842TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3843 Init();
3844 cricket::MediaSessionOptions options;
3845 options.recv_video = true;
3846 options.recv_audio = true;
3847 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003848 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003849
3850 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3851 "aaaaaaaaaaaaaaaaaaaaaa");
3852 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3853 "bbbbbbbbbbbbbbbbbbbbbb");
3854 SetRemoteDescriptionWithoutError(offer.release());
3855
3856 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003857 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003858 SetLocalDescriptionWithoutError(answer.release());
3859
3860 // Receive an offer with new ufrag and password, but only for the video media
3861 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003862 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003863 CreateRemoteOffer(options, session_->remote_description()));
3864 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3865 "cccccccccccccccccccccc");
3866 SetRemoteDescriptionWithoutError(updated_offer.release());
3867
kwibergd1fe2812016-04-27 06:47:29 -07003868 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003869
3870 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3871 session_->local_description()->description(),
3872 cricket::MEDIA_TYPE_AUDIO));
3873
3874 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3875 session_->local_description()->description(),
3876 cricket::MEDIA_TYPE_VIDEO));
3877
3878 SetLocalDescriptionWithoutError(updated_answer.release());
3879}
3880
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003881TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003882 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003883 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003884 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003885 const std::string session_id_orig = offer->session_id();
3886 const std::string session_version_orig = offer->session_version();
3887 SetLocalDescriptionWithoutError(offer);
3888
3889 video_channel_ = media_engine_->GetVideoChannel(0);
3890 video_channel_->set_fail_set_send_codecs(true);
3891
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003892 SessionDescriptionInterface* answer =
3893 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003894 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003895
3896 // Test that after a content error, setting any description will
3897 // result in an error.
3898 video_channel_->set_fail_set_send_codecs(false);
3899 answer = CreateRemoteAnswer(session_->local_description());
3900 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3901 offer = CreateRemoteOffer();
3902 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003903}
3904
3905// Runs the loopback call test with BUNDLE and STUN disabled.
3906TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3907 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003908 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003909 cricket::PORTALLOCATOR_DISABLE_STUN |
3910 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003911 TestLoopbackCall();
3912}
3913
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003914TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003915 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003916 cricket::PORTALLOCATOR_DISABLE_STUN |
3917 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3918 cricket::PORTALLOCATOR_DISABLE_RELAY);
3919
3920 // best connection is IPv6 since it has higher network preference.
3921 LoopbackNetworkConfiguration config;
3922 config.test_ipv6_network_ = true;
3923 config.best_connection_after_initial_ice_converged_ =
3924 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3925
3926 TestLoopbackCall(config);
3927}
3928
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003929// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003930TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003931 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3932 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003933 TestLoopbackCall();
3934}
3935
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003936TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003937 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003938 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003939 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003940 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003941 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3942}
3943
Henrik Boström87713d02015-08-25 09:53:21 +02003944TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003945 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003946
htaa2a49d92016-03-04 02:51:39 -08003947 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003948 options_.disable_sctp_data_channels = false;
3949
Henrik Boström87713d02015-08-25 09:53:21 +02003950 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003951
3952 SetLocalDescriptionWithDataChannel();
3953 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3954}
3955
Henrik Boström87713d02015-08-25 09:53:21 +02003956TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003957 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003958
Henrik Boström87713d02015-08-25 09:53:21 +02003959 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003960
kwibergd1fe2812016-04-27 06:47:29 -07003961 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003962 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003963 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3964}
3965
Henrik Boström87713d02015-08-25 09:53:21 +02003966TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003967 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003968 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003969 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003970
3971 // Create remote offer with SCTP.
3972 cricket::MediaSessionOptions options;
3973 options.data_channel_type = cricket::DCT_SCTP;
3974 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003975 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003976 SetRemoteDescriptionWithoutError(offer);
3977
3978 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003979 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003980 EXPECT_TRUE(answer != NULL);
3981 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3982 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003983}
3984
Henrik Boström87713d02015-08-25 09:53:21 +02003985TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003986 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003987 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003988
3989 SetLocalDescriptionWithDataChannel();
3990 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3991}
3992
Henrik Boström87713d02015-08-25 09:53:21 +02003993TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003994 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003995
Henrik Boström87713d02015-08-25 09:53:21 +02003996 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003997
3998 SetLocalDescriptionWithDataChannel();
3999 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4000}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004001
Henrik Boström87713d02015-08-25 09:53:21 +02004002TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004003 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00004004 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02004005 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004006
4007 SetLocalDescriptionWithDataChannel();
4008 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
4009}
4010
Henrik Boström87713d02015-08-25 09:53:21 +02004011TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004012 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004013 const int new_send_port = 9998;
4014 const int new_recv_port = 7775;
4015
Henrik Boström87713d02015-08-25 09:53:21 +02004016 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004017 SetFactoryDtlsSrtp();
4018
4019 // By default, don't actually add the codecs to desc_factory_; they don't
4020 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
4021 // let the session description get parsed. That'll get the proper codecs
4022 // into the stream.
4023 cricket::MediaSessionOptions options;
4024 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
4025 "stream1", new_send_port, options);
4026
4027 // SetRemoteDescription will take the ownership of the offer.
4028 SetRemoteDescriptionWithoutError(offer);
4029
htaa2a49d92016-03-04 02:51:39 -08004030 SessionDescriptionInterface* answer =
4031 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004032 ASSERT_TRUE(answer != NULL);
4033
4034 // Now set the local description, which'll take ownership of the answer.
4035 SetLocalDescriptionWithoutError(answer);
4036
4037 // TEST PLAN: Set the port number to something new, set it in the SDP,
4038 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004039 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07004040 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004041
4042 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
4043 int portnum = -1;
4044 ASSERT_TRUE(ch != NULL);
4045 ASSERT_EQ(1UL, ch->send_codecs().size());
4046 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004047 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004048 ch->send_codecs()[0].name.c_str()));
4049 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
4050 &portnum));
4051 EXPECT_EQ(new_send_port, portnum);
4052
4053 ASSERT_EQ(1UL, ch->recv_codecs().size());
4054 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004055 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004056 ch->recv_codecs()[0].name.c_str()));
4057 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
4058 &portnum));
4059 EXPECT_EQ(new_recv_port, portnum);
4060}
4061
deadbeefab9b2d12015-10-14 11:33:11 -07004062// Verifies that when a session's DataChannel receives an OPEN message,
4063// WebRtcSession signals the DataChannel creation request with the expected
4064// config.
4065TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
4066 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4067
4068 InitWithDtls(GetParam());
4069
4070 SetLocalDescriptionWithDataChannel();
4071 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4072
4073 webrtc::DataChannelInit config;
4074 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004075 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004076 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4077 cricket::ReceiveDataParams params;
4078 params.ssrc = config.id;
4079 params.type = cricket::DMT_CONTROL;
4080
4081 cricket::DataChannel* data_channel = session_->data_channel();
4082 data_channel->SignalDataReceived(data_channel, params, payload);
4083
4084 EXPECT_EQ("a", last_data_channel_label_);
4085 EXPECT_EQ(config.id, last_data_channel_config_.id);
4086 EXPECT_FALSE(last_data_channel_config_.negotiated);
4087 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4088 last_data_channel_config_.open_handshake_role);
4089}
4090
4091TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004092 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
4093 FakeDtlsIdentityStore::GenerateCertificate();
4094
htaa2a49d92016-03-04 02:51:39 -08004095 configuration_.certificates.push_back(certificate);
4096 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004097 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4098
4099 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4100}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004101
Henrik Boström87713d02015-08-25 09:53:21 +02004102// Verifies that CreateOffer succeeds when CreateOffer is called before async
4103// identity generation is finished (even if a certificate is provided this is
4104// an async op).
4105TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4106 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4107 InitWithDtls(GetParam());
4108
Henrik Boströmd8281982015-08-27 10:12:24 +02004109 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004110 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004111 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004112
wu@webrtc.org91053e72013-08-10 07:18:04 +00004113 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004114 VerifyNoCryptoParams(offer->description(), true);
4115 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004116}
4117
4118// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004119// identity generation is finished (even if a certificate is provided this is
4120// an async op).
4121TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004122 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004123 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004124 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004125
4126 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004127 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004128 std::unique_ptr<JsepSessionDescription> offer(
4129 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004130 ASSERT_TRUE(offer.get() != NULL);
4131 SetRemoteDescriptionWithoutError(offer.release());
4132
kwibergd1fe2812016-04-27 06:47:29 -07004133 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004134 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004135 VerifyNoCryptoParams(answer->description(), true);
4136 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004137}
4138
4139// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004140// identity generation is finished (even if a certificate is provided this is
4141// an async op).
4142TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004143 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004144 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004145
Henrik Boströmd8281982015-08-27 10:12:24 +02004146 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004147
kwibergd1fe2812016-04-27 06:47:29 -07004148 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004149 EXPECT_TRUE(offer != NULL);
4150}
4151
4152// Verifies that CreateOffer fails when CreateOffer is called after async
4153// identity generation fails.
4154TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004155 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004156 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004157
Henrik Boströmd8281982015-08-27 10:12:24 +02004158 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004159
kwibergd1fe2812016-04-27 06:47:29 -07004160 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004161 EXPECT_TRUE(offer == NULL);
4162}
4163
4164// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4165// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004166TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004167 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004168 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004169 VerifyMultipleAsyncCreateDescription(GetParam(),
4170 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004171}
4172
4173// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4174// before async identity generation fails.
4175TEST_F(WebRtcSessionTest,
4176 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004177 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004178 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4179 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004180}
4181
4182// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4183// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004184TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004185 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004186 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004187 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004188 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004189}
4190
4191// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4192// before async identity generation fails.
4193TEST_F(WebRtcSessionTest,
4194 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004195 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004196 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4197 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004198}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004199
4200// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4201// offer has no SDES crypto but only DTLS fingerprint.
4202TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4203 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004204 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004205 // Create a remote offer with secured transport disabled.
4206 cricket::MediaSessionOptions options;
4207 JsepSessionDescription* offer(CreateRemoteOffer(
4208 options, cricket::SEC_DISABLED));
4209 // Adds a DTLS fingerprint to the remote offer.
4210 cricket::SessionDescription* sdp = offer->description();
4211 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4212 ASSERT_TRUE(audio != NULL);
4213 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4214 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004215 rtc::SSLFingerprint::CreateFromRfc4572(
4216 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004217 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004218 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004219}
4220
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004221TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004222 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004223 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004224 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004225 SessionDescriptionInterface* offer = CreateOffer();
4226
4227 SetLocalDescriptionWithoutError(offer);
4228
4229 voice_channel_ = media_engine_->GetVoiceChannel(0);
4230
4231 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004232 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004233 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004234}
4235
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004236// Tests that we can renegotiate new media content with ICE candidates in the
4237// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004238TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004239 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004240 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004241 SetFactoryDtlsSrtp();
4242
deadbeefab9b2d12015-10-14 11:33:11 -07004243 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004244 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004245 SetLocalDescriptionWithoutError(offer);
4246
4247 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4248 SetRemoteDescriptionWithoutError(answer);
4249
4250 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004251 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004252 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4253
4254 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004255 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004256 candidate1.set_component(1);
4257 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4258 candidate1);
4259 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4260 SetRemoteDescriptionWithoutError(offer);
4261
htaa2a49d92016-03-04 02:51:39 -08004262 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004263 SetLocalDescriptionWithoutError(answer);
4264}
4265
4266// Tests that we can renegotiate new media content with ICE candidates separated
4267// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004268TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004269 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004270 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004271 SetFactoryDtlsSrtp();
4272
deadbeefab9b2d12015-10-14 11:33:11 -07004273 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004274 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004275 SetLocalDescriptionWithoutError(offer);
4276
4277 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4278 SetRemoteDescriptionWithoutError(answer);
4279
4280 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004281 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004282 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4283 SetRemoteDescriptionWithoutError(offer);
4284
4285 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004286 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004287 candidate1.set_component(1);
4288 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4289 candidate1);
4290 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4291
htaa2a49d92016-03-04 02:51:39 -08004292 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004293 SetLocalDescriptionWithoutError(answer);
4294}
honghaiz7f777492016-02-02 21:54:01 -08004295
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004296// Tests that RTX codec is removed from the answer when it isn't supported
4297// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004298TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004299 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004300 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004301 std::string offer_sdp(kSdpWithRtx);
4302
4303 SessionDescriptionInterface* offer =
4304 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4305 EXPECT_TRUE(offer->ToString(&offer_sdp));
4306
4307 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004308 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004309 SetRemoteDescriptionWithoutError(offer);
4310
htaa2a49d92016-03-04 02:51:39 -08004311 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004312 // Answer SDP does not contain the RTX codec.
4313 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004314 SetLocalDescriptionWithoutError(answer);
4315}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004316
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004317// This verifies that the voice channel after bundle has both options from video
4318// and voice channels.
4319TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4320 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004321 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004322
4323 PeerConnectionInterface::RTCOfferAnswerOptions options;
4324 options.use_rtp_mux = true;
4325
4326 SessionDescriptionInterface* offer = CreateOffer(options);
4327 SetLocalDescriptionWithoutError(offer);
4328
4329 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4330 rtc::Socket::Option::OPT_SNDBUF, 4000);
4331
4332 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4333 rtc::Socket::Option::OPT_RCVBUF, 8000);
4334
4335 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004336 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004337 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4338 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004339 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004340 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4341
deadbeefcbecd352015-09-23 11:50:27 -07004342 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004343 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4344 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004345 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004346 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4347
deadbeefcbecd352015-09-23 11:50:27 -07004348 EXPECT_NE(session_->voice_rtp_transport_channel(),
4349 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004350
deadbeefab9b2d12015-10-14 11:33:11 -07004351 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004352 SessionDescriptionInterface* answer =
4353 CreateRemoteAnswer(session_->local_description());
4354 SetRemoteDescriptionWithoutError(answer);
4355
deadbeefcbecd352015-09-23 11:50:27 -07004356 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004357 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4358 EXPECT_EQ(4000, option_val);
4359
deadbeefcbecd352015-09-23 11:50:27 -07004360 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004361 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4362 EXPECT_EQ(8000, option_val);
4363}
4364
tommi0f620f42015-07-09 03:25:02 -07004365// Test creating a session, request multiple offers, destroy the session
4366// and make sure we got success/failure callbacks for all of the requests.
4367// Background: crbug.com/507307
4368TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4369 Init();
4370
4371 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4372 PeerConnectionInterface::RTCOfferAnswerOptions options;
4373 options.offer_to_receive_audio =
4374 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004375 cricket::MediaSessionOptions session_options;
4376 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004377
4378 for (auto& o : observers) {
4379 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004380 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004381 }
4382
4383 session_.reset();
4384
tommi0f620f42015-07-09 03:25:02 -07004385 for (auto& o : observers) {
4386 // We expect to have received a notification now even if the session was
4387 // terminated. The offer creation may or may not have succeeded, but we
4388 // must have received a notification which, so the only invalid state
4389 // is kInit.
4390 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4391 }
4392}
4393
stefanc1aeaf02015-10-15 07:26:07 -07004394TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4395 TestPacketOptions();
4396}
4397
deadbeef057ecf02016-01-20 14:30:43 -08004398// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4399// is destroyed.
4400TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4401 Init();
4402 session_.reset();
4403 EXPECT_TRUE(session_destroyed_);
4404}
4405
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004406// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4407// currently fails because upon disconnection and reconnection OnIceComplete is
4408// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004409
deadbeefcbecd352015-09-23 11:50:27 -07004410INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4411 WebRtcSessionTest,
4412 testing::Values(ALREADY_GENERATED,
4413 DTLS_IDENTITY_STORE));