blob: 45ffc36c2ee1a8513c3860a484a1b150258f8782 [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
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200161 virtual ~MockIceObserver() = default;
162
perkjdfb769d2016-02-09 03:09:43 -0800163 void OnIceConnectionChange(
164 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 ice_connection_state_ = new_state;
166 }
perkjdfb769d2016-02-09 03:09:43 -0800167 void OnIceGatheringChange(
168 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 // We can never transition back to "new".
170 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
171 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800172 oncandidatesready_ =
173 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174 }
175
176 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800177 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000178 switch (candidate->sdp_mline_index()) {
179 case kMediaContentIndex0:
180 mline_0_candidates_.push_back(candidate->candidate());
181 break;
182 case kMediaContentIndex1:
183 mline_1_candidates_.push_back(candidate->candidate());
184 break;
185 default:
186 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000188
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 // The ICE gathering state should always be Gathering when a candidate is
190 // received (or possibly Completed in the case of the final candidate).
191 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
192 }
193
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700194 // Some local candidates are removed.
195 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700196 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700197 num_candidates_removed_ += candidates.size();
198 }
199
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 bool oncandidatesready_;
201 std::vector<cricket::Candidate> mline_0_candidates_;
202 std::vector<cricket::Candidate> mline_1_candidates_;
203 PeerConnectionInterface::IceConnectionState ice_connection_state_;
204 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700205 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206};
207
208class WebRtcSessionForTest : public webrtc::WebRtcSession {
209 public:
stefanc1aeaf02015-10-15 07:26:07 -0700210 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000211 rtc::Thread* signaling_thread,
212 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700214 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700215 : WebRtcSession(media_controller,
216 signaling_thread,
217 worker_thread,
218 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 RegisterIceObserver(ice_observer);
220 }
221 virtual ~WebRtcSessionForTest() {}
222
deadbeefcbecd352015-09-23 11:50:27 -0700223 // Note that these methods are only safe to use if the signaling thread
224 // is the same as the worker thread
225 cricket::TransportChannel* voice_rtp_transport_channel() {
226 return rtp_transport_channel(voice_channel());
227 }
228
229 cricket::TransportChannel* voice_rtcp_transport_channel() {
230 return rtcp_transport_channel(voice_channel());
231 }
232
233 cricket::TransportChannel* video_rtp_transport_channel() {
234 return rtp_transport_channel(video_channel());
235 }
236
237 cricket::TransportChannel* video_rtcp_transport_channel() {
238 return rtcp_transport_channel(video_channel());
239 }
240
241 cricket::TransportChannel* data_rtp_transport_channel() {
242 return rtp_transport_channel(data_channel());
243 }
244
245 cricket::TransportChannel* data_rtcp_transport_channel() {
246 return rtcp_transport_channel(data_channel());
247 }
248
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 using webrtc::WebRtcSession::SetAudioPlayout;
250 using webrtc::WebRtcSession::SetAudioSend;
nisse2ded9b12016-04-08 02:23:55 -0700251 using webrtc::WebRtcSession::SetSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 using webrtc::WebRtcSession::SetVideoPlayout;
253 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700254
255 private:
256 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
257 if (!ch) {
258 return nullptr;
259 }
260 return ch->transport_channel();
261 }
262
263 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
264 if (!ch) {
265 return nullptr;
266 }
267 return ch->rtcp_transport_channel();
268 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000269};
270
wu@webrtc.org91053e72013-08-10 07:18:04 +0000271class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000272 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000274 enum State {
275 kInit,
276 kFailed,
277 kSucceeded,
278 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000279 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000280
281 // CreateSessionDescriptionObserver implementation.
282 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000283 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000284 state_ = kSucceeded;
285 }
286 virtual void OnFailure(const std::string& error) {
287 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288 }
289
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000290 SessionDescriptionInterface* description() { return description_.get(); }
291
292 SessionDescriptionInterface* ReleaseDescription() {
293 return description_.release();
294 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295
wu@webrtc.org91053e72013-08-10 07:18:04 +0000296 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297
wu@webrtc.org91053e72013-08-10 07:18:04 +0000298 protected:
299 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300
301 private:
kwibergd1fe2812016-04-27 06:47:29 -0700302 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000303 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304};
305
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800306class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000307 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800308 FakeAudioSource() : sink_(NULL) {}
309 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000310 if (sink_)
311 sink_->OnClose();
312 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000313
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000314 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000315
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800316 const cricket::AudioSource::Sink* sink() const { return sink_; }
317
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000318 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800319 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000320};
321
Henrik Boström87713d02015-08-25 09:53:21 +0200322class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700323 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
324 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 protected:
326 // TODO Investigate why ChannelManager crashes, if it's created
327 // after stun_server.
328 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700329 : media_engine_(new cricket::FakeMediaEngine()),
330 data_engine_(new cricket::FakeDataEngine()),
331 channel_manager_(
332 new cricket::ChannelManager(media_engine_,
333 data_engine_,
stefanc1aeaf02015-10-15 07:26:07 -0700334 rtc::Thread::Current())),
335 fake_call_(webrtc::Call::Config()),
336 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800337 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
338 rtc::Thread::Current(),
stefanc1aeaf02015-10-15 07:26:07 -0700339 channel_manager_.get())),
340 tdesc_factory_(new cricket::TransportDescriptionFactory()),
341 desc_factory_(
342 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
343 tdesc_factory_.get())),
344 pss_(new rtc::PhysicalSocketServer),
345 vss_(new rtc::VirtualSocketServer(pss_.get())),
346 fss_(new rtc::FirewallSocketServer(vss_.get())),
347 ss_scope_(fss_.get()),
348 stun_socket_addr_(
349 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
350 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
351 stun_socket_addr_)),
352 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
353 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000354 cricket::ServerAddresses stun_servers;
355 stun_servers.insert(stun_socket_addr_);
356 allocator_.reset(new cricket::BasicPortAllocator(
357 &network_manager_,
358 stun_servers,
359 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000360 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700361 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 EXPECT_TRUE(channel_manager_->Init());
363 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000364 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000365 }
366
367 void AddInterface(const SocketAddress& addr) {
368 network_manager_.AddInterface(addr);
369 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700370 void RemoveInterface(const SocketAddress& addr) {
371 network_manager_.RemoveInterface(addr);
372 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373
Henrik Boström87713d02015-08-25 09:53:21 +0200374 // If |dtls_identity_store| != null or |rtc_configuration| contains
375 // |certificates| then DTLS will be enabled unless explicitly disabled by
376 // |rtc_configuration| options. When DTLS is enabled a certificate will be
377 // used if provided, otherwise one will be generated using the
378 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000379 void Init(
kwibergd1fe2812016-04-27 06:47:29 -0700380 std::unique_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 ASSERT_TRUE(session_.get() == NULL);
382 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700383 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700384 allocator_.get(), &observer_));
385 session_->SignalDataChannelOpenMessage.connect(
386 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800387 session_->GetOnDestroyedSignal()->connect(
388 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000389
390 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
391 observer_.ice_connection_state_);
392 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
393 observer_.ice_gathering_state_);
394
htaa2a49d92016-03-04 02:51:39 -0800395 EXPECT_TRUE(session_->Initialize(options_, std::move(dtls_identity_store),
396 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700397 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398 }
399
deadbeefab9b2d12015-10-14 11:33:11 -0700400 void OnDataChannelOpenMessage(const std::string& label,
401 const InternalDataChannelInit& config) {
402 last_data_channel_label_ = label;
403 last_data_channel_config_ = config;
404 }
405
deadbeef057ecf02016-01-20 14:30:43 -0800406 void OnSessionDestroyed() { session_destroyed_ = true; }
407
htaa2a49d92016-03-04 02:51:39 -0800408 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000409
410 void InitWithIceTransport(
411 PeerConnectionInterface::IceTransportsType ice_transport_type) {
htaa2a49d92016-03-04 02:51:39 -0800412 configuration_.type = ice_transport_type;
413 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000414 }
415
416 void InitWithBundlePolicy(
417 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800418 configuration_.bundle_policy = bundle_policy;
419 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700420 }
421
422 void InitWithRtcpMuxPolicy(
423 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
424 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800425 configuration_.rtcp_mux_policy = rtcp_mux_policy;
426 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000427 }
428
Henrik Boström87713d02015-08-25 09:53:21 +0200429 // Successfully init with DTLS; with a certificate generated and supplied or
430 // with a store that generates it for us.
431 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
kwibergd1fe2812016-04-27 06:47:29 -0700432 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store;
Henrik Boström87713d02015-08-25 09:53:21 +0200433 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800434 configuration_.certificates.push_back(
Henrik Boström87713d02015-08-25 09:53:21 +0200435 FakeDtlsIdentityStore::GenerateCertificate());
436 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
437 dtls_identity_store.reset(new FakeDtlsIdentityStore());
438 dtls_identity_store->set_should_fail(false);
439 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700440 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200441 }
htaa2a49d92016-03-04 02:51:39 -0800442 Init(std::move(dtls_identity_store));
Henrik Boström87713d02015-08-25 09:53:21 +0200443 }
444
445 // Init with DTLS with a store that will fail to generate a certificate.
446 void InitWithDtlsIdentityGenFail() {
kwibergd1fe2812016-04-27 06:47:29 -0700447 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store(
Henrik Boström5e56c592015-08-11 10:33:13 +0200448 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200449 dtls_identity_store->set_should_fail(true);
htaa2a49d92016-03-04 02:51:39 -0800450 Init(std::move(dtls_identity_store));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000451 }
452
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453 void InitWithDtmfCodec() {
454 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700455 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
456 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457 std::vector<cricket::AudioCodec> codecs;
458 codecs.push_back(kTelephoneEventCodec);
459 media_engine_->SetAudioCodecs(codecs);
460 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000461 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 }
463
deadbeefab9b2d12015-10-14 11:33:11 -0700464 void SendAudioVideoStream1() {
465 send_stream_1_ = true;
466 send_stream_2_ = false;
467 send_audio_ = true;
468 send_video_ = true;
469 }
470
471 void SendAudioVideoStream2() {
472 send_stream_1_ = false;
473 send_stream_2_ = true;
474 send_audio_ = true;
475 send_video_ = true;
476 }
477
478 void SendAudioVideoStream1And2() {
479 send_stream_1_ = true;
480 send_stream_2_ = true;
481 send_audio_ = true;
482 send_video_ = true;
483 }
484
485 void SendNothing() {
486 send_stream_1_ = false;
487 send_stream_2_ = false;
488 send_audio_ = false;
489 send_video_ = false;
490 }
491
492 void SendAudioOnlyStream2() {
493 send_stream_1_ = false;
494 send_stream_2_ = true;
495 send_audio_ = true;
496 send_video_ = false;
497 }
498
499 void SendVideoOnlyStream2() {
500 send_stream_1_ = false;
501 send_stream_2_ = true;
502 send_audio_ = false;
503 send_video_ = true;
504 }
505
506 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
507 if (send_stream_1_ && send_audio_) {
508 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
509 kStream1);
510 }
511 if (send_stream_1_ && send_video_) {
512 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
513 kStream1);
514 }
515 if (send_stream_2_ && send_audio_) {
516 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
517 kStream2);
518 }
519 if (send_stream_2_ && send_video_) {
520 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
521 kStream2);
522 }
523 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
524 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
525 data_channel_->label(),
526 data_channel_->label());
527 }
528 }
529
530 void GetOptionsForOffer(
531 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
532 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800533 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700534
deadbeefc80741f2015-10-22 13:14:45 -0700535 AddStreamsToOptions(session_options);
536 if (rtc_options.offer_to_receive_audio ==
537 RTCOfferAnswerOptions::kUndefined) {
538 session_options->recv_audio =
539 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
540 }
541 if (rtc_options.offer_to_receive_video ==
542 RTCOfferAnswerOptions::kUndefined) {
543 session_options->recv_video =
544 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
545 }
546 session_options->bundle_enabled =
547 session_options->bundle_enabled &&
548 (session_options->has_audio() || session_options->has_video() ||
549 session_options->has_data());
550
deadbeefab9b2d12015-10-14 11:33:11 -0700551 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
552 session_options->data_channel_type = cricket::DCT_SCTP;
553 }
554 }
555
htaa2a49d92016-03-04 02:51:39 -0800556 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
557 // ParseConstraintsForAnswer is used to set some defaults.
558 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700559
deadbeefc80741f2015-10-22 13:14:45 -0700560 AddStreamsToOptions(session_options);
561 session_options->bundle_enabled =
562 session_options->bundle_enabled &&
563 (session_options->has_audio() || session_options->has_video() ||
564 session_options->has_data());
565
deadbeefab9b2d12015-10-14 11:33:11 -0700566 if (session_->data_channel_type() == cricket::DCT_SCTP) {
567 session_options->data_channel_type = cricket::DCT_SCTP;
568 }
569 }
570
571 // Creates a local offer and applies it. Starts ICE.
572 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000573 // to decide which streams to create.
574 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000575 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576 SetLocalDescriptionWithoutError(offer);
577 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
578 observer_.ice_gathering_state_,
579 kIceCandidatesTimeout);
580 }
581
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000582 SessionDescriptionInterface* CreateOffer() {
583 PeerConnectionInterface::RTCOfferAnswerOptions options;
584 options.offer_to_receive_audio =
585 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
586
587 return CreateOffer(options);
588 }
589
wu@webrtc.org91053e72013-08-10 07:18:04 +0000590 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800591 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000592 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000593 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700594 cricket::MediaSessionOptions session_options;
595 GetOptionsForOffer(options, &session_options);
596 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000597 EXPECT_TRUE_WAIT(
598 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000599 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000600 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000601 }
602
603 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800604 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000605 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000606 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800607 cricket::MediaSessionOptions session_options = options;
608 GetOptionsForAnswer(&session_options);
609 // Overwrite recv_audio and recv_video with passed-in values.
610 session_options.recv_video = options.recv_video;
611 session_options.recv_audio = options.recv_audio;
612 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000613 EXPECT_TRUE_WAIT(
614 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000615 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000616 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000617 }
618
htaa2a49d92016-03-04 02:51:39 -0800619 SessionDescriptionInterface* CreateAnswer() {
620 cricket::MediaSessionOptions options;
621 options.recv_video = true;
622 options.recv_audio = true;
623 return CreateAnswer(options);
624 }
625
wu@webrtc.org364f2042013-11-20 21:49:41 +0000626 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 return (session_->voice_channel() != NULL &&
628 session_->video_channel() != NULL);
629 }
630
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000631 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
632 ASSERT_TRUE(session_.get() != NULL);
633 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
634 ASSERT_TRUE(content != NULL);
635 const cricket::AudioContentDescription* audio_content =
636 static_cast<const cricket::AudioContentDescription*>(
637 content->description);
638 ASSERT_TRUE(audio_content != NULL);
639 ASSERT_EQ(1U, audio_content->cryptos().size());
640 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
641 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
642 audio_content->cryptos()[0].cipher_suite);
643 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
644 audio_content->protocol());
645
646 content = cricket::GetFirstVideoContent(sdp);
647 ASSERT_TRUE(content != NULL);
648 const cricket::VideoContentDescription* video_content =
649 static_cast<const cricket::VideoContentDescription*>(
650 content->description);
651 ASSERT_TRUE(video_content != NULL);
652 ASSERT_EQ(1U, video_content->cryptos().size());
653 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
654 video_content->cryptos()[0].cipher_suite);
655 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
656 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
657 video_content->protocol());
658 }
659
660 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
661 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
662 ASSERT_TRUE(content != NULL);
663 const cricket::AudioContentDescription* audio_content =
664 static_cast<const cricket::AudioContentDescription*>(
665 content->description);
666 ASSERT_TRUE(audio_content != NULL);
667 ASSERT_EQ(0U, audio_content->cryptos().size());
668
669 content = cricket::GetFirstVideoContent(sdp);
670 ASSERT_TRUE(content != NULL);
671 const cricket::VideoContentDescription* video_content =
672 static_cast<const cricket::VideoContentDescription*>(
673 content->description);
674 ASSERT_TRUE(video_content != NULL);
675 ASSERT_EQ(0U, video_content->cryptos().size());
676
677 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700678 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700680 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681 video_content->protocol());
682 } else {
683 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
684 audio_content->protocol());
685 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
686 video_content->protocol());
687 }
688 }
689
690 // Set the internal fake description factories to do DTLS-SRTP.
691 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000692 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000694 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200695 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800696 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700697 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800698 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000699 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
700 }
701
702 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
703 bool expected) {
704 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
705 ASSERT_TRUE(audio != NULL);
706 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 const TransportInfo* video = sdp->GetTransportInfoByName("video");
708 ASSERT_TRUE(video != NULL);
709 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 }
711
712 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000713 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000715 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000716 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000718 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000720 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
721 offer);
htaa2a49d92016-03-04 02:51:39 -0800722 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723 // Answer should be NULL as no crypto params in offer.
724 ASSERT_TRUE(answer == NULL);
725 }
726
727 void VerifyAnswerFromCryptoOffer() {
728 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000729 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700731 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
733 ASSERT_TRUE(offer.get() != NULL);
734 VerifyCryptoParams(offer->description());
735 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700736 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 ASSERT_TRUE(answer.get() != NULL);
738 VerifyCryptoParams(answer->description());
739 }
740
deadbeef0ed85b22016-02-23 17:24:52 -0800741 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
742 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800744 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 }
746
747 const cricket::ContentInfos& contents = desc1->contents();
748 cricket::ContentInfos::const_iterator it = contents.begin();
749
750 for (; it != contents.end(); ++it) {
751 const cricket::TransportDescription* transport_desc1 =
752 desc1->GetTransportDescriptionByName(it->name);
753 const cricket::TransportDescription* transport_desc2 =
754 desc2->GetTransportDescriptionByName(it->name);
755 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800756 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757 }
758 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
759 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800760 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 }
762 }
deadbeef0ed85b22016-02-23 17:24:52 -0800763 return true;
764 }
765
766 // Compares ufrag/password only for the specified |media_type|.
767 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
768 const cricket::SessionDescription* desc2,
769 cricket::MediaType media_type) {
770 if (desc1->contents().size() != desc2->contents().size()) {
771 return false;
772 }
773
774 const cricket::ContentInfo* cinfo =
775 cricket::GetFirstMediaContent(desc1->contents(), media_type);
776 const cricket::TransportDescription* transport_desc1 =
777 desc1->GetTransportDescriptionByName(cinfo->name);
778 const cricket::TransportDescription* transport_desc2 =
779 desc2->GetTransportDescriptionByName(cinfo->name);
780 if (!transport_desc1 || !transport_desc2) {
781 return false;
782 }
783 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
784 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
785 return false;
786 }
787 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000789
790 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
791 std::string *sdp) {
792 const cricket::SessionDescription* desc = current_desc->description();
793 EXPECT_TRUE(current_desc->ToString(sdp));
794
795 const cricket::ContentInfos& contents = desc->contents();
796 cricket::ContentInfos::const_iterator it = contents.begin();
797 // Replace ufrag and pwd lines with empty strings.
798 for (; it != contents.end(); ++it) {
799 const cricket::TransportDescription* transport_desc =
800 desc->GetTransportDescriptionByName(it->name);
801 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
802 + "\r\n";
803 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
804 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000805 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000806 "", 0,
807 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000808 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000809 "", 0,
810 sdp);
811 }
812 }
813
deadbeef0ed85b22016-02-23 17:24:52 -0800814 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
815 const std::string& ufrag,
816 const std::string& pwd) {
817 cricket::SessionDescription* desc = current_desc->description();
818 for (TransportInfo& transport_info : desc->transport_infos()) {
819 cricket::TransportDescription& transport_desc =
820 transport_info.description;
821 transport_desc.ice_ufrag = ufrag;
822 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000823 }
824 }
825
deadbeef0ed85b22016-02-23 17:24:52 -0800826 // Sets ufrag/pwd for specified |media_type|.
827 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
828 cricket::MediaType media_type,
829 const std::string& ufrag,
830 const std::string& pwd) {
831 cricket::SessionDescription* desc = current_desc->description();
832 const cricket::ContentInfo* cinfo =
833 cricket::GetFirstMediaContent(desc->contents(), media_type);
834 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
835 cricket::TransportDescription* transport_desc =
836 &transport_info->description;
837 transport_desc->ice_ufrag = ufrag;
838 transport_desc->ice_pwd = pwd;
839 }
840
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841 // Creates a remote offer and and applies it as a remote description,
842 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700843 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 // to decide which local and remote streams to create.
845 void CreateAndSetRemoteOfferAndLocalAnswer() {
846 SessionDescriptionInterface* offer = CreateRemoteOffer();
847 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800848 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 SetLocalDescriptionWithoutError(answer);
850 }
851 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
852 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700853 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 }
855 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700856 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 SetLocalDescriptionWithoutError(desc);
858 EXPECT_EQ(expected_state, session_->state());
859 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000860 void SetLocalDescriptionExpectError(const std::string& action,
861 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 SessionDescriptionInterface* desc) {
863 std::string error;
864 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000865 std::string sdp_type = "local ";
866 sdp_type.append(action);
867 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 EXPECT_NE(std::string::npos, error.find(expected_error));
869 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000870 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
871 SessionDescriptionInterface* desc) {
872 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
873 expected_error, desc);
874 }
875 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
876 SessionDescriptionInterface* desc) {
877 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
878 expected_error, desc);
879 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
881 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
882 }
883 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700884 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 SetRemoteDescriptionWithoutError(desc);
886 EXPECT_EQ(expected_state, session_->state());
887 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000888 void SetRemoteDescriptionExpectError(const std::string& action,
889 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 SessionDescriptionInterface* desc) {
891 std::string error;
892 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000893 std::string sdp_type = "remote ";
894 sdp_type.append(action);
895 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 EXPECT_NE(std::string::npos, error.find(expected_error));
897 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000898 void SetRemoteDescriptionOfferExpectError(
899 const std::string& expected_error, SessionDescriptionInterface* desc) {
900 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
901 expected_error, desc);
902 }
903 void SetRemoteDescriptionPranswerExpectError(
904 const std::string& expected_error, SessionDescriptionInterface* desc) {
905 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
906 expected_error, desc);
907 }
908 void SetRemoteDescriptionAnswerExpectError(
909 const std::string& expected_error, SessionDescriptionInterface* desc) {
910 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
911 expected_error, desc);
912 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913
914 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
915 SessionDescriptionInterface** nocrypto_answer) {
916 // Create a SDP without Crypto.
917 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000918 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 options.bundle_enabled = true;
920 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
921 ASSERT_TRUE(*offer != NULL);
922 VerifyCryptoParams((*offer)->description());
923
924 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
925 cricket::SEC_DISABLED);
926 EXPECT_TRUE(*nocrypto_answer != NULL);
927 }
928
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000929 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
930 SessionDescriptionInterface** nodtls_answer) {
931 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000932 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000933 options.bundle_enabled = true;
934
kwibergd1fe2812016-04-27 06:47:29 -0700935 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000936 CreateRemoteOffer(options, cricket::SEC_ENABLED));
937
938 *nodtls_answer =
939 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
940 EXPECT_TRUE(*nodtls_answer != NULL);
941 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
942 VerifyCryptoParams((*nodtls_answer)->description());
943
944 SetFactoryDtlsSrtp();
945 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
946 ASSERT_TRUE(*offer != NULL);
947 VerifyFingerprintStatus((*offer)->description(), true);
948 VerifyCryptoParams((*offer)->description());
949 }
950
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 JsepSessionDescription* CreateRemoteOfferWithVersion(
952 cricket::MediaSessionOptions options,
953 cricket::SecurePolicy secure_policy,
954 const std::string& session_version,
955 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000956 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 const cricket::SessionDescription* cricket_desc = NULL;
958 if (current_desc) {
959 cricket_desc = current_desc->description();
960 session_id = current_desc->session_id();
961 }
962
963 desc_factory_->set_secure(secure_policy);
964 JsepSessionDescription* offer(
965 new JsepSessionDescription(JsepSessionDescription::kOffer));
966 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
967 session_id, session_version)) {
968 delete offer;
969 offer = NULL;
970 }
971 return offer;
972 }
973 JsepSessionDescription* CreateRemoteOffer(
974 cricket::MediaSessionOptions options) {
975 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
976 kSessionVersion, NULL);
977 }
978 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000979 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
980 return CreateRemoteOfferWithVersion(
981 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 }
983 JsepSessionDescription* CreateRemoteOffer(
984 cricket::MediaSessionOptions options,
985 const SessionDescriptionInterface* current_desc) {
986 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
987 kSessionVersion, current_desc);
988 }
989
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000990 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
991 const char* sctp_stream_name, int new_port,
992 cricket::MediaSessionOptions options) {
993 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000994 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
995 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000996 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
997 }
998
999 // Takes ownership of offer_basis (and deletes it).
1000 JsepSessionDescription* ChangeSDPSctpPort(
1001 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1002 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1003 // SessionDescription from the mutated string.
1004 const char* default_port_str = "5000";
1005 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001006 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001007 std::string offer_str;
1008 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001009 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001010 new_port_str, strlen(new_port_str),
1011 &offer_str);
1012 JsepSessionDescription* offer = new JsepSessionDescription(
1013 offer_basis->type());
1014 delete offer_basis;
1015 offer->Initialize(offer_str, NULL);
1016 return offer;
1017 }
1018
deadbeefab9b2d12015-10-14 11:33:11 -07001019 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020 // before this function to decide which streams to create.
1021 JsepSessionDescription* CreateRemoteOffer() {
1022 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001023 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001024 return CreateRemoteOffer(options, session_->remote_description());
1025 }
1026
1027 JsepSessionDescription* CreateRemoteAnswer(
1028 const SessionDescriptionInterface* offer,
1029 cricket::MediaSessionOptions options,
1030 cricket::SecurePolicy policy) {
1031 desc_factory_->set_secure(policy);
1032 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001033 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001034 JsepSessionDescription* answer(
1035 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1036 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1037 options, NULL),
1038 session_id, kSessionVersion)) {
1039 delete answer;
1040 answer = NULL;
1041 }
1042 return answer;
1043 }
1044
1045 JsepSessionDescription* CreateRemoteAnswer(
1046 const SessionDescriptionInterface* offer,
1047 cricket::MediaSessionOptions options) {
1048 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1049 }
1050
deadbeefab9b2d12015-10-14 11:33:11 -07001051 // Creates an answer session description.
1052 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 // to decide which streams to create.
1054 JsepSessionDescription* CreateRemoteAnswer(
1055 const SessionDescriptionInterface* offer) {
1056 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001057 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1059 }
1060
1061 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001062 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001063 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001064 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001065
1066 PeerConnectionInterface::RTCOfferAnswerOptions options;
1067 options.use_rtp_mux = bundle;
1068
1069 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1071 // and answer.
1072 SetLocalDescriptionWithoutError(offer);
1073
kwibergd1fe2812016-04-27 06:47:29 -07001074 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001075 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 std::string sdp;
1077 EXPECT_TRUE(answer->ToString(&sdp));
1078
1079 size_t expected_candidate_num = 2;
1080 if (!rtcp_mux) {
1081 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1082 // for rtp and rtcp.
1083 expected_candidate_num = 4;
1084 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085 const std::string kRtcpMux = "a=rtcp-mux";
1086 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001087 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088 kXRtcpMux.c_str(), kXRtcpMux.length(),
1089 &sdp);
1090 }
1091
1092 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1093 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001094
1095 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001096 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001097 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1098 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001099 if (bundle) {
1100 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1101 } else {
1102 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001103 }
1104 }
1105 // Tests that we can only send DTMF when the dtmf codec is supported.
1106 void TestCanInsertDtmf(bool can) {
1107 if (can) {
1108 InitWithDtmfCodec();
1109 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001110 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 }
deadbeefab9b2d12015-10-14 11:33:11 -07001112 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001113 CreateAndSetRemoteOfferAndLocalAnswer();
1114 EXPECT_FALSE(session_->CanInsertDtmf(""));
1115 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1116 }
1117
zhihuang3a334652016-05-05 18:37:49 -07001118 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1119 const std::string& codec_name) {
1120 for (const auto& content : desc->description()->contents()) {
1121 if (static_cast<cricket::MediaContentDescription*>(content.description)
1122 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1123 const auto* mdesc =
1124 static_cast<cricket::VideoContentDescription*>(content.description);
1125 for (const auto& codec : mdesc->codecs()) {
1126 if (codec.name == codec_name) {
1127 return true;
1128 }
1129 }
1130 }
1131 }
1132 return false;
1133 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001134 // Helper class to configure loopback network and verify Best
1135 // Connection using right IP protocol for TestLoopbackCall
1136 // method. LoopbackNetworkManager applies firewall rules to block
1137 // all ping traffic once ICE completed, and remove them to observe
1138 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1139 // verifies the best connection is using the right IP protocol after
1140 // initial ICE convergences.
1141
1142 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001143 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001144 LoopbackNetworkConfiguration()
1145 : test_ipv6_network_(false),
1146 test_extra_ipv4_network_(false),
1147 best_connection_after_initial_ice_converged_(1, 0) {}
1148
1149 // Used to track the expected best connection count in each IP protocol.
1150 struct ExpectedBestConnection {
1151 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1152 : ipv4_count_(ipv4_count),
1153 ipv6_count_(ipv6_count) {}
1154
1155 int ipv4_count_;
1156 int ipv6_count_;
1157 };
1158
1159 bool test_ipv6_network_;
1160 bool test_extra_ipv4_network_;
1161 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1162
1163 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001164 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001165 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1166 }
1167
1168 private:
jbauchac8869e2015-07-03 01:36:14 -07001169 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001170 const ExpectedBestConnection& expected) const {
1171 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001172 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1173 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001174 expected.ipv4_count_);
1175 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001176 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1177 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001178 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001179 // This is used in the loopback call so there is only single host to host
1180 // candidate pair.
1181 EXPECT_EQ(metrics_observer->GetEnumCounter(
1182 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1183 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001184 0);
1185 EXPECT_EQ(metrics_observer->GetEnumCounter(
1186 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1187 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001188 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001189 }
1190 };
1191
1192 class LoopbackNetworkManager {
1193 public:
1194 LoopbackNetworkManager(WebRtcSessionTest* session,
1195 const LoopbackNetworkConfiguration& config)
1196 : config_(config) {
1197 session->AddInterface(
1198 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1199 if (config_.test_extra_ipv4_network_) {
1200 session->AddInterface(
1201 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1202 }
1203 if (config_.test_ipv6_network_) {
1204 session->AddInterface(
1205 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1206 }
1207 }
1208
1209 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1210 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1211 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1212 if (config_.test_extra_ipv4_network_) {
1213 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1214 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1215 }
1216 if (config_.test_ipv6_network_) {
1217 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1218 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1219 }
1220 }
1221
1222 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1223
1224 private:
1225 LoopbackNetworkConfiguration config_;
1226 };
1227
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001228 // The method sets up a call from the session to itself, in a loopback
1229 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001230 // disconnection, and then a permanent disconnection.
1231 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1233 // While running the call, this method also checks if the session goes through
1234 // the correct sequence of ICE states when a connection is established,
1235 // broken, and re-established.
1236 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001237 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1238 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001239 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001240
stefanc1aeaf02015-10-15 07:26:07 -07001241 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001242 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001243 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001244 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001245
1246 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1247 observer_.ice_gathering_state_);
1248 SetLocalDescriptionWithoutError(offer);
1249 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1250 observer_.ice_connection_state_);
1251 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001252 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001253 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1254 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001255 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256
1257 std::string sdp;
1258 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001259 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1260 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001261 ASSERT_TRUE(desc != NULL);
1262 SetRemoteDescriptionWithoutError(desc);
1263
1264 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001265 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001266
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001267 // The ice connection state is "Connected" too briefly to catch in a test.
1268 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001269 observer_.ice_connection_state_, kIceCandidatesTimeout);
1270 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001271
stefanc1aeaf02015-10-15 07:26:07 -07001272 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1273 LoopbackNetworkManager loopback_network_manager(this, config);
1274 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001275 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276 // Adding firewall rule to block ping requests, which should cause
1277 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001278
1279 loopback_network_manager.ApplyFirewallRules(fss_.get());
1280
1281 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001282 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1283 observer_.ice_connection_state_,
1284 kIceCandidatesTimeout);
1285
jbauchac8869e2015-07-03 01:36:14 -07001286 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001287
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001289 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001291 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001292 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001293 observer_.ice_connection_state_,
1294 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001295
1296 // Now we block ping requests and wait until the ICE connection transitions
1297 // to the Failed state. This will take at least 30 seconds because it must
1298 // wait for the Port to timeout.
1299 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001300
1301 loopback_network_manager.ApplyFirewallRules(fss_.get());
1302 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001303 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001304 observer_.ice_connection_state_,
1305 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 }
1307
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001308 void TestLoopbackCall() {
1309 LoopbackNetworkConfiguration config;
1310 TestLoopbackCall(config);
1311 }
1312
stefanc1aeaf02015-10-15 07:26:07 -07001313 void TestPacketOptions() {
1314 media_controller_.reset(
1315 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1316 LoopbackNetworkConfiguration config;
1317 LoopbackNetworkManager loopback_network_manager(this, config);
1318
1319 SetupLoopbackCall();
1320
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001321 // Wait for channel to be ready for sending.
1322 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001323 uint8_t test_packet[15] = {0};
1324 rtc::PacketOptions options;
1325 options.packet_id = 10;
1326 media_engine_->GetVideoChannel(0)
1327 ->SendRtp(test_packet, sizeof(test_packet), options);
1328
1329 const int kPacketTimeout = 2000;
1330 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1331 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1332 }
1333
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001334 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1335 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001336 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1337 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001338
1339 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001340 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1341 codecs.push_back(kCNCodec1);
1342 codecs.push_back(kCNCodec2);
1343 media_engine_->SetAudioCodecs(codecs);
1344 desc_factory_->set_audio_codecs(codecs);
1345 }
1346
1347 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1348 const cricket::ContentDescription* description = content->description;
1349 ASSERT(description != NULL);
1350 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001351 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001352 ASSERT(audio_content_desc != NULL);
1353 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1354 if (audio_content_desc->codecs()[i].name == "CN")
1355 return false;
1356 }
1357 return true;
1358 }
1359
deadbeefab9b2d12015-10-14 11:33:11 -07001360 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001361 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001362 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001363 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1364 data_channel_ = DataChannel::Create(
1365 session_.get(), session_->data_channel_type(), "datachannel", dci);
1366 }
1367
1368 void SetLocalDescriptionWithDataChannel() {
1369 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001370 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001371 SetLocalDescriptionWithoutError(offer);
1372 }
1373
wu@webrtc.org91053e72013-08-10 07:18:04 +00001374 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001375 RTCCertificateGenerationMethod cert_gen_method,
1376 CreateSessionDescriptionRequest::Type type) {
1377 InitWithDtls(cert_gen_method);
1378 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1379 }
1380
1381 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1382 CreateSessionDescriptionRequest::Type type) {
1383 InitWithDtlsIdentityGenFail();
1384 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1385 }
1386
1387 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001388 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001389 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001390 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001391 if (type == CreateSessionDescriptionRequest::kAnswer) {
1392 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001393 std::unique_ptr<JsepSessionDescription> offer(
1394 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001395 ASSERT_TRUE(offer.get() != NULL);
1396 SetRemoteDescriptionWithoutError(offer.release());
1397 }
1398
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001399 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001400 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001401 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001402 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001403 observers[kNumber];
1404 for (int i = 0; i < kNumber; ++i) {
1405 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1406 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001407 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001408 } else {
htaa2a49d92016-03-04 02:51:39 -08001409 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001410 }
1411 }
1412
1413 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1414 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1415 WebRtcSessionCreateSDPObserverForTest::kFailed;
1416
1417 for (int i = 0; i < kNumber; ++i) {
1418 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1419 if (success) {
1420 EXPECT_TRUE(observers[i]->description() != NULL);
1421 } else {
1422 EXPECT_TRUE(observers[i]->description() == NULL);
1423 }
1424 }
1425 }
1426
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001427 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001428 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001429 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001430 turn_server.credentials = credentials;
1431 turn_server.ports.push_back(
1432 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1433 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001434 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001435 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001436 }
1437
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438 cricket::FakeMediaEngine* media_engine_;
1439 cricket::FakeDataEngine* data_engine_;
kwibergd1fe2812016-04-27 06:47:29 -07001440 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001441 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001442 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1443 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1444 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1445 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1446 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1447 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001448 rtc::SocketServerScope ss_scope_;
1449 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001450 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001451 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001452 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001453 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001454 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001455 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001456 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001457 MockIceObserver observer_;
1458 cricket::FakeVideoMediaChannel* video_channel_;
1459 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001460 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001461 // The following flags affect options created for CreateOffer/CreateAnswer.
1462 bool send_stream_1_ = false;
1463 bool send_stream_2_ = false;
1464 bool send_audio_ = false;
1465 bool send_video_ = false;
1466 rtc::scoped_refptr<DataChannel> data_channel_;
1467 // Last values received from data channel creation signal.
1468 std::string last_data_channel_label_;
1469 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001470 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001471};
1472
Henrik Boström87713d02015-08-25 09:53:21 +02001473TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1474 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001475 // SDES is disabled when DTLS is on.
1476 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001477}
1478
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001479TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001480 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001481 // SDES is required if DTLS is off.
1482 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001483}
1484
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001485TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1486 TestSessionCandidatesWithBundleRtcpMux(false, false);
1487}
1488
1489// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1490// with rtcp-mux and/or bundle.
1491TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1492 TestSessionCandidatesWithBundleRtcpMux(false, true);
1493}
1494
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1496 TestSessionCandidatesWithBundleRtcpMux(true, true);
1497}
1498
1499TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001500 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1501 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001502 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001503 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001504 InitiateCall();
1505 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1506 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1507 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1508}
1509
minyuec8930ba2016-01-22 06:17:46 -08001510// Crashes on Win only. See webrtc:5411.
1511#if defined(WEBRTC_WIN)
1512#define MAYBE_TestStunError DISABLED_TestStunError
1513#else
1514#define MAYBE_TestStunError TestStunError
1515#endif
1516TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001517 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1518 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001519 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001520 rtc::FP_UDP,
1521 rtc::FD_ANY,
1522 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001523 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001524 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001526 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1528 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1529 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1530}
1531
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001532// Test session delivers no candidates gathered when constraint set to "none".
1533TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1534 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001535 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001536 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001537 InitiateCall();
1538 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1539 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1540 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1541}
1542
1543// Test session delivers only relay candidates gathered when constaint set to
1544// "relay".
1545TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1546 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1547 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001548 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001549 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001550 InitiateCall();
1551 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1552 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1553 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1554 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1555 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1556 observer_.mline_0_candidates_[i].type());
1557 }
1558 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1559 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1560 observer_.mline_1_candidates_[i].type());
1561 }
1562}
1563
1564// Test session delivers all candidates gathered when constaint set to "all".
1565TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1566 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001567 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001568 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001569 InitiateCall();
1570 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1571 // Host + STUN. By default allocator is disabled to gather relay candidates.
1572 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1573 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1574}
1575
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001576TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001577 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001578 SessionDescriptionInterface* offer = NULL;
1579 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1580 std::string unknown_action;
1581 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1582 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1583}
1584
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585// Test creating offers and receive answers and make sure the
1586// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001587TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001588 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001589 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001590 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591 const std::string session_id_orig = offer->session_id();
1592 const std::string session_version_orig = offer->session_version();
1593 SetLocalDescriptionWithoutError(offer);
1594
deadbeefab9b2d12015-10-14 11:33:11 -07001595 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596 SessionDescriptionInterface* answer =
1597 CreateRemoteAnswer(session_->local_description());
1598 SetRemoteDescriptionWithoutError(answer);
1599
1600 video_channel_ = media_engine_->GetVideoChannel(0);
1601 voice_channel_ = media_engine_->GetVoiceChannel(0);
1602
1603 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1604 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1605
1606 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1607 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1608
1609 ASSERT_EQ(1u, video_channel_->send_streams().size());
1610 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1611 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1612 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1613
1614 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001615 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001616 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001617
1618 // Verify the session id is the same and the session version is
1619 // increased.
1620 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001621 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1622 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623
1624 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001625 EXPECT_EQ(0u, video_channel_->send_streams().size());
1626 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627
deadbeefab9b2d12015-10-14 11:33:11 -07001628 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 answer = CreateRemoteAnswer(session_->local_description());
1630 SetRemoteDescriptionWithoutError(answer);
1631
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632 // Make sure the receive streams have not changed.
1633 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1634 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1635 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1636 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1637}
1638
1639// Test receiving offers and creating answers and make sure the
1640// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001641TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001642 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001643 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001644 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001645 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001646 SetRemoteDescriptionWithoutError(offer);
1647
deadbeefab9b2d12015-10-14 11:33:11 -07001648 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001649 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001650 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001651 SetLocalDescriptionWithoutError(answer);
1652
1653 const std::string session_id_orig = answer->session_id();
1654 const std::string session_version_orig = answer->session_version();
1655
1656 video_channel_ = media_engine_->GetVideoChannel(0);
1657 voice_channel_ = media_engine_->GetVoiceChannel(0);
1658
htaa2a49d92016-03-04 02:51:39 -08001659 ASSERT_TRUE(video_channel_);
1660 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1662 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1663
1664 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1665 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1666
1667 ASSERT_EQ(1u, video_channel_->send_streams().size());
1668 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1669 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1670 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1671
deadbeefab9b2d12015-10-14 11:33:11 -07001672 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001673 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001674 SetRemoteDescriptionWithoutError(offer);
1675
1676 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001677 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001678 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679
1680 // Verify the session id is the same and the session version is
1681 // increased.
1682 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001683 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1684 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001685 SetLocalDescriptionWithoutError(answer);
1686
1687 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1688 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1689 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1690 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1691 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1692 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1693
1694 // Make sure we have no send streams.
1695 EXPECT_EQ(0u, video_channel_->send_streams().size());
1696 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1697}
1698
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001699TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001700 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001701 media_engine_->set_fail_create_channel(true);
1702
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001703 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001704 ASSERT_TRUE(offer != NULL);
1705 // SetRemoteDescription and SetLocalDescription will take the ownership of
1706 // the offer.
1707 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001708 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001709 ASSERT_TRUE(offer != NULL);
1710 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1711}
1712
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001713//
1714// Tests for creating/setting SDP under different SDES/DTLS polices:
1715//
1716// --DTLS off and SDES on
1717// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1718// set local/remote offer/answer with crypto --> success
1719// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1720// failure
1721// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1722// failure
1723// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1724// failure
1725//
1726// --DTLS on and SDES off
1727// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1728// set local/remote offer/answer with DTLS fingerprint --> success
1729// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1730// fingerprint --> failure
1731// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1732// --> failure
1733// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1734// --> failure
1735//
1736// --Encryption disabled: DTLS off and SDES off
1737// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1738// answer without SDES or DTLS --> success
1739// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1740// answer without SDES or DTLS --> success
1741//
1742
1743// Test that we return a failure when applying a remote/local offer that doesn't
1744// have cryptos enabled when DTLS is off.
1745TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001746 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001748 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749 JsepSessionDescription* offer = CreateRemoteOffer(
1750 options, cricket::SEC_DISABLED);
1751 ASSERT_TRUE(offer != NULL);
1752 VerifyNoCryptoParams(offer->description(), false);
1753 // SetRemoteDescription and SetLocalDescription will take the ownership of
1754 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001755 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1757 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001758 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759}
1760
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001761// Test that we return a failure when applying a local answer that doesn't have
1762// cryptos enabled when DTLS is off.
1763TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001764 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 SessionDescriptionInterface* offer = NULL;
1766 SessionDescriptionInterface* answer = NULL;
1767 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1768 // SetRemoteDescription and SetLocalDescription will take the ownership of
1769 // the offer.
1770 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001771 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772}
1773
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001774// Test we will return fail when apply an remote answer that doesn't have
1775// crypto enabled when DTLS is off.
1776TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001777 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 SessionDescriptionInterface* offer = NULL;
1779 SessionDescriptionInterface* answer = NULL;
1780 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1781 // SetRemoteDescription and SetLocalDescription will take the ownership of
1782 // the offer.
1783 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001784 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785}
1786
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001787// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1788// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001789TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001790 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001791 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001792 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 SetFactoryDtlsSrtp();
1794 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001795 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001796 JsepSessionDescription* offer =
1797 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 ASSERT_TRUE(offer != NULL);
1799 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001800 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801
1802 // SetRemoteDescription will take the ownership of the offer.
1803 SetRemoteDescriptionWithoutError(offer);
1804
1805 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001806 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 ASSERT_TRUE(answer != NULL);
1808 VerifyFingerprintStatus(answer->description(), true);
1809 // Check that we don't have an a=crypto line in the answer.
1810 VerifyNoCryptoParams(answer->description(), true);
1811
1812 // Now set the local description, which should work, even without a=crypto.
1813 SetLocalDescriptionWithoutError(answer);
1814}
1815
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001816// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1817// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001818TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001819 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001820 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001821 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001822 SetFactoryDtlsSrtp();
1823
1824 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001825 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001826 ASSERT_TRUE(offer != NULL);
1827 VerifyFingerprintStatus(offer->description(), true);
1828 // Check that we don't have an a=crypto line in the offer.
1829 VerifyNoCryptoParams(offer->description(), true);
1830
1831 // Now set the local description, which should work, even without a=crypto.
1832 SetLocalDescriptionWithoutError(offer);
1833
1834 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001835 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001836 JsepSessionDescription* answer =
1837 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1838 ASSERT_TRUE(answer != NULL);
1839 VerifyFingerprintStatus(answer->description(), true);
1840 VerifyNoCryptoParams(answer->description(), true);
1841
1842 // SetRemoteDescription will take the ownership of the answer.
1843 SetRemoteDescriptionWithoutError(answer);
1844}
1845
1846// Test that if we support DTLS and the other side didn't offer a fingerprint,
1847// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001848TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001849 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001850 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001851 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001852 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001853 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854 JsepSessionDescription* offer = CreateRemoteOffer(
1855 options, cricket::SEC_REQUIRED);
1856 ASSERT_TRUE(offer != NULL);
1857 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001858 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001860 // SetRemoteDescription will take the ownership of the offer.
1861 SetRemoteDescriptionOfferExpectError(
1862 kSdpWithoutDtlsFingerprint, offer);
1863
1864 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1865 // SetLocalDescription will take the ownership of the offer.
1866 SetLocalDescriptionOfferExpectError(
1867 kSdpWithoutDtlsFingerprint, offer);
1868}
1869
1870// Test that we return a failure when applying a local answer that doesn't have
1871// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001872TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001873 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001874 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001875 SessionDescriptionInterface* offer = NULL;
1876 SessionDescriptionInterface* answer = NULL;
1877 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1878
1879 // SetRemoteDescription and SetLocalDescription will take the ownership of
1880 // the offer and answer.
1881 SetRemoteDescriptionWithoutError(offer);
1882 SetLocalDescriptionAnswerExpectError(
1883 kSdpWithoutDtlsFingerprint, answer);
1884}
1885
1886// Test that we return a failure when applying a remote answer that doesn't have
1887// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001888TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001889 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001890 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001891 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001892 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001893 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001894 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001895 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001896 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001897 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001898
1899 // SetRemoteDescription and SetLocalDescription will take the ownership of
1900 // the offer and answer.
1901 SetLocalDescriptionWithoutError(offer);
1902 SetRemoteDescriptionAnswerExpectError(
1903 kSdpWithoutDtlsFingerprint, answer);
1904}
1905
1906// Test that we create a local offer without SDES or DTLS and accept a remote
1907// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001908TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001909 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001910 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001911 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001912
1913 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001914 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001915 ASSERT_TRUE(offer != NULL);
1916 VerifyFingerprintStatus(offer->description(), false);
1917 // Check that we don't have an a=crypto line in the offer.
1918 VerifyNoCryptoParams(offer->description(), false);
1919
1920 // Now set the local description, which should work, even without a=crypto.
1921 SetLocalDescriptionWithoutError(offer);
1922
1923 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001924 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001925 JsepSessionDescription* answer =
1926 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1927 ASSERT_TRUE(answer != NULL);
1928 VerifyFingerprintStatus(answer->description(), false);
1929 VerifyNoCryptoParams(answer->description(), false);
1930
1931 // SetRemoteDescription will take the ownership of the answer.
1932 SetRemoteDescriptionWithoutError(answer);
1933}
1934
1935// Test that we create a local answer without SDES or DTLS and accept a remote
1936// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001937TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001938 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001939 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001940
1941 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001942 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001943 JsepSessionDescription* offer =
1944 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1945 ASSERT_TRUE(offer != NULL);
1946 VerifyFingerprintStatus(offer->description(), false);
1947 VerifyNoCryptoParams(offer->description(), false);
1948
1949 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950 SetRemoteDescriptionWithoutError(offer);
1951
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001952 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001953 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954 ASSERT_TRUE(answer != NULL);
1955 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001956 // Check that we don't have an a=crypto line in the answer.
1957 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001959 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960 SetLocalDescriptionWithoutError(answer);
1961}
1962
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001963// Test that we can create and set an answer correctly when different
1964// SSL roles have been negotiated for different transports.
1965// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1966TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1967 SendAudioVideoStream1();
1968 InitWithDtls(GetParam());
1969 SetFactoryDtlsSrtp();
1970
1971 SessionDescriptionInterface* offer = CreateOffer();
1972 SetLocalDescriptionWithoutError(offer);
1973
1974 cricket::MediaSessionOptions options;
1975 options.recv_video = true;
1976
1977 // First, negotiate different SSL roles.
1978 SessionDescriptionInterface* answer =
1979 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1980 TransportInfo* audio_transport_info =
1981 answer->description()->GetTransportInfoByName("audio");
1982 audio_transport_info->description.connection_role =
1983 cricket::CONNECTIONROLE_ACTIVE;
1984 TransportInfo* video_transport_info =
1985 answer->description()->GetTransportInfoByName("video");
1986 video_transport_info->description.connection_role =
1987 cricket::CONNECTIONROLE_PASSIVE;
1988 SetRemoteDescriptionWithoutError(answer);
1989
1990 // Now create an offer in the reverse direction, and ensure the initial
1991 // offerer responds with an answer with correct SSL roles.
1992 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1993 kSessionVersion,
1994 session_->remote_description());
1995 SetRemoteDescriptionWithoutError(offer);
1996
htaa2a49d92016-03-04 02:51:39 -08001997 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001998 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1999 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2000 audio_transport_info->description.connection_role);
2001 video_transport_info = answer->description()->GetTransportInfoByName("video");
2002 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2003 video_transport_info->description.connection_role);
2004 SetLocalDescriptionWithoutError(answer);
2005
2006 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2007 // audio is transferred over to video in the answer that completes the BUNDLE
2008 // negotiation.
2009 options.bundle_enabled = true;
2010 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2011 kSessionVersion,
2012 session_->remote_description());
2013 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002014 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002015 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2016 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2017 audio_transport_info->description.connection_role);
2018 video_transport_info = answer->description()->GetTransportInfoByName("video");
2019 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2020 video_transport_info->description.connection_role);
2021 SetLocalDescriptionWithoutError(answer);
2022}
2023
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002025 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002026 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002028 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002029 SetLocalDescriptionWithoutError(offer);
2030
2031 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002032 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033 SetLocalDescriptionWithoutError(offer2);
2034}
2035
2036TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002037 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002038 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002040 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041 SetRemoteDescriptionWithoutError(offer);
2042
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002043 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044 SetRemoteDescriptionWithoutError(offer2);
2045}
2046
2047TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002048 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002049 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002050 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002052 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002053 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2054 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055}
2056
2057TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002058 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002059 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002060 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002062 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002063 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002064 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065}
2066
2067TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002068 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002069 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002071 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072
htaa2a49d92016-03-04 02:51:39 -08002073 JsepSessionDescription* pranswer =
2074 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002076 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077
deadbeefab9b2d12015-10-14 11:33:11 -07002078 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002079 JsepSessionDescription* pranswer2 =
2080 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002081 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2082
deadbeefd59daf82015-10-14 15:02:44 -07002083 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084
deadbeefab9b2d12015-10-14 11:33:11 -07002085 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002086 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002087 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088}
2089
2090TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002091 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002092 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002093 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002094 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095
2096 JsepSessionDescription* pranswer =
2097 CreateRemoteAnswer(session_->local_description());
2098 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2099
2100 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002101 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102
deadbeefab9b2d12015-10-14 11:33:11 -07002103 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104 JsepSessionDescription* pranswer2 =
2105 CreateRemoteAnswer(session_->local_description());
2106 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2107
2108 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002109 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110
deadbeefab9b2d12015-10-14 11:33:11 -07002111 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112 SessionDescriptionInterface* answer =
2113 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002114 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115}
2116
2117TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002118 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002119 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002120 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002121
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122 SessionDescriptionInterface* answer =
2123 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002124 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2125 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126}
2127
2128TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002129 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002130 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002131 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002132
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 SessionDescriptionInterface* answer =
2134 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002135 SetRemoteDescriptionAnswerExpectError(
2136 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137}
2138
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002139// Tests that the remote candidates are added and removed successfully.
2140TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002141 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002142 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002144 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2145 "", "", "host", 0, "");
2146 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2148
deadbeefd59daf82015-10-14 15:02:44 -07002149 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2151
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002152 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002154
2155 // Fail since we have not set a remote description.
2156 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157
2158 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2159 session_->local_description());
2160 SetRemoteDescriptionWithoutError(answer);
2161
deadbeefd59daf82015-10-14 15:02:44 -07002162 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2163 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002164 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002165 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2166 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2167
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168 // Verifying the candidates are copied properly from internal vector.
2169 const SessionDescriptionInterface* remote_desc =
2170 session_->remote_description();
2171 ASSERT_TRUE(remote_desc != NULL);
2172 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2173 const IceCandidateCollection* candidates =
2174 remote_desc->candidates(kMediaContentIndex0);
2175 ASSERT_EQ(2u, candidates->count());
2176 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2177 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2178 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2179 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2180
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002181 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2182 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183 candidate.set_component(2);
2184 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2185 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002186 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187
2188 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2189 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002190
2191 // Remove candidate1 and candidate2
2192 std::vector<cricket::Candidate> remote_candidates;
2193 remote_candidates.push_back(ice_candidate1.candidate());
2194 remote_candidates.push_back(ice_candidate2.candidate());
2195 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2196 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002197}
2198
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002199// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002200// that it is retained if the remote session description is changed.
2201TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002202 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203 cricket::Candidate candidate1;
2204 candidate1.set_component(1);
2205 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2206 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002207 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208 CreateAndSetRemoteOfferAndLocalAnswer();
2209
2210 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2211 const SessionDescriptionInterface* remote_desc =
2212 session_->remote_description();
2213 ASSERT_TRUE(remote_desc != NULL);
2214 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2215 const IceCandidateCollection* candidates =
2216 remote_desc->candidates(kMediaContentIndex0);
2217 ASSERT_EQ(1u, candidates->count());
2218 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2219
2220 // Update the RemoteSessionDescription with a new session description and
2221 // a candidate and check that the new remote session description contains both
2222 // candidates.
2223 SessionDescriptionInterface* offer = CreateRemoteOffer();
2224 cricket::Candidate candidate2;
2225 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2226 candidate2);
2227 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2228 SetRemoteDescriptionWithoutError(offer);
2229
2230 remote_desc = session_->remote_description();
2231 ASSERT_TRUE(remote_desc != NULL);
2232 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2233 candidates = remote_desc->candidates(kMediaContentIndex0);
2234 ASSERT_EQ(2u, candidates->count());
2235 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2236 // Username and password have be updated with the TransportInfo of the
2237 // SessionDescription, won't be equal to the original one.
2238 candidate2.set_username(candidates->at(0)->candidate().username());
2239 candidate2.set_password(candidates->at(0)->candidate().password());
2240 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2241 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2242 // No need to verify the username and password.
2243 candidate1.set_username(candidates->at(1)->candidate().username());
2244 candidate1.set_password(candidates->at(1)->candidate().password());
2245 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2246
2247 // Test that the candidate is ignored if we can add the same candidate again.
2248 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2249}
2250
2251// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002252// that they are retained if the local session description is changed. And if
2253// continual gathering is enabled, they are removed from the local session
2254// description when the network is down.
2255TEST_F(WebRtcSessionTest,
2256 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002257 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002258 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002259 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260 CreateAndSetRemoteOfferAndLocalAnswer();
2261
2262 const SessionDescriptionInterface* local_desc = session_->local_description();
2263 const IceCandidateCollection* candidates =
2264 local_desc->candidates(kMediaContentIndex0);
2265 ASSERT_TRUE(candidates != NULL);
2266 EXPECT_EQ(0u, candidates->count());
2267
2268 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2269
2270 local_desc = session_->local_description();
2271 candidates = local_desc->candidates(kMediaContentIndex0);
2272 ASSERT_TRUE(candidates != NULL);
2273 EXPECT_LT(0u, candidates->count());
2274 candidates = local_desc->candidates(1);
2275 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002276 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277
2278 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002279 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280 CreateAndSetRemoteOfferAndLocalAnswer();
2281
2282 local_desc = session_->local_description();
2283 candidates = local_desc->candidates(kMediaContentIndex0);
2284 ASSERT_TRUE(candidates != NULL);
2285 EXPECT_LT(0u, candidates->count());
2286 candidates = local_desc->candidates(1);
2287 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002288 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002289
2290 candidates = local_desc->candidates(kMediaContentIndex0);
2291 size_t num_local_candidates = candidates->count();
2292 // Enable Continual Gathering
2293 session_->SetIceConfig(cricket::IceConfig(-1, -1, true, false, -1));
2294 // Bring down the network interface to trigger candidate removals.
2295 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2296 // Verify that all local candidates are removed.
2297 EXPECT_EQ(0, observer_.num_candidates_removed_);
2298 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2299 kIceCandidatesTimeout);
2300 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2301}
2302
2303// Tests that if continual gathering is disabled, local candidates won't be
2304// removed when the interface is turned down.
2305TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2306 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2307 Init();
2308 SendAudioVideoStream1();
2309 CreateAndSetRemoteOfferAndLocalAnswer();
2310
2311 const SessionDescriptionInterface* local_desc = session_->local_description();
2312 const IceCandidateCollection* candidates =
2313 local_desc->candidates(kMediaContentIndex0);
2314 ASSERT_TRUE(candidates != NULL);
2315 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2316
2317 size_t num_local_candidates = candidates->count();
2318 EXPECT_LT(0u, num_local_candidates);
2319 // By default, Continual Gathering is disabled.
2320 // Bring down the network interface.
2321 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2322 // Verify that the local candidates are not removed.
2323 rtc::Thread::Current()->ProcessMessages(1000);
2324 EXPECT_EQ(0, observer_.num_candidates_removed_);
2325 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326}
2327
2328// Test that we can set a remote session description with remote candidates.
2329TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002330 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331
2332 cricket::Candidate candidate1;
2333 candidate1.set_component(1);
2334 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2335 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002336 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002337 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338
2339 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2340 SetRemoteDescriptionWithoutError(offer);
2341
2342 const SessionDescriptionInterface* remote_desc =
2343 session_->remote_description();
2344 ASSERT_TRUE(remote_desc != NULL);
2345 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2346 const IceCandidateCollection* candidates =
2347 remote_desc->candidates(kMediaContentIndex0);
2348 ASSERT_EQ(1u, candidates->count());
2349 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2350
htaa2a49d92016-03-04 02:51:39 -08002351 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 SetLocalDescriptionWithoutError(answer);
2353}
2354
2355// Test that offers and answers contains ice candidates when Ice candidates have
2356// been gathered.
2357TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002358 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002359 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002360 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 // Ice is started but candidates are not provided until SetLocalDescription
2362 // is called.
2363 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2364 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2365 CreateAndSetRemoteOfferAndLocalAnswer();
2366 // Wait until at least one local candidate has been collected.
2367 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2368 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369
kwibergd1fe2812016-04-27 06:47:29 -07002370 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002371
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002372 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2373 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374
2375 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2376 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002377 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2379 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380 SetLocalDescriptionWithoutError(answer);
2381}
2382
2383// Verifies TransportProxy and media channels are created with content names
2384// present in the SessionDescription.
2385TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002386 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002387 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002388 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389
2390 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002391 // "video". Goal is to modify these content names and verify transport
2392 // channels
2393 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394 // present in SDP.
2395 std::string sdp;
2396 EXPECT_TRUE(offer->ToString(&sdp));
2397 const std::string kAudioMid = "a=mid:audio";
2398 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2399 const std::string kVideoMid = "a=mid:video";
2400 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2401
2402 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002403 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404 kAudioMidReplaceStr.c_str(),
2405 kAudioMidReplaceStr.length(),
2406 &sdp);
2407 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002408 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 kVideoMidReplaceStr.c_str(),
2410 kVideoMidReplaceStr.length(),
2411 &sdp);
2412
2413 SessionDescriptionInterface* modified_offer =
2414 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2415
2416 SetRemoteDescriptionWithoutError(modified_offer);
2417
htaa2a49d92016-03-04 02:51:39 -08002418 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419 SetLocalDescriptionWithoutError(answer);
2420
deadbeefcbecd352015-09-23 11:50:27 -07002421 cricket::TransportChannel* voice_transport_channel =
2422 session_->voice_rtp_transport_channel();
2423 EXPECT_TRUE(voice_transport_channel != NULL);
2424 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2425 cricket::TransportChannel* video_transport_channel =
2426 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002427 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002428 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002429 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2430 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2431}
2432
2433// Test that an offer contains the correct media content descriptions based on
2434// the send streams when no constraints have been set.
2435TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002436 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002437 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002438
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002439 ASSERT_TRUE(offer != NULL);
2440 const cricket::ContentInfo* content =
2441 cricket::GetFirstAudioContent(offer->description());
2442 EXPECT_TRUE(content != NULL);
2443 content = cricket::GetFirstVideoContent(offer->description());
2444 EXPECT_TRUE(content == NULL);
2445}
2446
2447// Test that an offer contains the correct media content descriptions based on
2448// the send streams when no constraints have been set.
2449TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002450 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002451 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002452 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002453 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002454
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002455 const cricket::ContentInfo* content =
2456 cricket::GetFirstAudioContent(offer->description());
2457 EXPECT_TRUE(content != NULL);
2458 content = cricket::GetFirstVideoContent(offer->description());
2459 EXPECT_TRUE(content == NULL);
2460
2461 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002462 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002463 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002464 content = cricket::GetFirstAudioContent(offer->description());
2465 EXPECT_TRUE(content != NULL);
2466 content = cricket::GetFirstVideoContent(offer->description());
2467 EXPECT_TRUE(content != NULL);
2468}
2469
2470// Test that an offer contains no media content descriptions if
2471// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2472TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002473 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002474 PeerConnectionInterface::RTCOfferAnswerOptions options;
2475 options.offer_to_receive_audio = 0;
2476 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477
kwibergd1fe2812016-04-27 06:47:29 -07002478 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002479
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 ASSERT_TRUE(offer != NULL);
2481 const cricket::ContentInfo* content =
2482 cricket::GetFirstAudioContent(offer->description());
2483 EXPECT_TRUE(content == NULL);
2484 content = cricket::GetFirstVideoContent(offer->description());
2485 EXPECT_TRUE(content == NULL);
2486}
2487
2488// Test that an offer contains only audio media content descriptions if
2489// kOfferToReceiveAudio constraints are set to true.
2490TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002491 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002492 PeerConnectionInterface::RTCOfferAnswerOptions options;
2493 options.offer_to_receive_audio =
2494 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2495
kwibergd1fe2812016-04-27 06:47:29 -07002496 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497
2498 const cricket::ContentInfo* content =
2499 cricket::GetFirstAudioContent(offer->description());
2500 EXPECT_TRUE(content != NULL);
2501 content = cricket::GetFirstVideoContent(offer->description());
2502 EXPECT_TRUE(content == NULL);
2503}
2504
2505// Test that an offer contains audio and video media content descriptions if
2506// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2507TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002508 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002509 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002510 PeerConnectionInterface::RTCOfferAnswerOptions options;
2511 options.offer_to_receive_audio =
2512 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2513 options.offer_to_receive_video =
2514 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2515
kwibergd1fe2812016-04-27 06:47:29 -07002516 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002517
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002518 const cricket::ContentInfo* content =
2519 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002520 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002521
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002522 content = cricket::GetFirstVideoContent(offer->description());
2523 EXPECT_TRUE(content != NULL);
2524
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002525 // Sets constraints to false and verifies that audio/video contents are
2526 // removed.
2527 options.offer_to_receive_audio = 0;
2528 options.offer_to_receive_video = 0;
2529 offer.reset(CreateOffer(options));
2530
2531 content = cricket::GetFirstAudioContent(offer->description());
2532 EXPECT_TRUE(content == NULL);
2533 content = cricket::GetFirstVideoContent(offer->description());
2534 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002535}
2536
2537// Test that an answer can not be created if the last remote description is not
2538// an offer.
2539TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002540 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002541 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542 SetLocalDescriptionWithoutError(offer);
2543 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2544 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002545 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546}
2547
2548// Test that an answer contains the correct media content descriptions when no
2549// constraints have been set.
2550TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002551 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002552 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002553 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002554 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002555 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002556 const cricket::ContentInfo* content =
2557 cricket::GetFirstAudioContent(answer->description());
2558 ASSERT_TRUE(content != NULL);
2559 EXPECT_FALSE(content->rejected);
2560
2561 content = cricket::GetFirstVideoContent(answer->description());
2562 ASSERT_TRUE(content != NULL);
2563 EXPECT_FALSE(content->rejected);
2564}
2565
2566// Test that an answer contains the correct media content descriptions when no
2567// constraints have been set and the offer only contain audio.
2568TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002569 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002570 // Create a remote offer with audio only.
2571 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002572
kwibergd1fe2812016-04-27 06:47:29 -07002573 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002574 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2575 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2576
2577 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002578 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579 const cricket::ContentInfo* content =
2580 cricket::GetFirstAudioContent(answer->description());
2581 ASSERT_TRUE(content != NULL);
2582 EXPECT_FALSE(content->rejected);
2583
2584 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2585}
2586
2587// Test that an answer contains the correct media content descriptions when no
2588// constraints have been set.
2589TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002590 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002591 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002592 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593 SetRemoteDescriptionWithoutError(offer.release());
2594 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002595 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002596 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002597 const cricket::ContentInfo* content =
2598 cricket::GetFirstAudioContent(answer->description());
2599 ASSERT_TRUE(content != NULL);
2600 EXPECT_FALSE(content->rejected);
2601
2602 content = cricket::GetFirstVideoContent(answer->description());
2603 ASSERT_TRUE(content != NULL);
2604 EXPECT_FALSE(content->rejected);
2605}
2606
2607// Test that an answer contains the correct media content descriptions when
2608// constraints have been set but no stream is sent.
2609TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002610 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002611 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002612 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002613 SetRemoteDescriptionWithoutError(offer.release());
2614
htaa2a49d92016-03-04 02:51:39 -08002615 cricket::MediaSessionOptions session_options;
2616 session_options.recv_audio = false;
2617 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002618 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002619 CreateAnswer(session_options));
2620
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002621 const cricket::ContentInfo* content =
2622 cricket::GetFirstAudioContent(answer->description());
2623 ASSERT_TRUE(content != NULL);
2624 EXPECT_TRUE(content->rejected);
2625
2626 content = cricket::GetFirstVideoContent(answer->description());
2627 ASSERT_TRUE(content != NULL);
2628 EXPECT_TRUE(content->rejected);
2629}
2630
2631// Test that an answer contains the correct media content descriptions when
2632// constraints have been set and streams are sent.
2633TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002634 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002635 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002636 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002637 SetRemoteDescriptionWithoutError(offer.release());
2638
htaa2a49d92016-03-04 02:51:39 -08002639 cricket::MediaSessionOptions options;
2640 options.recv_audio = false;
2641 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002642
2643 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002644 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002645 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002646
2647 // TODO(perkj): Should the direction be set to SEND_ONLY?
2648 const cricket::ContentInfo* content =
2649 cricket::GetFirstAudioContent(answer->description());
2650 ASSERT_TRUE(content != NULL);
2651 EXPECT_FALSE(content->rejected);
2652
2653 // TODO(perkj): Should the direction be set to SEND_ONLY?
2654 content = cricket::GetFirstVideoContent(answer->description());
2655 ASSERT_TRUE(content != NULL);
2656 EXPECT_FALSE(content->rejected);
2657}
2658
2659TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2660 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002661 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002662 PeerConnectionInterface::RTCOfferAnswerOptions options;
2663 options.offer_to_receive_audio =
2664 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2665 options.voice_activity_detection = false;
2666
kwibergd1fe2812016-04-27 06:47:29 -07002667 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002668
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002669 const cricket::ContentInfo* content =
2670 cricket::GetFirstAudioContent(offer->description());
2671 EXPECT_TRUE(content != NULL);
2672 EXPECT_TRUE(VerifyNoCNCodecs(content));
2673}
2674
2675TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2676 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002677 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002678 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002679 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002680 SetRemoteDescriptionWithoutError(offer.release());
2681
htaa2a49d92016-03-04 02:51:39 -08002682 cricket::MediaSessionOptions options;
2683 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002684 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002685 const cricket::ContentInfo* content =
2686 cricket::GetFirstAudioContent(answer->description());
2687 ASSERT_TRUE(content != NULL);
2688 EXPECT_TRUE(VerifyNoCNCodecs(content));
2689}
2690
2691// This test verifies the call setup when remote answer with audio only and
2692// later updates with video.
2693TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002694 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002695 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2696 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2697
deadbeefab9b2d12015-10-14 11:33:11 -07002698 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002699 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002700
2701 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002702 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2703
2704 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2705 // and answer;
2706 SetLocalDescriptionWithoutError(offer);
2707 SetRemoteDescriptionWithoutError(answer);
2708
2709 video_channel_ = media_engine_->GetVideoChannel(0);
2710 voice_channel_ = media_engine_->GetVoiceChannel(0);
2711
2712 ASSERT_TRUE(video_channel_ == NULL);
2713
2714 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2715 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2716 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2717
2718 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002719 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002720 CreateAndSetRemoteOfferAndLocalAnswer();
2721
2722 video_channel_ = media_engine_->GetVideoChannel(0);
2723 voice_channel_ = media_engine_->GetVoiceChannel(0);
2724
2725 ASSERT_TRUE(video_channel_ != NULL);
2726 ASSERT_TRUE(voice_channel_ != NULL);
2727
2728 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2729 ASSERT_EQ(1u, video_channel_->send_streams().size());
2730 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2731 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2732 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2733 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2734 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2735 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2736
2737 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002738 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002739 CreateAndSetRemoteOfferAndLocalAnswer();
2740
2741 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2742 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2743 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2744 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2745 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2746}
2747
2748// This test verifies the call setup when remote answer with video only and
2749// later updates with audio.
2750TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002751 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002752 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2753 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002754 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002755 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002756
2757 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002758 options.recv_audio = false;
2759 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002760 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2761 offer, options, cricket::SEC_ENABLED);
2762
2763 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2764 // and answer.
2765 SetLocalDescriptionWithoutError(offer);
2766 SetRemoteDescriptionWithoutError(answer);
2767
2768 video_channel_ = media_engine_->GetVideoChannel(0);
2769 voice_channel_ = media_engine_->GetVoiceChannel(0);
2770
2771 ASSERT_TRUE(voice_channel_ == NULL);
2772 ASSERT_TRUE(video_channel_ != NULL);
2773
2774 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2775 ASSERT_EQ(1u, video_channel_->send_streams().size());
2776 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2777
2778 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002779 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002780 CreateAndSetRemoteOfferAndLocalAnswer();
2781
2782 voice_channel_ = media_engine_->GetVoiceChannel(0);
2783 ASSERT_TRUE(voice_channel_ != NULL);
2784
2785 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2786 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2787 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2788 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2789
2790 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002791 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002792 CreateAndSetRemoteOfferAndLocalAnswer();
2793
2794 video_channel_ = media_engine_->GetVideoChannel(0);
2795 voice_channel_ = media_engine_->GetVoiceChannel(0);
2796
2797 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2798 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2799 ASSERT_EQ(1u, video_channel_->send_streams().size());
2800 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2801}
2802
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002803TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002804 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002805 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002806 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002807 VerifyCryptoParams(offer->description());
2808 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002809 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002810 VerifyCryptoParams(answer->description());
2811}
2812
2813TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002814 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002815 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002816 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002817 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002818 VerifyNoCryptoParams(offer->description(), false);
2819}
2820
2821TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002822 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002823 VerifyAnswerFromNonCryptoOffer();
2824}
2825
2826TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002827 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002828 VerifyAnswerFromCryptoOffer();
2829}
2830
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002831// This test verifies that setLocalDescription fails if
2832// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2833TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002834 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002835 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002836 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002837
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002838 std::string sdp;
2839 RemoveIceUfragPwdLines(offer.get(), &sdp);
2840 SessionDescriptionInterface* modified_offer =
2841 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002842 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002843}
2844
2845// This test verifies that setRemoteDescription fails if
2846// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2847TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002848 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002849 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002850 std::string sdp;
2851 RemoveIceUfragPwdLines(offer.get(), &sdp);
2852 SessionDescriptionInterface* modified_offer =
2853 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002854 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002855}
2856
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002857// This test verifies that setLocalDescription fails if local offer has
2858// too short ice ufrag and pwd strings.
2859TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002860 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002861 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002862 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002863 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2864 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002865 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002866 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002867 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002868
2869 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002870 offer.reset(CreateOffer());
2871 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2872 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002873}
2874
2875// This test verifies that setRemoteDescription fails if remote offer has
2876// too short ice ufrag and pwd strings.
2877TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002878 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002879 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002880 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2881 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002882 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002883 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002884 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002885
deadbeef0ed85b22016-02-23 17:24:52 -08002886 offer.reset(CreateRemoteOffer());
2887 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2888 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002889}
2890
Honghai Zhang04e91462015-12-11 14:26:22 -08002891// Test that if the remote offer indicates the peer requested ICE restart (via
2892// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2893TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002894 Init();
honghaiz503726c2015-07-31 12:37:38 -07002895
2896 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002897 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002898 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002899 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2900 0, "", "", "relay", 0, "");
2901 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2902 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002903 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2904 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002905 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2906
2907 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002908 offer.reset(CreateRemoteOffer());
2909 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002910 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2911 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2912 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002913 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2914 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002915 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2916
2917 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002918 offer.reset(CreateRemoteOffer());
2919 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002920 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2921 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2922 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002923 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2924 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002925 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2926
2927 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002928 offer.reset(CreateRemoteOffer());
2929 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2930 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002931 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2932}
2933
Honghai Zhang04e91462015-12-11 14:26:22 -08002934// Test that if the remote answer indicates the peer requested ICE restart (via
2935// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2936TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2937 Init();
2938 SessionDescriptionInterface* offer = CreateOffer();
2939 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002940
2941 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002942 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002943 answer->set_type(JsepSessionDescription::kPrAnswer);
2944 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002945 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2946 0, "", "", "relay", 0, "");
2947 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2948 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002949 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2950 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002951 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2952
2953 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002954 answer.reset(CreateRemoteAnswer(offer));
2955 answer->set_type(JsepSessionDescription::kPrAnswer);
2956 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002957 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2958 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2959 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002960 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2961 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002962 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2963
2964 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002965 answer.reset(CreateRemoteAnswer(offer));
2966 answer->set_type(JsepSessionDescription::kPrAnswer);
2967 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002968 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2969 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2970 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002971 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2972 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002973 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2974
2975 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002976 answer.reset(CreateRemoteAnswer(offer));
2977 answer->set_type(JsepSessionDescription::kPrAnswer);
2978 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2979 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002980 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2981}
2982
Donald Curtisd4f769d2015-05-28 09:48:21 -07002983// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002984// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002985TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2986 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2987
2988 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002989 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002990
2991 PeerConnectionInterface::RTCOfferAnswerOptions options;
2992 options.use_rtp_mux = true;
2993
2994 SessionDescriptionInterface* offer = CreateRemoteOffer();
2995 SetRemoteDescriptionWithoutError(offer);
2996
htaa2a49d92016-03-04 02:51:39 -08002997 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002998 SetLocalDescriptionWithoutError(answer);
2999
deadbeefcbecd352015-09-23 11:50:27 -07003000 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3001 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003002
deadbeefcbecd352015-09-23 11:50:27 -07003003 cricket::BaseChannel* voice_channel = session_->voice_channel();
3004 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003005
3006 // Checks if one of the transport channels contains a connection using a given
3007 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003008 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07003009 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07003010 session_->GetChannelTransportStats(voice_channel, &stats);
3011 for (auto& kv : stats.transport_stats) {
3012 for (auto& chan_stat : kv.second.channel_stats) {
3013 for (auto& conn_info : chan_stat.connection_infos) {
3014 if (conn_info.remote_candidate.address().port() == port) {
3015 return true;
3016 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003017 }
3018 }
3019 }
3020 return false;
3021 };
3022
3023 EXPECT_FALSE(connection_with_remote_port(5000));
3024 EXPECT_FALSE(connection_with_remote_port(5001));
3025 EXPECT_FALSE(connection_with_remote_port(6000));
3026
3027 // The way the *_WAIT checks work is they only wait if the condition fails,
3028 // which does not help in the case where state is not changing. This is
3029 // problematic in this test since we want to verify that adding a video
3030 // candidate does _not_ change state. So we interleave candidates and assume
3031 // that messages are executed in the order they were posted.
3032
3033 // First audio candidate.
3034 cricket::Candidate candidate0;
3035 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3036 candidate0.set_component(1);
3037 candidate0.set_protocol("udp");
3038 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3039 candidate0);
3040 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3041
3042 // Video candidate.
3043 cricket::Candidate candidate1;
3044 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3045 candidate1.set_component(1);
3046 candidate1.set_protocol("udp");
3047 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3048 candidate1);
3049 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3050
3051 // Second audio candidate.
3052 cricket::Candidate candidate2;
3053 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3054 candidate2.set_component(1);
3055 candidate2.set_protocol("udp");
3056 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3057 candidate2);
3058 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3059
3060 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3061 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3062
3063 // No need here for a _WAIT check since we are checking that state hasn't
3064 // changed: if this is false we would be doing waits for nothing and if this
3065 // is true then there will be no messages processed anyways.
3066 EXPECT_FALSE(connection_with_remote_port(6000));
3067}
3068
deadbeefcbecd352015-09-23 11:50:27 -07003069// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003070TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3071 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003072 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003073
3074 PeerConnectionInterface::RTCOfferAnswerOptions options;
3075 options.use_rtp_mux = true;
3076
3077 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003078 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003079
deadbeefcbecd352015-09-23 11:50:27 -07003080 EXPECT_NE(session_->voice_rtp_transport_channel(),
3081 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003082
deadbeefab9b2d12015-10-14 11:33:11 -07003083 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003084 SessionDescriptionInterface* answer =
3085 CreateRemoteAnswer(session_->local_description());
3086 SetRemoteDescriptionWithoutError(answer);
3087
deadbeefcbecd352015-09-23 11:50:27 -07003088 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3089 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003090}
3091
deadbeefcbecd352015-09-23 11:50:27 -07003092// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003093TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3094 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003095 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003096
Donald Curtis0e209b02015-03-24 09:29:54 -07003097 PeerConnectionInterface::RTCOfferAnswerOptions options;
3098 options.use_rtp_mux = true;
3099
3100 SessionDescriptionInterface* offer = CreateOffer(options);
3101 SetLocalDescriptionWithoutError(offer);
3102
deadbeefcbecd352015-09-23 11:50:27 -07003103 EXPECT_NE(session_->voice_rtp_transport_channel(),
3104 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003105
deadbeefab9b2d12015-10-14 11:33:11 -07003106 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003107
3108 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003109 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003110 CreateRemoteAnswer(session_->local_description()));
3111 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3112 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3113 JsepSessionDescription* modified_answer =
3114 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3115 modified_answer->Initialize(answer_copy, "1", "1");
3116 SetRemoteDescriptionWithoutError(modified_answer); //
3117
deadbeefcbecd352015-09-23 11:50:27 -07003118 EXPECT_NE(session_->voice_rtp_transport_channel(),
3119 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003120}
3121
3122// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3123TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3124 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003125 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003126
3127 PeerConnectionInterface::RTCOfferAnswerOptions options;
3128 options.use_rtp_mux = true;
3129
3130 SessionDescriptionInterface* offer = CreateOffer(options);
3131 SetLocalDescriptionWithoutError(offer);
3132
deadbeefcbecd352015-09-23 11:50:27 -07003133 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3134 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003135
deadbeefab9b2d12015-10-14 11:33:11 -07003136 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003137 SessionDescriptionInterface* answer =
3138 CreateRemoteAnswer(session_->local_description());
3139 SetRemoteDescriptionWithoutError(answer);
3140
deadbeefcbecd352015-09-23 11:50:27 -07003141 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3142 session_->video_rtp_transport_channel());
3143}
3144
3145// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3146// audio content in the answer.
3147TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3148 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003149 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003150
3151 PeerConnectionInterface::RTCOfferAnswerOptions options;
3152 options.use_rtp_mux = true;
3153
3154 SessionDescriptionInterface* offer = CreateOffer(options);
3155 SetLocalDescriptionWithoutError(offer);
3156
3157 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3158 session_->video_rtp_transport_channel());
3159
deadbeefab9b2d12015-10-14 11:33:11 -07003160 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003161 cricket::MediaSessionOptions recv_options;
3162 recv_options.recv_audio = false;
3163 recv_options.recv_video = true;
3164 SessionDescriptionInterface* answer =
3165 CreateRemoteAnswer(session_->local_description(), recv_options);
3166 SetRemoteDescriptionWithoutError(answer);
3167
deadbeefd59daf82015-10-14 15:02:44 -07003168 EXPECT_TRUE(nullptr == session_->voice_channel());
3169 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003170
deadbeefd59daf82015-10-14 15:02:44 -07003171 session_->Close();
3172 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3173 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3174 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3175 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003176}
3177
3178// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3179TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3180 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003181 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003182
Donald Curtis0e209b02015-03-24 09:29:54 -07003183 PeerConnectionInterface::RTCOfferAnswerOptions options;
3184 options.use_rtp_mux = true;
3185
3186 SessionDescriptionInterface* offer = CreateOffer(options);
3187 SetLocalDescriptionWithoutError(offer);
3188
deadbeefcbecd352015-09-23 11:50:27 -07003189 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3190 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003191
deadbeefab9b2d12015-10-14 11:33:11 -07003192 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003193
3194 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003195 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003196 CreateRemoteAnswer(session_->local_description()));
3197 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3198 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3199 JsepSessionDescription* modified_answer =
3200 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3201 modified_answer->Initialize(answer_copy, "1", "1");
3202 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003203
deadbeefcbecd352015-09-23 11:50:27 -07003204 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3205 session_->video_rtp_transport_channel());
3206}
3207
3208// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3209TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3210 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003211 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003212
3213 SessionDescriptionInterface* offer = CreateRemoteOffer();
3214 SetRemoteDescriptionWithoutError(offer);
3215
3216 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3217 session_->video_rtp_transport_channel());
3218
deadbeefab9b2d12015-10-14 11:33:11 -07003219 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003220 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003221 SetLocalDescriptionWithoutError(answer);
3222
3223 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3224 session_->video_rtp_transport_channel());
3225}
3226
3227// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3228TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3229 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003230 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003231
3232 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003233 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003234 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3235 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3236 JsepSessionDescription* modified_offer =
3237 new JsepSessionDescription(JsepSessionDescription::kOffer);
3238 modified_offer->Initialize(offer_copy, "1", "1");
3239
3240 // Expect an error when applying the remote description
3241 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3242 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003243}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003244
Peter Thatcher4eddf182015-04-30 10:55:59 -07003245// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003246TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3247 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003248 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003249
Donald Curtis0e209b02015-03-24 09:29:54 -07003250 PeerConnectionInterface::RTCOfferAnswerOptions options;
3251 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003252
Donald Curtis0e209b02015-03-24 09:29:54 -07003253 SessionDescriptionInterface* offer = CreateOffer(options);
3254 SetLocalDescriptionWithoutError(offer);
3255
deadbeefcbecd352015-09-23 11:50:27 -07003256 EXPECT_NE(session_->voice_rtp_transport_channel(),
3257 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003258
deadbeefab9b2d12015-10-14 11:33:11 -07003259 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003260 SessionDescriptionInterface* answer =
3261 CreateRemoteAnswer(session_->local_description());
3262 SetRemoteDescriptionWithoutError(answer);
3263
3264 // This should lead to an audio-only call but isn't implemented
3265 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003266 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3267 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003268}
3269
deadbeefcbecd352015-09-23 11:50:27 -07003270// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003271TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3272 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003273 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003274 PeerConnectionInterface::RTCOfferAnswerOptions options;
3275 options.use_rtp_mux = true;
3276
3277 SessionDescriptionInterface* offer = CreateOffer(options);
3278 SetLocalDescriptionWithoutError(offer);
3279
deadbeefcbecd352015-09-23 11:50:27 -07003280 EXPECT_NE(session_->voice_rtp_transport_channel(),
3281 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003282
deadbeefab9b2d12015-10-14 11:33:11 -07003283 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003284
3285 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003286 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003287 CreateRemoteAnswer(session_->local_description()));
3288 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3289 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3290 JsepSessionDescription* modified_answer =
3291 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3292 modified_answer->Initialize(answer_copy, "1", "1");
3293 SetRemoteDescriptionWithoutError(modified_answer); //
3294
deadbeefcbecd352015-09-23 11:50:27 -07003295 EXPECT_NE(session_->voice_rtp_transport_channel(),
3296 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003297}
3298
Peter Thatcher4eddf182015-04-30 10:55:59 -07003299// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3300TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3301 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003302 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003303
3304 PeerConnectionInterface::RTCOfferAnswerOptions options;
3305 options.use_rtp_mux = true;
3306
3307 SessionDescriptionInterface* offer = CreateOffer(options);
3308 SetRemoteDescriptionWithoutError(offer);
3309
deadbeefcbecd352015-09-23 11:50:27 -07003310 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3311 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003312}
3313
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003314TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3315 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003316 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003317
3318 PeerConnectionInterface::RTCOfferAnswerOptions options;
3319 SessionDescriptionInterface* offer = CreateOffer(options);
3320 SetLocalDescriptionWithoutError(offer);
3321
deadbeefcbecd352015-09-23 11:50:27 -07003322 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3323 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003324
deadbeefab9b2d12015-10-14 11:33:11 -07003325 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003326 SessionDescriptionInterface* answer =
3327 CreateRemoteAnswer(session_->local_description());
3328 SetRemoteDescriptionWithoutError(answer);
3329
deadbeefcbecd352015-09-23 11:50:27 -07003330 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3331 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003332}
3333
3334TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3335 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003336 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003337
3338 PeerConnectionInterface::RTCOfferAnswerOptions options;
3339 SessionDescriptionInterface* offer = CreateOffer(options);
3340 SetLocalDescriptionWithoutError(offer);
3341
deadbeefcbecd352015-09-23 11:50:27 -07003342 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3343 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003344
deadbeefab9b2d12015-10-14 11:33:11 -07003345 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003346 SessionDescriptionInterface* answer =
3347 CreateRemoteAnswer(session_->local_description());
3348 SetRemoteDescriptionWithoutError(answer);
3349
deadbeefcbecd352015-09-23 11:50:27 -07003350 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3351 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003352}
3353
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003354// This test verifies that SetLocalDescription and SetRemoteDescription fails
3355// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3356TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003357 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003358 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003359
3360 PeerConnectionInterface::RTCOfferAnswerOptions options;
3361 options.use_rtp_mux = true;
3362
3363 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003364 std::string offer_str;
3365 offer->ToString(&offer_str);
3366 // Disable rtcp-mux
3367 const std::string rtcp_mux = "rtcp-mux";
3368 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003369 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003370 xrtcp_mux.c_str(), xrtcp_mux.length(),
3371 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003372 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003373 new JsepSessionDescription(JsepSessionDescription::kOffer);
3374 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003375 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003376 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003377 new JsepSessionDescription(JsepSessionDescription::kOffer);
3378 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003379 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003380 // Trying unmodified SDP.
3381 SetLocalDescriptionWithoutError(offer);
3382}
3383
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003384TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003385 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003386 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003387 CreateAndSetRemoteOfferAndLocalAnswer();
3388 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3389 ASSERT_TRUE(channel != NULL);
3390 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003391 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003392 double volume;
3393 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3394 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003395 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003396 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3397 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003398 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003399 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3400 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003401}
3402
skvlade0d46372016-04-07 22:59:22 -07003403TEST_F(WebRtcSessionTest, SetAudioMaxSendBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003404 Init();
3405 SendAudioVideoStream1();
3406 CreateAndSetRemoteOfferAndLocalAnswer();
3407 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3408 ASSERT_TRUE(channel != NULL);
3409 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
skvlade0d46372016-04-07 22:59:22 -07003410 EXPECT_EQ(-1, channel->max_bps());
skvladdc1c62c2016-03-16 19:07:43 -07003411 webrtc::RtpParameters params = session_->GetAudioRtpParameters(send_ssrc);
skvlade0d46372016-04-07 22:59:22 -07003412 EXPECT_EQ(1, params.encodings.size());
3413 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3414 params.encodings[0].max_bitrate_bps = 1000;
3415 EXPECT_TRUE(session_->SetAudioRtpParameters(send_ssrc, params));
skvladdc1c62c2016-03-16 19:07:43 -07003416
skvlade0d46372016-04-07 22:59:22 -07003417 // Read back the parameters and verify they have been changed.
3418 params = session_->GetAudioRtpParameters(send_ssrc);
3419 EXPECT_EQ(1, params.encodings.size());
3420 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3421
3422 // Verify that the audio channel received the new parameters.
3423 params = channel->GetRtpParameters(send_ssrc);
3424 EXPECT_EQ(1, params.encodings.size());
3425 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3426
3427 // Verify that the global bitrate limit has not been changed.
3428 EXPECT_EQ(-1, channel->max_bps());
skvladdc1c62c2016-03-16 19:07:43 -07003429}
3430
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003431TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003432 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003433 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003434 CreateAndSetRemoteOfferAndLocalAnswer();
3435 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3436 ASSERT_TRUE(channel != NULL);
3437 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003438 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003439 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3440
3441 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003442 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003443
kwibergd1fe2812016-04-27 06:47:29 -07003444 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003445 session_->SetAudioSend(send_ssrc, false, options, source.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003446 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003447 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003448 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003449
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003450 // This will trigger SetSink(nullptr) to the |source|.
3451 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003452 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003453 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003454 EXPECT_TRUE(source->sink() == nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003455}
3456
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003457TEST_F(WebRtcSessionTest, AudioSourceForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003458 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003459 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003460 CreateAndSetRemoteOfferAndLocalAnswer();
3461 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3462 ASSERT_TRUE(channel != NULL);
3463 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003464 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003465
kwibergd1fe2812016-04-27 06:47:29 -07003466 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003467 cricket::AudioOptions options;
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003468 session_->SetAudioSend(send_ssrc, true, options, source.get());
3469 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003470
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003471 // Delete the |source| and it will trigger OnClose() to the sink, and this
3472 // will invalidate the |source_| pointer in the sink and prevent getting a
3473 // SetSink(nullptr) callback afterwards.
3474 source.reset();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003475
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003476 // This will trigger SetSink(nullptr) if no OnClose() callback.
3477 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003478}
3479
3480TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003481 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003482 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003483 CreateAndSetRemoteOfferAndLocalAnswer();
3484 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3485 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003486 ASSERT_LT(0u, channel->sinks().size());
3487 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003488 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003489 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490 cricket::FakeVideoRenderer renderer;
3491 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003492 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003493 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003494 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495}
3496
skvladdc1c62c2016-03-16 19:07:43 -07003497TEST_F(WebRtcSessionTest, SetVideoMaxSendBitrate) {
3498 Init();
3499 SendAudioVideoStream1();
3500 CreateAndSetRemoteOfferAndLocalAnswer();
3501 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3502 ASSERT_TRUE(channel != NULL);
3503 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
3504 EXPECT_EQ(-1, channel->max_bps());
3505 webrtc::RtpParameters params = session_->GetVideoRtpParameters(send_ssrc);
3506 EXPECT_EQ(1, params.encodings.size());
3507 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3508 params.encodings[0].max_bitrate_bps = 1000;
3509 EXPECT_TRUE(session_->SetVideoRtpParameters(send_ssrc, params));
3510
3511 // Read back the parameters and verify they have been changed.
3512 params = session_->GetVideoRtpParameters(send_ssrc);
3513 EXPECT_EQ(1, params.encodings.size());
3514 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3515
3516 // Verify that the video channel received the new parameters.
3517 params = channel->GetRtpParameters(send_ssrc);
3518 EXPECT_EQ(1, params.encodings.size());
3519 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3520
3521 // Verify that the global bitrate limit has not been changed.
3522 EXPECT_EQ(-1, channel->max_bps());
3523}
3524
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003525TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003526 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003527 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003528 CreateAndSetRemoteOfferAndLocalAnswer();
3529 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3530 ASSERT_TRUE(channel != NULL);
3531 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003532 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003533 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3534 cricket::VideoOptions* options = NULL;
3535 session_->SetVideoSend(send_ssrc, false, options);
3536 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3537 session_->SetVideoSend(send_ssrc, true, options);
3538 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3539}
3540
3541TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3542 TestCanInsertDtmf(false);
3543}
3544
3545TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3546 TestCanInsertDtmf(true);
3547}
3548
3549TEST_F(WebRtcSessionTest, InsertDtmf) {
3550 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003551 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003552 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003553 CreateAndSetRemoteOfferAndLocalAnswer();
3554 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3555 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3556
3557 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003558 const int expected_duration = 90;
3559 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3560 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3561 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3562
3563 // Verify
3564 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003565 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003566 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003567 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003568 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003569 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003570 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003571 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003572}
3573
deadbeefd59daf82015-10-14 15:02:44 -07003574// This test verifies the |initial_offerer| flag when session initiates the
3575// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003576TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003577 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003578 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003579 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3581 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003582 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003583 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003584 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003585}
3586
deadbeefd59daf82015-10-14 15:02:44 -07003587// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003588TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003589 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003590 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003591 SessionDescriptionInterface* offer = CreateRemoteOffer();
3592 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003593 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003594
deadbeefd59daf82015-10-14 15:02:44 -07003595 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003596 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003597 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003598}
3599
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003600// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3601TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003602 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003603 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003604 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003605 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003606 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003607 CreateRemoteAnswer(session_->local_description()));
3608
3609 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3610 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003611 JsepSessionDescription* modified_answer =
3612 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003613
3614 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3615 answer->session_id(),
3616 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003617 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003618
wu@webrtc.org4e393072014-04-07 17:04:35 +00003619 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003620 std::string sdp;
3621 EXPECT_TRUE(answer->ToString(&sdp));
3622 const std::string kAudioMid = "a=mid:audio";
3623 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003624 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003625 kAudioMidReplaceStr.c_str(),
3626 kAudioMidReplaceStr.length(),
3627 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003628 SessionDescriptionInterface* modified_answer1 =
3629 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003630 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003631
wu@webrtc.org4e393072014-04-07 17:04:35 +00003632 // Different media types.
3633 EXPECT_TRUE(answer->ToString(&sdp));
3634 const std::string kAudioMline = "m=audio";
3635 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003636 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003637 kAudioMlineReplaceStr.c_str(),
3638 kAudioMlineReplaceStr.length(),
3639 &sdp);
3640 SessionDescriptionInterface* modified_answer2 =
3641 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3642 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3643
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003644 SetRemoteDescriptionWithoutError(answer.release());
3645}
3646
3647// Verifying remote offer and local answer have matching m-lines as per
3648// RFC 3264.
3649TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003650 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003651 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003652 SessionDescriptionInterface* offer = CreateRemoteOffer();
3653 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003654 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003655
3656 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3657 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003658 JsepSessionDescription* modified_answer =
3659 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003660
3661 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3662 answer->session_id(),
3663 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003664 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003665 SetLocalDescriptionWithoutError(answer);
3666}
3667
3668// This test verifies that WebRtcSession does not start candidate allocation
3669// before SetLocalDescription is called.
3670TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003671 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003672 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003673 SessionDescriptionInterface* offer = CreateRemoteOffer();
3674 cricket::Candidate candidate;
3675 candidate.set_component(1);
3676 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3677 candidate);
3678 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3679 cricket::Candidate candidate1;
3680 candidate1.set_component(1);
3681 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3682 candidate1);
3683 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3684 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003685 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3686 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003687
3688 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003689 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003690 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3691 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3692
htaa2a49d92016-03-04 02:51:39 -08003693 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003694 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003695 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3696}
3697
3698// This test verifies that crypto parameter is updated in local session
3699// description as per security policy set in MediaSessionDescriptionFactory.
3700TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003701 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003702 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003703 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003704
3705 // Making sure SetLocalDescription correctly sets crypto value in
3706 // SessionDescription object after de-serialization of sdp string. The value
3707 // will be set as per MediaSessionDescriptionFactory.
3708 std::string offer_str;
3709 offer->ToString(&offer_str);
3710 SessionDescriptionInterface* jsep_offer_str =
3711 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3712 SetLocalDescriptionWithoutError(jsep_offer_str);
3713 EXPECT_TRUE(session_->voice_channel()->secure_required());
3714 EXPECT_TRUE(session_->video_channel()->secure_required());
3715}
3716
3717// This test verifies the crypto parameter when security is disabled.
3718TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003719 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003720 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003721 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003722 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003723
3724 // Making sure SetLocalDescription correctly sets crypto value in
3725 // SessionDescription object after de-serialization of sdp string. The value
3726 // will be set as per MediaSessionDescriptionFactory.
3727 std::string offer_str;
3728 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003729 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003730 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3731 SetLocalDescriptionWithoutError(jsep_offer_str);
3732 EXPECT_FALSE(session_->voice_channel()->secure_required());
3733 EXPECT_FALSE(session_->video_channel()->secure_required());
3734}
3735
3736// This test verifies that an answer contains new ufrag and password if an offer
3737// with new ufrag and password is received.
3738TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003739 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003740 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003741 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003742 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003743 SetRemoteDescriptionWithoutError(offer.release());
3744
deadbeefab9b2d12015-10-14 11:33:11 -07003745 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003746 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003747 SetLocalDescriptionWithoutError(answer.release());
3748
3749 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003750 for (const cricket::ContentInfo& content :
3751 session_->local_description()->description()->contents()) {
3752 options.transport_options[content.name].ice_restart = true;
3753 }
kwibergd1fe2812016-04-27 06:47:29 -07003754 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003755 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003756 SetRemoteDescriptionWithoutError(updated_offer1.release());
3757
kwibergd1fe2812016-04-27 06:47:29 -07003758 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003759
deadbeef0ed85b22016-02-23 17:24:52 -08003760 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3761 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003762
deadbeef0ed85b22016-02-23 17:24:52 -08003763 // Even a second answer (created before the description is set) should have
3764 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003765 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003766
3767 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3768 session_->local_description()->description()));
3769
3770 SetLocalDescriptionWithoutError(updated_answer2.release());
3771}
3772
3773// This test verifies that an answer contains new ufrag and password if an offer
3774// that changes either the ufrag or password (but not both) is received.
3775// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3776// a=ice-pwd attributes compared to the previous SDP from the peer, it
3777// indicates that ICE is restarting for this media stream."
3778TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3779 Init();
3780 cricket::MediaSessionOptions options;
3781 options.recv_audio = true;
3782 options.recv_video = true;
3783 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003784 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003785 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3786 SetRemoteDescriptionWithoutError(offer.release());
3787
3788 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003789 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003790 SetLocalDescriptionWithoutError(answer.release());
3791
3792 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003793 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003794 CreateRemoteOffer(options, session_->remote_description()));
3795 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3796 "original_password12345");
3797 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3798
kwibergd1fe2812016-04-27 06:47:29 -07003799 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003800 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3801 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003802 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003803
3804 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003805 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003806 CreateRemoteOffer(options, session_->remote_description()));
3807 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3808 "modified_password12345");
3809 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3810
kwibergd1fe2812016-04-27 06:47:29 -07003811 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003812 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3813 session_->local_description()->description()));
3814 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003815}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003816
wu@webrtc.org91053e72013-08-10 07:18:04 +00003817// This test verifies that an answer contains old ufrag and password if an offer
3818// with old ufrag and password is received.
3819TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003820 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003821 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003822 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003823 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003824 SetRemoteDescriptionWithoutError(offer.release());
3825
deadbeefab9b2d12015-10-14 11:33:11 -07003826 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003827 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003828 SetLocalDescriptionWithoutError(answer.release());
3829
3830 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003831 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003832 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003833 SetRemoteDescriptionWithoutError(updated_offer2.release());
3834
kwibergd1fe2812016-04-27 06:47:29 -07003835 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003836
deadbeef0ed85b22016-02-23 17:24:52 -08003837 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3838 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003839
3840 SetLocalDescriptionWithoutError(updated_answer2.release());
3841}
3842
deadbeef0ed85b22016-02-23 17:24:52 -08003843// This test verifies that if an offer does an ICE restart on some, but not all
3844// media sections, the answer will change the ufrag/password in the correct
3845// media sections.
3846TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3847 Init();
3848 cricket::MediaSessionOptions options;
3849 options.recv_video = true;
3850 options.recv_audio = true;
3851 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003852 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003853
3854 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3855 "aaaaaaaaaaaaaaaaaaaaaa");
3856 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3857 "bbbbbbbbbbbbbbbbbbbbbb");
3858 SetRemoteDescriptionWithoutError(offer.release());
3859
3860 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003861 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003862 SetLocalDescriptionWithoutError(answer.release());
3863
3864 // Receive an offer with new ufrag and password, but only for the video media
3865 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003866 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003867 CreateRemoteOffer(options, session_->remote_description()));
3868 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3869 "cccccccccccccccccccccc");
3870 SetRemoteDescriptionWithoutError(updated_offer.release());
3871
kwibergd1fe2812016-04-27 06:47:29 -07003872 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003873
3874 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3875 session_->local_description()->description(),
3876 cricket::MEDIA_TYPE_AUDIO));
3877
3878 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3879 session_->local_description()->description(),
3880 cricket::MEDIA_TYPE_VIDEO));
3881
3882 SetLocalDescriptionWithoutError(updated_answer.release());
3883}
3884
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003885TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003886 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003887 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003888 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003889 const std::string session_id_orig = offer->session_id();
3890 const std::string session_version_orig = offer->session_version();
3891 SetLocalDescriptionWithoutError(offer);
3892
3893 video_channel_ = media_engine_->GetVideoChannel(0);
3894 video_channel_->set_fail_set_send_codecs(true);
3895
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003896 SessionDescriptionInterface* answer =
3897 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003898 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003899
3900 // Test that after a content error, setting any description will
3901 // result in an error.
3902 video_channel_->set_fail_set_send_codecs(false);
3903 answer = CreateRemoteAnswer(session_->local_description());
3904 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3905 offer = CreateRemoteOffer();
3906 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003907}
3908
3909// Runs the loopback call test with BUNDLE and STUN disabled.
3910TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3911 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003912 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003913 cricket::PORTALLOCATOR_DISABLE_STUN |
3914 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003915 TestLoopbackCall();
3916}
3917
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003918TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003919 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003920 cricket::PORTALLOCATOR_DISABLE_STUN |
3921 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3922 cricket::PORTALLOCATOR_DISABLE_RELAY);
3923
3924 // best connection is IPv6 since it has higher network preference.
3925 LoopbackNetworkConfiguration config;
3926 config.test_ipv6_network_ = true;
3927 config.best_connection_after_initial_ice_converged_ =
3928 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3929
3930 TestLoopbackCall(config);
3931}
3932
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003933// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003934TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003935 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3936 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003937 TestLoopbackCall();
3938}
3939
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003940TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003941 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003942 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003943 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003944 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003945 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3946}
3947
Henrik Boström87713d02015-08-25 09:53:21 +02003948TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003949 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003950
htaa2a49d92016-03-04 02:51:39 -08003951 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003952 options_.disable_sctp_data_channels = false;
3953
Henrik Boström87713d02015-08-25 09:53:21 +02003954 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003955
3956 SetLocalDescriptionWithDataChannel();
3957 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3958}
3959
Henrik Boström87713d02015-08-25 09:53:21 +02003960TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003961 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003962
Henrik Boström87713d02015-08-25 09:53:21 +02003963 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003964
kwibergd1fe2812016-04-27 06:47:29 -07003965 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003966 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003967 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3968}
3969
Henrik Boström87713d02015-08-25 09:53:21 +02003970TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003971 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003972 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003973 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003974
3975 // Create remote offer with SCTP.
3976 cricket::MediaSessionOptions options;
3977 options.data_channel_type = cricket::DCT_SCTP;
3978 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003979 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003980 SetRemoteDescriptionWithoutError(offer);
3981
3982 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003983 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003984 EXPECT_TRUE(answer != NULL);
3985 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3986 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003987}
3988
Henrik Boström87713d02015-08-25 09:53:21 +02003989TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003990 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003991 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003992
3993 SetLocalDescriptionWithDataChannel();
3994 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3995}
3996
Henrik Boström87713d02015-08-25 09:53:21 +02003997TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003998 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003999
Henrik Boström87713d02015-08-25 09:53:21 +02004000 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004001
4002 SetLocalDescriptionWithDataChannel();
4003 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4004}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004005
Henrik Boström87713d02015-08-25 09:53:21 +02004006TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004007 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00004008 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02004009 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004010
4011 SetLocalDescriptionWithDataChannel();
4012 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
4013}
4014
Henrik Boström87713d02015-08-25 09:53:21 +02004015TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004016 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004017 const int new_send_port = 9998;
4018 const int new_recv_port = 7775;
4019
Henrik Boström87713d02015-08-25 09:53:21 +02004020 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004021 SetFactoryDtlsSrtp();
4022
4023 // By default, don't actually add the codecs to desc_factory_; they don't
4024 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
4025 // let the session description get parsed. That'll get the proper codecs
4026 // into the stream.
4027 cricket::MediaSessionOptions options;
4028 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
4029 "stream1", new_send_port, options);
4030
4031 // SetRemoteDescription will take the ownership of the offer.
4032 SetRemoteDescriptionWithoutError(offer);
4033
htaa2a49d92016-03-04 02:51:39 -08004034 SessionDescriptionInterface* answer =
4035 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004036 ASSERT_TRUE(answer != NULL);
4037
4038 // Now set the local description, which'll take ownership of the answer.
4039 SetLocalDescriptionWithoutError(answer);
4040
4041 // TEST PLAN: Set the port number to something new, set it in the SDP,
4042 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004043 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07004044 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004045
4046 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
4047 int portnum = -1;
4048 ASSERT_TRUE(ch != NULL);
4049 ASSERT_EQ(1UL, ch->send_codecs().size());
4050 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004051 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004052 ch->send_codecs()[0].name.c_str()));
4053 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
4054 &portnum));
4055 EXPECT_EQ(new_send_port, portnum);
4056
4057 ASSERT_EQ(1UL, ch->recv_codecs().size());
4058 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004059 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004060 ch->recv_codecs()[0].name.c_str()));
4061 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
4062 &portnum));
4063 EXPECT_EQ(new_recv_port, portnum);
4064}
4065
deadbeefab9b2d12015-10-14 11:33:11 -07004066// Verifies that when a session's DataChannel receives an OPEN message,
4067// WebRtcSession signals the DataChannel creation request with the expected
4068// config.
4069TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
4070 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4071
4072 InitWithDtls(GetParam());
4073
4074 SetLocalDescriptionWithDataChannel();
4075 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4076
4077 webrtc::DataChannelInit config;
4078 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004079 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004080 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4081 cricket::ReceiveDataParams params;
4082 params.ssrc = config.id;
4083 params.type = cricket::DMT_CONTROL;
4084
4085 cricket::DataChannel* data_channel = session_->data_channel();
4086 data_channel->SignalDataReceived(data_channel, params, payload);
4087
4088 EXPECT_EQ("a", last_data_channel_label_);
4089 EXPECT_EQ(config.id, last_data_channel_config_.id);
4090 EXPECT_FALSE(last_data_channel_config_.negotiated);
4091 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4092 last_data_channel_config_.open_handshake_role);
4093}
4094
4095TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004096 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
4097 FakeDtlsIdentityStore::GenerateCertificate();
4098
htaa2a49d92016-03-04 02:51:39 -08004099 configuration_.certificates.push_back(certificate);
4100 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004101 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4102
4103 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4104}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004105
Henrik Boström87713d02015-08-25 09:53:21 +02004106// Verifies that CreateOffer succeeds when CreateOffer is called before async
4107// identity generation is finished (even if a certificate is provided this is
4108// an async op).
4109TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4110 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4111 InitWithDtls(GetParam());
4112
Henrik Boströmd8281982015-08-27 10:12:24 +02004113 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004114 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004115 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004116
wu@webrtc.org91053e72013-08-10 07:18:04 +00004117 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004118 VerifyNoCryptoParams(offer->description(), true);
4119 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004120}
4121
4122// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004123// identity generation is finished (even if a certificate is provided this is
4124// an async op).
4125TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004126 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004127 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004128 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004129
4130 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004131 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004132 std::unique_ptr<JsepSessionDescription> offer(
4133 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004134 ASSERT_TRUE(offer.get() != NULL);
4135 SetRemoteDescriptionWithoutError(offer.release());
4136
kwibergd1fe2812016-04-27 06:47:29 -07004137 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004138 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004139 VerifyNoCryptoParams(answer->description(), true);
4140 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004141}
4142
4143// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004144// identity generation is finished (even if a certificate is provided this is
4145// an async op).
4146TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004147 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004148 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004149
Henrik Boströmd8281982015-08-27 10:12:24 +02004150 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004151
kwibergd1fe2812016-04-27 06:47:29 -07004152 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004153 EXPECT_TRUE(offer != NULL);
4154}
4155
4156// Verifies that CreateOffer fails when CreateOffer is called after async
4157// identity generation fails.
4158TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004159 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004160 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004161
Henrik Boströmd8281982015-08-27 10:12:24 +02004162 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004163
kwibergd1fe2812016-04-27 06:47:29 -07004164 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004165 EXPECT_TRUE(offer == NULL);
4166}
4167
4168// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4169// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004170TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004171 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004172 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004173 VerifyMultipleAsyncCreateDescription(GetParam(),
4174 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004175}
4176
4177// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4178// before async identity generation fails.
4179TEST_F(WebRtcSessionTest,
4180 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004181 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004182 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4183 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004184}
4185
4186// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4187// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004188TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004189 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004190 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004191 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004192 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004193}
4194
4195// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4196// before async identity generation fails.
4197TEST_F(WebRtcSessionTest,
4198 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004199 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004200 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4201 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004202}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004203
4204// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4205// offer has no SDES crypto but only DTLS fingerprint.
4206TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4207 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004208 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004209 // Create a remote offer with secured transport disabled.
4210 cricket::MediaSessionOptions options;
4211 JsepSessionDescription* offer(CreateRemoteOffer(
4212 options, cricket::SEC_DISABLED));
4213 // Adds a DTLS fingerprint to the remote offer.
4214 cricket::SessionDescription* sdp = offer->description();
4215 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4216 ASSERT_TRUE(audio != NULL);
4217 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4218 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004219 rtc::SSLFingerprint::CreateFromRfc4572(
4220 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004221 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004222 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004223}
4224
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004225TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004226 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004227 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004228 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004229 SessionDescriptionInterface* offer = CreateOffer();
4230
4231 SetLocalDescriptionWithoutError(offer);
4232
4233 voice_channel_ = media_engine_->GetVoiceChannel(0);
4234
4235 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004236 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004237 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004238}
4239
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004240// Tests that we can renegotiate new media content with ICE candidates in the
4241// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004242TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004243 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004244 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004245 SetFactoryDtlsSrtp();
4246
deadbeefab9b2d12015-10-14 11:33:11 -07004247 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004248 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004249 SetLocalDescriptionWithoutError(offer);
4250
4251 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4252 SetRemoteDescriptionWithoutError(answer);
4253
4254 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004255 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004256 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4257
4258 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004259 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004260 candidate1.set_component(1);
4261 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4262 candidate1);
4263 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4264 SetRemoteDescriptionWithoutError(offer);
4265
htaa2a49d92016-03-04 02:51:39 -08004266 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004267 SetLocalDescriptionWithoutError(answer);
4268}
4269
4270// Tests that we can renegotiate new media content with ICE candidates separated
4271// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004272TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004273 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004274 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004275 SetFactoryDtlsSrtp();
4276
deadbeefab9b2d12015-10-14 11:33:11 -07004277 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004278 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004279 SetLocalDescriptionWithoutError(offer);
4280
4281 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4282 SetRemoteDescriptionWithoutError(answer);
4283
4284 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004285 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004286 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4287 SetRemoteDescriptionWithoutError(offer);
4288
4289 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004290 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004291 candidate1.set_component(1);
4292 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4293 candidate1);
4294 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4295
htaa2a49d92016-03-04 02:51:39 -08004296 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004297 SetLocalDescriptionWithoutError(answer);
4298}
honghaiz7f777492016-02-02 21:54:01 -08004299
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004300// Tests that RTX codec is removed from the answer when it isn't supported
4301// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004302TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004303 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004304 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004305 std::string offer_sdp(kSdpWithRtx);
4306
4307 SessionDescriptionInterface* offer =
4308 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4309 EXPECT_TRUE(offer->ToString(&offer_sdp));
4310
4311 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004312 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004313 SetRemoteDescriptionWithoutError(offer);
4314
htaa2a49d92016-03-04 02:51:39 -08004315 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004316 // Answer SDP does not contain the RTX codec.
4317 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004318 SetLocalDescriptionWithoutError(answer);
4319}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004320
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004321// This verifies that the voice channel after bundle has both options from video
4322// and voice channels.
4323TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4324 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004325 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004326
4327 PeerConnectionInterface::RTCOfferAnswerOptions options;
4328 options.use_rtp_mux = true;
4329
4330 SessionDescriptionInterface* offer = CreateOffer(options);
4331 SetLocalDescriptionWithoutError(offer);
4332
4333 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4334 rtc::Socket::Option::OPT_SNDBUF, 4000);
4335
4336 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4337 rtc::Socket::Option::OPT_RCVBUF, 8000);
4338
4339 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004340 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004341 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4342 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004343 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004344 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4345
deadbeefcbecd352015-09-23 11:50:27 -07004346 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004347 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4348 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004349 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004350 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4351
deadbeefcbecd352015-09-23 11:50:27 -07004352 EXPECT_NE(session_->voice_rtp_transport_channel(),
4353 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004354
deadbeefab9b2d12015-10-14 11:33:11 -07004355 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004356 SessionDescriptionInterface* answer =
4357 CreateRemoteAnswer(session_->local_description());
4358 SetRemoteDescriptionWithoutError(answer);
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_SNDBUF, &option_val));
4362 EXPECT_EQ(4000, option_val);
4363
deadbeefcbecd352015-09-23 11:50:27 -07004364 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004365 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4366 EXPECT_EQ(8000, option_val);
4367}
4368
tommi0f620f42015-07-09 03:25:02 -07004369// Test creating a session, request multiple offers, destroy the session
4370// and make sure we got success/failure callbacks for all of the requests.
4371// Background: crbug.com/507307
4372TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4373 Init();
4374
4375 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4376 PeerConnectionInterface::RTCOfferAnswerOptions options;
4377 options.offer_to_receive_audio =
4378 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004379 cricket::MediaSessionOptions session_options;
4380 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004381
4382 for (auto& o : observers) {
4383 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004384 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004385 }
4386
4387 session_.reset();
4388
tommi0f620f42015-07-09 03:25:02 -07004389 for (auto& o : observers) {
4390 // We expect to have received a notification now even if the session was
4391 // terminated. The offer creation may or may not have succeeded, but we
4392 // must have received a notification which, so the only invalid state
4393 // is kInit.
4394 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4395 }
4396}
4397
stefanc1aeaf02015-10-15 07:26:07 -07004398TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4399 TestPacketOptions();
4400}
4401
deadbeef057ecf02016-01-20 14:30:43 -08004402// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4403// is destroyed.
4404TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4405 Init();
4406 session_.reset();
4407 EXPECT_TRUE(session_destroyed_);
4408}
4409
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004410// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4411// currently fails because upon disconnection and reconnection OnIceComplete is
4412// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004413
deadbeefcbecd352015-09-23 11:50:27 -07004414INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4415 WebRtcSessionTest,
4416 testing::Values(ALREADY_GENERATED,
4417 DTLS_IDENTITY_STORE));