blob: b90daee5107c3e34519119943a816b225b300e4c [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 Boströmd79599d2016-06-01 13:58:50 +020022#include "webrtc/api/test/fakertccertificategenerator.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010023#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;
jbauchac8869e2015-07-03 01:36:14 -070064using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070066using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067using webrtc::JsepIceCandidate;
68using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000069using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070using webrtc::PeerConnectionInterface;
71using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070072using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000074using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000075using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000076using webrtc::kCreateChannelFailed;
77using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000079using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000080using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000081using webrtc::kSdpWithoutDtlsFingerprint;
82using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000084using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000085using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000087typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
88
wu@webrtc.org364f2042013-11-20 21:49:41 +000089static const int kClientAddrPort = 0;
90static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000091static const char kClientIPv6AddrHost1[] =
92 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000093static const char kClientAddrHost2[] = "22.22.22.22";
94static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000095static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
96static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000097static const char kTurnUsername[] = "test";
98static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099
100static const char kSessionVersion[] = "1";
101
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102// Media index of candidates belonging to the first media content.
103static const int kMediaContentIndex0 = 0;
104static const char kMediaContentName0[] = "audio";
105
106// Media index of candidates belonging to the second media content.
107static const int kMediaContentIndex1 = 1;
108static const char kMediaContentName1[] = "video";
109
110static const int kIceCandidatesTimeout = 10000;
deadbeeff5f03e82016-06-06 11:16:06 -0700111// STUN timeout with all retransmissions is a total of 9500ms.
112static const int kStunTimeout = 9500;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000114static const char kFakeDtlsFingerprint[] =
115 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
116 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
117
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000118static const char kTooLongIceUfragPwd[] =
119 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
120 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
121 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
122 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
123
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000124static const char kSdpWithRtx[] =
125 "v=0\r\n"
126 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
127 "s=-\r\n"
128 "t=0 0\r\n"
129 "a=msid-semantic: WMS stream1\r\n"
130 "m=video 9 RTP/SAVPF 0 96\r\n"
131 "c=IN IP4 0.0.0.0\r\n"
132 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
133 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
134 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
135 "a=mid:video\r\n"
136 "a=sendrecv\r\n"
137 "a=rtcp-mux\r\n"
138 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
139 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
140 "a=rtpmap:0 fake_video_codec/90000\r\n"
141 "a=rtpmap:96 rtx/90000\r\n"
142 "a=fmtp:96 apt=0\r\n";
143
deadbeefab9b2d12015-10-14 11:33:11 -0700144static const char kStream1[] = "stream1";
145static const char kVideoTrack1[] = "video1";
146static const char kAudioTrack1[] = "audio1";
147
148static const char kStream2[] = "stream2";
149static const char kVideoTrack2[] = "video2";
150static const char kAudioTrack2[] = "audio2";
151
Henrik Boström87713d02015-08-25 09:53:21 +0200152enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
153
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154class MockIceObserver : public webrtc::IceObserver {
155 public:
156 MockIceObserver()
157 : oncandidatesready_(false),
158 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
159 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
160 }
161
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200162 virtual ~MockIceObserver() = default;
163
perkjdfb769d2016-02-09 03:09:43 -0800164 void OnIceConnectionChange(
165 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166 ice_connection_state_ = new_state;
skvlad6c87a672016-05-17 17:49:52 -0700167 ice_connection_state_history_.push_back(new_state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 }
perkjdfb769d2016-02-09 03:09:43 -0800169 void OnIceGatheringChange(
170 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 // We can never transition back to "new".
172 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
173 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800174 oncandidatesready_ =
175 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176 }
177
178 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800179 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000180 switch (candidate->sdp_mline_index()) {
181 case kMediaContentIndex0:
182 mline_0_candidates_.push_back(candidate->candidate());
183 break;
184 case kMediaContentIndex1:
185 mline_1_candidates_.push_back(candidate->candidate());
186 break;
187 default:
188 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000190
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 // The ICE gathering state should always be Gathering when a candidate is
192 // received (or possibly Completed in the case of the final candidate).
193 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
194 }
195
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700196 // Some local candidates are removed.
197 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700198 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700199 num_candidates_removed_ += candidates.size();
200 }
201
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000202 bool oncandidatesready_;
203 std::vector<cricket::Candidate> mline_0_candidates_;
204 std::vector<cricket::Candidate> mline_1_candidates_;
205 PeerConnectionInterface::IceConnectionState ice_connection_state_;
206 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
skvlad6c87a672016-05-17 17:49:52 -0700207 std::vector<PeerConnectionInterface::IceConnectionState>
208 ice_connection_state_history_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700209 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210};
211
212class WebRtcSessionForTest : public webrtc::WebRtcSession {
213 public:
stefanc1aeaf02015-10-15 07:26:07 -0700214 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
danilchape9021a32016-05-17 01:52:02 -0700215 rtc::Thread* network_thread,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000216 rtc::Thread* worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700217 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700219 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700220 : WebRtcSession(media_controller,
danilchape9021a32016-05-17 01:52:02 -0700221 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700222 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700223 signaling_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700224 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 RegisterIceObserver(ice_observer);
226 }
227 virtual ~WebRtcSessionForTest() {}
228
deadbeefcbecd352015-09-23 11:50:27 -0700229 // Note that these methods are only safe to use if the signaling thread
230 // is the same as the worker thread
231 cricket::TransportChannel* voice_rtp_transport_channel() {
232 return rtp_transport_channel(voice_channel());
233 }
234
235 cricket::TransportChannel* voice_rtcp_transport_channel() {
236 return rtcp_transport_channel(voice_channel());
237 }
238
239 cricket::TransportChannel* video_rtp_transport_channel() {
240 return rtp_transport_channel(video_channel());
241 }
242
243 cricket::TransportChannel* video_rtcp_transport_channel() {
244 return rtcp_transport_channel(video_channel());
245 }
246
247 cricket::TransportChannel* data_rtp_transport_channel() {
248 return rtp_transport_channel(data_channel());
249 }
250
251 cricket::TransportChannel* data_rtcp_transport_channel() {
252 return rtcp_transport_channel(data_channel());
253 }
254
deadbeefcbecd352015-09-23 11:50:27 -0700255 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ömd79599d2016-06-01 13:58:50 +0200374 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
375 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
376 // options. When DTLS is enabled a certificate will be used if provided,
377 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000378 void Init(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200379 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 ASSERT_TRUE(session_.get() == NULL);
381 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700382 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
danilchape9021a32016-05-17 01:52:02 -0700383 rtc::Thread::Current(), allocator_.get(), &observer_));
deadbeefab9b2d12015-10-14 11:33:11 -0700384 session_->SignalDataChannelOpenMessage.connect(
385 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800386 session_->GetOnDestroyedSignal()->connect(
387 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388
389 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
390 observer_.ice_connection_state_);
391 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
392 observer_.ice_gathering_state_);
393
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200394 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800395 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700396 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000397 }
398
deadbeefab9b2d12015-10-14 11:33:11 -0700399 void OnDataChannelOpenMessage(const std::string& label,
400 const InternalDataChannelInit& config) {
401 last_data_channel_label_ = label;
402 last_data_channel_config_ = config;
403 }
404
deadbeef057ecf02016-01-20 14:30:43 -0800405 void OnSessionDestroyed() { session_destroyed_ = true; }
406
htaa2a49d92016-03-04 02:51:39 -0800407 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000408
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000409 void InitWithBundlePolicy(
410 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800411 configuration_.bundle_policy = bundle_policy;
412 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700413 }
414
415 void InitWithRtcpMuxPolicy(
416 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
417 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800418 configuration_.rtcp_mux_policy = rtcp_mux_policy;
419 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000420 }
421
Henrik Boström87713d02015-08-25 09:53:21 +0200422 // Successfully init with DTLS; with a certificate generated and supplied or
423 // with a store that generates it for us.
424 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200425 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200426 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800427 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200428 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200429 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200430 cert_generator.reset(new FakeRTCCertificateGenerator());
431 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200432 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700433 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200434 }
Henrik Boströmd79599d2016-06-01 13:58:50 +0200435 Init(std::move(cert_generator));
Henrik Boström87713d02015-08-25 09:53:21 +0200436 }
437
438 // Init with DTLS with a store that will fail to generate a certificate.
439 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200440 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
441 new FakeRTCCertificateGenerator());
442 cert_generator->set_should_fail(true);
443 Init(std::move(cert_generator));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000444 }
445
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446 void InitWithDtmfCodec() {
447 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700448 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
449 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450 std::vector<cricket::AudioCodec> codecs;
451 codecs.push_back(kTelephoneEventCodec);
452 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -0700453 desc_factory_->set_audio_codecs(codecs, codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000454 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455 }
456
deadbeefab9b2d12015-10-14 11:33:11 -0700457 void SendAudioVideoStream1() {
458 send_stream_1_ = true;
459 send_stream_2_ = false;
460 send_audio_ = true;
461 send_video_ = true;
462 }
463
464 void SendAudioVideoStream2() {
465 send_stream_1_ = false;
466 send_stream_2_ = true;
467 send_audio_ = true;
468 send_video_ = true;
469 }
470
471 void SendAudioVideoStream1And2() {
472 send_stream_1_ = true;
473 send_stream_2_ = true;
474 send_audio_ = true;
475 send_video_ = true;
476 }
477
478 void SendNothing() {
479 send_stream_1_ = false;
480 send_stream_2_ = false;
481 send_audio_ = false;
482 send_video_ = false;
483 }
484
485 void SendAudioOnlyStream2() {
486 send_stream_1_ = false;
487 send_stream_2_ = true;
488 send_audio_ = true;
489 send_video_ = false;
490 }
491
492 void SendVideoOnlyStream2() {
493 send_stream_1_ = false;
494 send_stream_2_ = true;
495 send_audio_ = false;
496 send_video_ = true;
497 }
498
499 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
500 if (send_stream_1_ && send_audio_) {
501 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
502 kStream1);
503 }
504 if (send_stream_1_ && send_video_) {
505 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
506 kStream1);
507 }
508 if (send_stream_2_ && send_audio_) {
509 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
510 kStream2);
511 }
512 if (send_stream_2_ && send_video_) {
513 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
514 kStream2);
515 }
516 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
517 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
518 data_channel_->label(),
519 data_channel_->label());
520 }
521 }
522
523 void GetOptionsForOffer(
524 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
525 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800526 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700527
deadbeefc80741f2015-10-22 13:14:45 -0700528 AddStreamsToOptions(session_options);
529 if (rtc_options.offer_to_receive_audio ==
530 RTCOfferAnswerOptions::kUndefined) {
531 session_options->recv_audio =
532 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
533 }
534 if (rtc_options.offer_to_receive_video ==
535 RTCOfferAnswerOptions::kUndefined) {
536 session_options->recv_video =
537 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
538 }
539 session_options->bundle_enabled =
540 session_options->bundle_enabled &&
541 (session_options->has_audio() || session_options->has_video() ||
542 session_options->has_data());
543
deadbeefab9b2d12015-10-14 11:33:11 -0700544 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
545 session_options->data_channel_type = cricket::DCT_SCTP;
546 }
547 }
548
htaa2a49d92016-03-04 02:51:39 -0800549 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
550 // ParseConstraintsForAnswer is used to set some defaults.
551 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700552
deadbeefc80741f2015-10-22 13:14:45 -0700553 AddStreamsToOptions(session_options);
554 session_options->bundle_enabled =
555 session_options->bundle_enabled &&
556 (session_options->has_audio() || session_options->has_video() ||
557 session_options->has_data());
558
deadbeefab9b2d12015-10-14 11:33:11 -0700559 if (session_->data_channel_type() == cricket::DCT_SCTP) {
560 session_options->data_channel_type = cricket::DCT_SCTP;
561 }
562 }
563
564 // Creates a local offer and applies it. Starts ICE.
565 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000566 // to decide which streams to create.
567 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000568 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000569 SetLocalDescriptionWithoutError(offer);
570 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
571 observer_.ice_gathering_state_,
572 kIceCandidatesTimeout);
573 }
574
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000575 SessionDescriptionInterface* CreateOffer() {
576 PeerConnectionInterface::RTCOfferAnswerOptions options;
577 options.offer_to_receive_audio =
578 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
579
580 return CreateOffer(options);
581 }
582
wu@webrtc.org91053e72013-08-10 07:18:04 +0000583 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800584 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000585 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000586 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700587 cricket::MediaSessionOptions session_options;
588 GetOptionsForOffer(options, &session_options);
589 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000590 EXPECT_TRUE_WAIT(
591 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000592 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000593 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000594 }
595
596 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800597 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000598 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000599 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800600 cricket::MediaSessionOptions session_options = options;
601 GetOptionsForAnswer(&session_options);
602 // Overwrite recv_audio and recv_video with passed-in values.
603 session_options.recv_video = options.recv_video;
604 session_options.recv_audio = options.recv_audio;
605 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000606 EXPECT_TRUE_WAIT(
607 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000608 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000609 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000610 }
611
htaa2a49d92016-03-04 02:51:39 -0800612 SessionDescriptionInterface* CreateAnswer() {
613 cricket::MediaSessionOptions options;
614 options.recv_video = true;
615 options.recv_audio = true;
616 return CreateAnswer(options);
617 }
618
wu@webrtc.org364f2042013-11-20 21:49:41 +0000619 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000620 return (session_->voice_channel() != NULL &&
621 session_->video_channel() != NULL);
622 }
623
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
625 ASSERT_TRUE(session_.get() != NULL);
626 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
627 ASSERT_TRUE(content != NULL);
628 const cricket::AudioContentDescription* audio_content =
629 static_cast<const cricket::AudioContentDescription*>(
630 content->description);
631 ASSERT_TRUE(audio_content != NULL);
632 ASSERT_EQ(1U, audio_content->cryptos().size());
633 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
634 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
635 audio_content->cryptos()[0].cipher_suite);
636 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
637 audio_content->protocol());
638
639 content = cricket::GetFirstVideoContent(sdp);
640 ASSERT_TRUE(content != NULL);
641 const cricket::VideoContentDescription* video_content =
642 static_cast<const cricket::VideoContentDescription*>(
643 content->description);
644 ASSERT_TRUE(video_content != NULL);
645 ASSERT_EQ(1U, video_content->cryptos().size());
646 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
647 video_content->cryptos()[0].cipher_suite);
648 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
649 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
650 video_content->protocol());
651 }
652
653 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
654 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
655 ASSERT_TRUE(content != NULL);
656 const cricket::AudioContentDescription* audio_content =
657 static_cast<const cricket::AudioContentDescription*>(
658 content->description);
659 ASSERT_TRUE(audio_content != NULL);
660 ASSERT_EQ(0U, audio_content->cryptos().size());
661
662 content = cricket::GetFirstVideoContent(sdp);
663 ASSERT_TRUE(content != NULL);
664 const cricket::VideoContentDescription* video_content =
665 static_cast<const cricket::VideoContentDescription*>(
666 content->description);
667 ASSERT_TRUE(video_content != NULL);
668 ASSERT_EQ(0U, video_content->cryptos().size());
669
670 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700671 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000672 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700673 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000674 video_content->protocol());
675 } else {
676 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
677 audio_content->protocol());
678 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
679 video_content->protocol());
680 }
681 }
682
683 // Set the internal fake description factories to do DTLS-SRTP.
684 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000685 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000687 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200688 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800689 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700690 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800691 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
693 }
694
695 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
696 bool expected) {
697 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
698 ASSERT_TRUE(audio != NULL);
699 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 const TransportInfo* video = sdp->GetTransportInfoByName("video");
701 ASSERT_TRUE(video != NULL);
702 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703 }
704
705 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000706 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000708 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000709 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000711 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000713 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
714 offer);
htaa2a49d92016-03-04 02:51:39 -0800715 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716 // Answer should be NULL as no crypto params in offer.
717 ASSERT_TRUE(answer == NULL);
718 }
719
720 void VerifyAnswerFromCryptoOffer() {
721 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000722 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700724 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
726 ASSERT_TRUE(offer.get() != NULL);
727 VerifyCryptoParams(offer->description());
728 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700729 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 ASSERT_TRUE(answer.get() != NULL);
731 VerifyCryptoParams(answer->description());
732 }
733
deadbeef0ed85b22016-02-23 17:24:52 -0800734 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
735 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800737 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738 }
739
740 const cricket::ContentInfos& contents = desc1->contents();
741 cricket::ContentInfos::const_iterator it = contents.begin();
742
743 for (; it != contents.end(); ++it) {
744 const cricket::TransportDescription* transport_desc1 =
745 desc1->GetTransportDescriptionByName(it->name);
746 const cricket::TransportDescription* transport_desc2 =
747 desc2->GetTransportDescriptionByName(it->name);
748 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800749 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000750 }
751 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
752 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800753 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 }
755 }
deadbeef0ed85b22016-02-23 17:24:52 -0800756 return true;
757 }
758
759 // Compares ufrag/password only for the specified |media_type|.
760 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
761 const cricket::SessionDescription* desc2,
762 cricket::MediaType media_type) {
763 if (desc1->contents().size() != desc2->contents().size()) {
764 return false;
765 }
766
767 const cricket::ContentInfo* cinfo =
768 cricket::GetFirstMediaContent(desc1->contents(), media_type);
769 const cricket::TransportDescription* transport_desc1 =
770 desc1->GetTransportDescriptionByName(cinfo->name);
771 const cricket::TransportDescription* transport_desc2 =
772 desc2->GetTransportDescriptionByName(cinfo->name);
773 if (!transport_desc1 || !transport_desc2) {
774 return false;
775 }
776 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
777 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
778 return false;
779 }
780 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000782
783 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
784 std::string *sdp) {
785 const cricket::SessionDescription* desc = current_desc->description();
786 EXPECT_TRUE(current_desc->ToString(sdp));
787
788 const cricket::ContentInfos& contents = desc->contents();
789 cricket::ContentInfos::const_iterator it = contents.begin();
790 // Replace ufrag and pwd lines with empty strings.
791 for (; it != contents.end(); ++it) {
792 const cricket::TransportDescription* transport_desc =
793 desc->GetTransportDescriptionByName(it->name);
794 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
795 + "\r\n";
796 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
797 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000798 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000799 "", 0,
800 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000801 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000802 "", 0,
803 sdp);
804 }
805 }
806
deadbeef0ed85b22016-02-23 17:24:52 -0800807 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
808 const std::string& ufrag,
809 const std::string& pwd) {
810 cricket::SessionDescription* desc = current_desc->description();
811 for (TransportInfo& transport_info : desc->transport_infos()) {
812 cricket::TransportDescription& transport_desc =
813 transport_info.description;
814 transport_desc.ice_ufrag = ufrag;
815 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000816 }
817 }
818
deadbeef0ed85b22016-02-23 17:24:52 -0800819 // Sets ufrag/pwd for specified |media_type|.
820 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
821 cricket::MediaType media_type,
822 const std::string& ufrag,
823 const std::string& pwd) {
824 cricket::SessionDescription* desc = current_desc->description();
825 const cricket::ContentInfo* cinfo =
826 cricket::GetFirstMediaContent(desc->contents(), media_type);
827 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
828 cricket::TransportDescription* transport_desc =
829 &transport_info->description;
830 transport_desc->ice_ufrag = ufrag;
831 transport_desc->ice_pwd = pwd;
832 }
833
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 // Creates a remote offer and and applies it as a remote description,
835 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700836 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 // to decide which local and remote streams to create.
838 void CreateAndSetRemoteOfferAndLocalAnswer() {
839 SessionDescriptionInterface* offer = CreateRemoteOffer();
840 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800841 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 SetLocalDescriptionWithoutError(answer);
843 }
844 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
845 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700846 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 }
848 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700849 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 SetLocalDescriptionWithoutError(desc);
851 EXPECT_EQ(expected_state, session_->state());
852 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000853 void SetLocalDescriptionExpectError(const std::string& action,
854 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 SessionDescriptionInterface* desc) {
856 std::string error;
857 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000858 std::string sdp_type = "local ";
859 sdp_type.append(action);
860 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 EXPECT_NE(std::string::npos, error.find(expected_error));
862 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000863 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
864 SessionDescriptionInterface* desc) {
865 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
866 expected_error, desc);
867 }
868 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
869 SessionDescriptionInterface* desc) {
870 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
871 expected_error, desc);
872 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
874 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
875 }
876 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700877 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 SetRemoteDescriptionWithoutError(desc);
879 EXPECT_EQ(expected_state, session_->state());
880 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000881 void SetRemoteDescriptionExpectError(const std::string& action,
882 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 SessionDescriptionInterface* desc) {
884 std::string error;
885 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000886 std::string sdp_type = "remote ";
887 sdp_type.append(action);
888 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 EXPECT_NE(std::string::npos, error.find(expected_error));
890 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000891 void SetRemoteDescriptionOfferExpectError(
892 const std::string& expected_error, SessionDescriptionInterface* desc) {
893 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
894 expected_error, desc);
895 }
896 void SetRemoteDescriptionPranswerExpectError(
897 const std::string& expected_error, SessionDescriptionInterface* desc) {
898 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
899 expected_error, desc);
900 }
901 void SetRemoteDescriptionAnswerExpectError(
902 const std::string& expected_error, SessionDescriptionInterface* desc) {
903 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
904 expected_error, desc);
905 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906
907 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
908 SessionDescriptionInterface** nocrypto_answer) {
909 // Create a SDP without Crypto.
910 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000911 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 options.bundle_enabled = true;
913 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
914 ASSERT_TRUE(*offer != NULL);
915 VerifyCryptoParams((*offer)->description());
916
917 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
918 cricket::SEC_DISABLED);
919 EXPECT_TRUE(*nocrypto_answer != NULL);
920 }
921
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000922 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
923 SessionDescriptionInterface** nodtls_answer) {
924 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000925 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000926 options.bundle_enabled = true;
927
kwibergd1fe2812016-04-27 06:47:29 -0700928 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000929 CreateRemoteOffer(options, cricket::SEC_ENABLED));
930
931 *nodtls_answer =
932 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
933 EXPECT_TRUE(*nodtls_answer != NULL);
934 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
935 VerifyCryptoParams((*nodtls_answer)->description());
936
937 SetFactoryDtlsSrtp();
938 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
939 ASSERT_TRUE(*offer != NULL);
940 VerifyFingerprintStatus((*offer)->description(), true);
941 VerifyCryptoParams((*offer)->description());
942 }
943
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 JsepSessionDescription* CreateRemoteOfferWithVersion(
945 cricket::MediaSessionOptions options,
946 cricket::SecurePolicy secure_policy,
947 const std::string& session_version,
948 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000949 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 const cricket::SessionDescription* cricket_desc = NULL;
951 if (current_desc) {
952 cricket_desc = current_desc->description();
953 session_id = current_desc->session_id();
954 }
955
956 desc_factory_->set_secure(secure_policy);
957 JsepSessionDescription* offer(
958 new JsepSessionDescription(JsepSessionDescription::kOffer));
959 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
960 session_id, session_version)) {
961 delete offer;
962 offer = NULL;
963 }
964 return offer;
965 }
966 JsepSessionDescription* CreateRemoteOffer(
967 cricket::MediaSessionOptions options) {
968 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
969 kSessionVersion, NULL);
970 }
971 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000972 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
973 return CreateRemoteOfferWithVersion(
974 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 }
976 JsepSessionDescription* CreateRemoteOffer(
977 cricket::MediaSessionOptions options,
978 const SessionDescriptionInterface* current_desc) {
979 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
980 kSessionVersion, current_desc);
981 }
982
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000983 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
984 const char* sctp_stream_name, int new_port,
985 cricket::MediaSessionOptions options) {
986 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000987 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
988 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000989 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
990 }
991
992 // Takes ownership of offer_basis (and deletes it).
993 JsepSessionDescription* ChangeSDPSctpPort(
994 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
995 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
996 // SessionDescription from the mutated string.
997 const char* default_port_str = "5000";
998 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000999 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001000 std::string offer_str;
1001 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001002 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001003 new_port_str, strlen(new_port_str),
1004 &offer_str);
1005 JsepSessionDescription* offer = new JsepSessionDescription(
1006 offer_basis->type());
1007 delete offer_basis;
1008 offer->Initialize(offer_str, NULL);
1009 return offer;
1010 }
1011
deadbeefab9b2d12015-10-14 11:33:11 -07001012 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013 // before this function to decide which streams to create.
1014 JsepSessionDescription* CreateRemoteOffer() {
1015 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001016 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017 return CreateRemoteOffer(options, session_->remote_description());
1018 }
1019
1020 JsepSessionDescription* CreateRemoteAnswer(
1021 const SessionDescriptionInterface* offer,
1022 cricket::MediaSessionOptions options,
1023 cricket::SecurePolicy policy) {
1024 desc_factory_->set_secure(policy);
1025 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001026 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001027 JsepSessionDescription* answer(
1028 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1029 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1030 options, NULL),
1031 session_id, kSessionVersion)) {
1032 delete answer;
1033 answer = NULL;
1034 }
1035 return answer;
1036 }
1037
1038 JsepSessionDescription* CreateRemoteAnswer(
1039 const SessionDescriptionInterface* offer,
1040 cricket::MediaSessionOptions options) {
1041 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1042 }
1043
deadbeefab9b2d12015-10-14 11:33:11 -07001044 // Creates an answer session description.
1045 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001046 // to decide which streams to create.
1047 JsepSessionDescription* CreateRemoteAnswer(
1048 const SessionDescriptionInterface* offer) {
1049 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001050 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001051 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1052 }
1053
1054 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001055 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001056 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001057 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001058
1059 PeerConnectionInterface::RTCOfferAnswerOptions options;
1060 options.use_rtp_mux = bundle;
1061
1062 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1064 // and answer.
1065 SetLocalDescriptionWithoutError(offer);
1066
kwibergd1fe2812016-04-27 06:47:29 -07001067 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001068 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 std::string sdp;
1070 EXPECT_TRUE(answer->ToString(&sdp));
1071
1072 size_t expected_candidate_num = 2;
1073 if (!rtcp_mux) {
1074 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1075 // for rtp and rtcp.
1076 expected_candidate_num = 4;
1077 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 const std::string kRtcpMux = "a=rtcp-mux";
1079 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001080 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001081 kXRtcpMux.c_str(), kXRtcpMux.length(),
1082 &sdp);
1083 }
1084
1085 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1086 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087
1088 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001089 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001090 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1091 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001092 if (bundle) {
1093 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1094 } else {
1095 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096 }
1097 }
1098 // Tests that we can only send DTMF when the dtmf codec is supported.
1099 void TestCanInsertDtmf(bool can) {
1100 if (can) {
1101 InitWithDtmfCodec();
1102 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001103 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104 }
deadbeefab9b2d12015-10-14 11:33:11 -07001105 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 CreateAndSetRemoteOfferAndLocalAnswer();
1107 EXPECT_FALSE(session_->CanInsertDtmf(""));
1108 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1109 }
1110
zhihuang3a334652016-05-05 18:37:49 -07001111 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1112 const std::string& codec_name) {
1113 for (const auto& content : desc->description()->contents()) {
1114 if (static_cast<cricket::MediaContentDescription*>(content.description)
1115 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1116 const auto* mdesc =
1117 static_cast<cricket::VideoContentDescription*>(content.description);
1118 for (const auto& codec : mdesc->codecs()) {
1119 if (codec.name == codec_name) {
1120 return true;
1121 }
1122 }
1123 }
1124 }
1125 return false;
1126 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001127 // Helper class to configure loopback network and verify Best
1128 // Connection using right IP protocol for TestLoopbackCall
1129 // method. LoopbackNetworkManager applies firewall rules to block
1130 // all ping traffic once ICE completed, and remove them to observe
1131 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1132 // verifies the best connection is using the right IP protocol after
1133 // initial ICE convergences.
1134
1135 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001136 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001137 LoopbackNetworkConfiguration()
1138 : test_ipv6_network_(false),
1139 test_extra_ipv4_network_(false),
1140 best_connection_after_initial_ice_converged_(1, 0) {}
1141
1142 // Used to track the expected best connection count in each IP protocol.
1143 struct ExpectedBestConnection {
1144 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1145 : ipv4_count_(ipv4_count),
1146 ipv6_count_(ipv6_count) {}
1147
1148 int ipv4_count_;
1149 int ipv6_count_;
1150 };
1151
1152 bool test_ipv6_network_;
1153 bool test_extra_ipv4_network_;
1154 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1155
1156 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001157 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001158 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1159 }
1160
1161 private:
jbauchac8869e2015-07-03 01:36:14 -07001162 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001163 const ExpectedBestConnection& expected) const {
1164 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001165 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1166 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001167 expected.ipv4_count_);
1168 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001169 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1170 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001171 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001172 // This is used in the loopback call so there is only single host to host
1173 // candidate pair.
1174 EXPECT_EQ(metrics_observer->GetEnumCounter(
1175 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1176 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001177 0);
1178 EXPECT_EQ(metrics_observer->GetEnumCounter(
1179 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1180 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001181 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001182 }
1183 };
1184
1185 class LoopbackNetworkManager {
1186 public:
1187 LoopbackNetworkManager(WebRtcSessionTest* session,
1188 const LoopbackNetworkConfiguration& config)
1189 : config_(config) {
1190 session->AddInterface(
1191 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1192 if (config_.test_extra_ipv4_network_) {
1193 session->AddInterface(
1194 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1195 }
1196 if (config_.test_ipv6_network_) {
1197 session->AddInterface(
1198 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1199 }
1200 }
1201
1202 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1203 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1204 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1205 if (config_.test_extra_ipv4_network_) {
1206 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1207 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1208 }
1209 if (config_.test_ipv6_network_) {
1210 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1211 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1212 }
1213 }
1214
1215 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1216
1217 private:
1218 LoopbackNetworkConfiguration config_;
1219 };
1220
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001221 // The method sets up a call from the session to itself, in a loopback
1222 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001223 // disconnection, and then a permanent disconnection.
1224 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001225 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1226 // While running the call, this method also checks if the session goes through
1227 // the correct sequence of ICE states when a connection is established,
1228 // broken, and re-established.
1229 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001230 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1231 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001233
stefanc1aeaf02015-10-15 07:26:07 -07001234 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001235 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001236 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001237 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001238
1239 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1240 observer_.ice_gathering_state_);
1241 SetLocalDescriptionWithoutError(offer);
1242 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1243 observer_.ice_connection_state_);
1244 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001245 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001246 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1247 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001248 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001249
1250 std::string sdp;
1251 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001252 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1253 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001254 ASSERT_TRUE(desc != NULL);
1255 SetRemoteDescriptionWithoutError(desc);
1256
1257 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001258 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001259
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001260 // The ice connection state is "Connected" too briefly to catch in a test.
1261 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001262 observer_.ice_connection_state_, kIceCandidatesTimeout);
1263 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264
stefanc1aeaf02015-10-15 07:26:07 -07001265 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1266 LoopbackNetworkManager loopback_network_manager(this, config);
1267 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001268 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001269 // Adding firewall rule to block ping requests, which should cause
1270 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001271
1272 loopback_network_manager.ApplyFirewallRules(fss_.get());
1273
1274 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1276 observer_.ice_connection_state_,
1277 kIceCandidatesTimeout);
1278
jbauchac8869e2015-07-03 01:36:14 -07001279 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001280
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001281 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001282 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001284 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001285 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001286 observer_.ice_connection_state_,
1287 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001288
1289 // Now we block ping requests and wait until the ICE connection transitions
1290 // to the Failed state. This will take at least 30 seconds because it must
1291 // wait for the Port to timeout.
1292 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001293
1294 loopback_network_manager.ApplyFirewallRules(fss_.get());
1295 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001296 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001297 observer_.ice_connection_state_,
1298 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299 }
1300
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001301 void TestLoopbackCall() {
1302 LoopbackNetworkConfiguration config;
1303 TestLoopbackCall(config);
1304 }
1305
stefanc1aeaf02015-10-15 07:26:07 -07001306 void TestPacketOptions() {
1307 media_controller_.reset(
1308 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1309 LoopbackNetworkConfiguration config;
1310 LoopbackNetworkManager loopback_network_manager(this, config);
1311
1312 SetupLoopbackCall();
1313
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001314 // Wait for channel to be ready for sending.
1315 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001316 uint8_t test_packet[15] = {0};
1317 rtc::PacketOptions options;
1318 options.packet_id = 10;
1319 media_engine_->GetVideoChannel(0)
1320 ->SendRtp(test_packet, sizeof(test_packet), options);
1321
1322 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001323 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1324 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001325 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1326 }
1327
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001328 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1329 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001330 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1331 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001332
1333 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001334 std::vector<cricket::AudioCodec> codecs =
1335 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001336 codecs.push_back(kCNCodec1);
1337 codecs.push_back(kCNCodec2);
1338 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001339 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001340 }
1341
1342 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1343 const cricket::ContentDescription* description = content->description;
1344 ASSERT(description != NULL);
1345 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001346 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001347 ASSERT(audio_content_desc != NULL);
1348 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1349 if (audio_content_desc->codecs()[i].name == "CN")
1350 return false;
1351 }
1352 return true;
1353 }
1354
deadbeefab9b2d12015-10-14 11:33:11 -07001355 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001356 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001357 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001358 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1359 data_channel_ = DataChannel::Create(
1360 session_.get(), session_->data_channel_type(), "datachannel", dci);
1361 }
1362
1363 void SetLocalDescriptionWithDataChannel() {
1364 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001365 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001366 SetLocalDescriptionWithoutError(offer);
1367 }
1368
wu@webrtc.org91053e72013-08-10 07:18:04 +00001369 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001370 RTCCertificateGenerationMethod cert_gen_method,
1371 CreateSessionDescriptionRequest::Type type) {
1372 InitWithDtls(cert_gen_method);
1373 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1374 }
1375
1376 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1377 CreateSessionDescriptionRequest::Type type) {
1378 InitWithDtlsIdentityGenFail();
1379 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1380 }
1381
1382 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001383 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001384 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001385 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001386 if (type == CreateSessionDescriptionRequest::kAnswer) {
1387 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001388 std::unique_ptr<JsepSessionDescription> offer(
1389 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001390 ASSERT_TRUE(offer.get() != NULL);
1391 SetRemoteDescriptionWithoutError(offer.release());
1392 }
1393
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001394 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001395 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001396 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001397 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001398 observers[kNumber];
1399 for (int i = 0; i < kNumber; ++i) {
1400 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1401 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001402 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001403 } else {
htaa2a49d92016-03-04 02:51:39 -08001404 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001405 }
1406 }
1407
1408 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1409 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1410 WebRtcSessionCreateSDPObserverForTest::kFailed;
1411
1412 for (int i = 0; i < kNumber; ++i) {
1413 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1414 if (success) {
1415 EXPECT_TRUE(observers[i]->description() != NULL);
1416 } else {
1417 EXPECT_TRUE(observers[i]->description() == NULL);
1418 }
1419 }
1420 }
1421
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001422 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001423 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001424 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001425 turn_server.credentials = credentials;
1426 turn_server.ports.push_back(
1427 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1428 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001429 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001430 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001431 }
1432
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001433 cricket::FakeMediaEngine* media_engine_;
1434 cricket::FakeDataEngine* data_engine_;
kwibergd1fe2812016-04-27 06:47:29 -07001435 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001436 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001437 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1438 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1439 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1440 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1441 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1442 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001443 rtc::SocketServerScope ss_scope_;
1444 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001445 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001446 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001447 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001448 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001449 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001450 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001451 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001452 MockIceObserver observer_;
1453 cricket::FakeVideoMediaChannel* video_channel_;
1454 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001455 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001456 // The following flags affect options created for CreateOffer/CreateAnswer.
1457 bool send_stream_1_ = false;
1458 bool send_stream_2_ = false;
1459 bool send_audio_ = false;
1460 bool send_video_ = false;
1461 rtc::scoped_refptr<DataChannel> data_channel_;
1462 // Last values received from data channel creation signal.
1463 std::string last_data_channel_label_;
1464 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001465 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466};
1467
Henrik Boström87713d02015-08-25 09:53:21 +02001468TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1469 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001470 // SDES is disabled when DTLS is on.
1471 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472}
1473
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001474TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001475 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001476 // SDES is required if DTLS is off.
1477 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001478}
1479
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1481 TestSessionCandidatesWithBundleRtcpMux(false, false);
1482}
1483
1484// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1485// with rtcp-mux and/or bundle.
1486TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1487 TestSessionCandidatesWithBundleRtcpMux(false, true);
1488}
1489
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001490TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1491 TestSessionCandidatesWithBundleRtcpMux(true, true);
1492}
1493
1494TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001495 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1496 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001497 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001498 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001499 InitiateCall();
1500 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1501 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1502 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1503}
1504
deadbeeff5f03e82016-06-06 11:16:06 -07001505TEST_F(WebRtcSessionTest, TestStunError) {
1506 rtc::ScopedFakeClock clock;
1507
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001508 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1509 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001510 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001511 rtc::FP_UDP,
1512 rtc::FD_ANY,
1513 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001514 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001515 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001517 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
deadbeeff5f03e82016-06-06 11:16:06 -07001518 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_, kStunTimeout, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001519 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1520 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001521 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1522 // warning.
1523 session_->Close();
1524 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525}
1526
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001527TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001528 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001529 SessionDescriptionInterface* offer = NULL;
1530 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1531 std::string unknown_action;
1532 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1533 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1534}
1535
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536// Test creating offers and receive answers and make sure the
1537// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001538TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001539 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001540 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001541 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001542 const std::string session_id_orig = offer->session_id();
1543 const std::string session_version_orig = offer->session_version();
1544 SetLocalDescriptionWithoutError(offer);
1545
deadbeefab9b2d12015-10-14 11:33:11 -07001546 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547 SessionDescriptionInterface* answer =
1548 CreateRemoteAnswer(session_->local_description());
1549 SetRemoteDescriptionWithoutError(answer);
1550
1551 video_channel_ = media_engine_->GetVideoChannel(0);
1552 voice_channel_ = media_engine_->GetVoiceChannel(0);
1553
1554 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1555 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1556
1557 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1558 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1559
1560 ASSERT_EQ(1u, video_channel_->send_streams().size());
1561 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1562 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1563 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1564
1565 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001566 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001567 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568
1569 // Verify the session id is the same and the session version is
1570 // increased.
1571 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001572 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1573 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001574
1575 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001576 EXPECT_EQ(0u, video_channel_->send_streams().size());
1577 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578
deadbeefab9b2d12015-10-14 11:33:11 -07001579 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580 answer = CreateRemoteAnswer(session_->local_description());
1581 SetRemoteDescriptionWithoutError(answer);
1582
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 // Make sure the receive streams have not changed.
1584 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1585 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1586 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1587 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1588}
1589
1590// Test receiving offers and creating answers and make sure the
1591// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001592TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001593 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001594 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001595 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001596 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 SetRemoteDescriptionWithoutError(offer);
1598
deadbeefab9b2d12015-10-14 11:33:11 -07001599 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001600 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001601 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602 SetLocalDescriptionWithoutError(answer);
1603
1604 const std::string session_id_orig = answer->session_id();
1605 const std::string session_version_orig = answer->session_version();
1606
1607 video_channel_ = media_engine_->GetVideoChannel(0);
1608 voice_channel_ = media_engine_->GetVoiceChannel(0);
1609
htaa2a49d92016-03-04 02:51:39 -08001610 ASSERT_TRUE(video_channel_);
1611 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1613 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1614
1615 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1616 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1617
1618 ASSERT_EQ(1u, video_channel_->send_streams().size());
1619 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1620 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1621 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1622
deadbeefab9b2d12015-10-14 11:33:11 -07001623 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001624 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625 SetRemoteDescriptionWithoutError(offer);
1626
1627 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001628 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001629 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630
1631 // Verify the session id is the same and the session version is
1632 // increased.
1633 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001634 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1635 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 SetLocalDescriptionWithoutError(answer);
1637
1638 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1639 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1640 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1641 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1642 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1643 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1644
1645 // Make sure we have no send streams.
1646 EXPECT_EQ(0u, video_channel_->send_streams().size());
1647 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1648}
1649
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001650TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001651 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001652 media_engine_->set_fail_create_channel(true);
1653
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001654 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001655 ASSERT_TRUE(offer != NULL);
1656 // SetRemoteDescription and SetLocalDescription will take the ownership of
1657 // the offer.
1658 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001659 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001660 ASSERT_TRUE(offer != NULL);
1661 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1662}
1663
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001664//
1665// Tests for creating/setting SDP under different SDES/DTLS polices:
1666//
1667// --DTLS off and SDES on
1668// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1669// set local/remote offer/answer with crypto --> success
1670// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1671// failure
1672// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1673// failure
1674// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1675// failure
1676//
1677// --DTLS on and SDES off
1678// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1679// set local/remote offer/answer with DTLS fingerprint --> success
1680// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1681// fingerprint --> failure
1682// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1683// --> failure
1684// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1685// --> failure
1686//
1687// --Encryption disabled: DTLS off and SDES off
1688// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1689// answer without SDES or DTLS --> success
1690// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1691// answer without SDES or DTLS --> success
1692//
1693
1694// Test that we return a failure when applying a remote/local offer that doesn't
1695// have cryptos enabled when DTLS is off.
1696TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001697 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001698 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001699 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700 JsepSessionDescription* offer = CreateRemoteOffer(
1701 options, cricket::SEC_DISABLED);
1702 ASSERT_TRUE(offer != NULL);
1703 VerifyNoCryptoParams(offer->description(), false);
1704 // SetRemoteDescription and SetLocalDescription will take the ownership of
1705 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001706 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1708 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001709 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710}
1711
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001712// Test that we return a failure when applying a local answer that doesn't have
1713// cryptos enabled when DTLS is off.
1714TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001715 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716 SessionDescriptionInterface* offer = NULL;
1717 SessionDescriptionInterface* answer = NULL;
1718 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1719 // SetRemoteDescription and SetLocalDescription will take the ownership of
1720 // the offer.
1721 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001722 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723}
1724
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001725// Test we will return fail when apply an remote answer that doesn't have
1726// crypto enabled when DTLS is off.
1727TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001728 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729 SessionDescriptionInterface* offer = NULL;
1730 SessionDescriptionInterface* answer = NULL;
1731 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1732 // SetRemoteDescription and SetLocalDescription will take the ownership of
1733 // the offer.
1734 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001735 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736}
1737
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001738// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1739// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001740TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001741 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001742 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001743 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744 SetFactoryDtlsSrtp();
1745 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001746 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001747 JsepSessionDescription* offer =
1748 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749 ASSERT_TRUE(offer != NULL);
1750 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001751 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752
1753 // SetRemoteDescription will take the ownership of the offer.
1754 SetRemoteDescriptionWithoutError(offer);
1755
1756 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001757 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 ASSERT_TRUE(answer != NULL);
1759 VerifyFingerprintStatus(answer->description(), true);
1760 // Check that we don't have an a=crypto line in the answer.
1761 VerifyNoCryptoParams(answer->description(), true);
1762
1763 // Now set the local description, which should work, even without a=crypto.
1764 SetLocalDescriptionWithoutError(answer);
1765}
1766
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001767// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1768// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001769TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001770 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001771 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001772 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001773 SetFactoryDtlsSrtp();
1774
1775 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001776 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001777 ASSERT_TRUE(offer != NULL);
1778 VerifyFingerprintStatus(offer->description(), true);
1779 // Check that we don't have an a=crypto line in the offer.
1780 VerifyNoCryptoParams(offer->description(), true);
1781
1782 // Now set the local description, which should work, even without a=crypto.
1783 SetLocalDescriptionWithoutError(offer);
1784
1785 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001786 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001787 JsepSessionDescription* answer =
1788 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1789 ASSERT_TRUE(answer != NULL);
1790 VerifyFingerprintStatus(answer->description(), true);
1791 VerifyNoCryptoParams(answer->description(), true);
1792
1793 // SetRemoteDescription will take the ownership of the answer.
1794 SetRemoteDescriptionWithoutError(answer);
1795}
1796
1797// Test that if we support DTLS and the other side didn't offer a fingerprint,
1798// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001799TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001800 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001801 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001803 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001804 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 JsepSessionDescription* offer = CreateRemoteOffer(
1806 options, cricket::SEC_REQUIRED);
1807 ASSERT_TRUE(offer != NULL);
1808 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001809 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001811 // SetRemoteDescription will take the ownership of the offer.
1812 SetRemoteDescriptionOfferExpectError(
1813 kSdpWithoutDtlsFingerprint, offer);
1814
1815 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1816 // SetLocalDescription will take the ownership of the offer.
1817 SetLocalDescriptionOfferExpectError(
1818 kSdpWithoutDtlsFingerprint, offer);
1819}
1820
1821// Test that we return a failure when applying a local answer that doesn't have
1822// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001823TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001824 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001825 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001826 SessionDescriptionInterface* offer = NULL;
1827 SessionDescriptionInterface* answer = NULL;
1828 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1829
1830 // SetRemoteDescription and SetLocalDescription will take the ownership of
1831 // the offer and answer.
1832 SetRemoteDescriptionWithoutError(offer);
1833 SetLocalDescriptionAnswerExpectError(
1834 kSdpWithoutDtlsFingerprint, answer);
1835}
1836
1837// Test that we return a failure when applying a remote answer that doesn't have
1838// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001839TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001840 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001841 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001842 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001843 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001844 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001845 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001846 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001847 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001848 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001849
1850 // SetRemoteDescription and SetLocalDescription will take the ownership of
1851 // the offer and answer.
1852 SetLocalDescriptionWithoutError(offer);
1853 SetRemoteDescriptionAnswerExpectError(
1854 kSdpWithoutDtlsFingerprint, answer);
1855}
1856
1857// Test that we create a local offer without SDES or DTLS and accept a remote
1858// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001859TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001860 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001861 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001862 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001863
1864 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001865 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001866 ASSERT_TRUE(offer != NULL);
1867 VerifyFingerprintStatus(offer->description(), false);
1868 // Check that we don't have an a=crypto line in the offer.
1869 VerifyNoCryptoParams(offer->description(), false);
1870
1871 // Now set the local description, which should work, even without a=crypto.
1872 SetLocalDescriptionWithoutError(offer);
1873
1874 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001875 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001876 JsepSessionDescription* answer =
1877 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1878 ASSERT_TRUE(answer != NULL);
1879 VerifyFingerprintStatus(answer->description(), false);
1880 VerifyNoCryptoParams(answer->description(), false);
1881
1882 // SetRemoteDescription will take the ownership of the answer.
1883 SetRemoteDescriptionWithoutError(answer);
1884}
1885
1886// Test that we create a local answer without SDES or DTLS and accept a remote
1887// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001888TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001889 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001890 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001891
1892 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001893 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001894 JsepSessionDescription* offer =
1895 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1896 ASSERT_TRUE(offer != NULL);
1897 VerifyFingerprintStatus(offer->description(), false);
1898 VerifyNoCryptoParams(offer->description(), false);
1899
1900 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001901 SetRemoteDescriptionWithoutError(offer);
1902
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001903 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001904 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001905 ASSERT_TRUE(answer != NULL);
1906 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001907 // Check that we don't have an a=crypto line in the answer.
1908 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001909
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001910 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911 SetLocalDescriptionWithoutError(answer);
1912}
1913
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001914// Test that we can create and set an answer correctly when different
1915// SSL roles have been negotiated for different transports.
1916// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1917TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1918 SendAudioVideoStream1();
1919 InitWithDtls(GetParam());
1920 SetFactoryDtlsSrtp();
1921
1922 SessionDescriptionInterface* offer = CreateOffer();
1923 SetLocalDescriptionWithoutError(offer);
1924
1925 cricket::MediaSessionOptions options;
1926 options.recv_video = true;
1927
1928 // First, negotiate different SSL roles.
1929 SessionDescriptionInterface* answer =
1930 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1931 TransportInfo* audio_transport_info =
1932 answer->description()->GetTransportInfoByName("audio");
1933 audio_transport_info->description.connection_role =
1934 cricket::CONNECTIONROLE_ACTIVE;
1935 TransportInfo* video_transport_info =
1936 answer->description()->GetTransportInfoByName("video");
1937 video_transport_info->description.connection_role =
1938 cricket::CONNECTIONROLE_PASSIVE;
1939 SetRemoteDescriptionWithoutError(answer);
1940
1941 // Now create an offer in the reverse direction, and ensure the initial
1942 // offerer responds with an answer with correct SSL roles.
1943 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1944 kSessionVersion,
1945 session_->remote_description());
1946 SetRemoteDescriptionWithoutError(offer);
1947
htaa2a49d92016-03-04 02:51:39 -08001948 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001949 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1950 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1951 audio_transport_info->description.connection_role);
1952 video_transport_info = answer->description()->GetTransportInfoByName("video");
1953 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1954 video_transport_info->description.connection_role);
1955 SetLocalDescriptionWithoutError(answer);
1956
1957 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1958 // audio is transferred over to video in the answer that completes the BUNDLE
1959 // negotiation.
1960 options.bundle_enabled = true;
1961 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1962 kSessionVersion,
1963 session_->remote_description());
1964 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08001965 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001966 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1967 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1968 audio_transport_info->description.connection_role);
1969 video_transport_info = answer->description()->GetTransportInfoByName("video");
1970 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1971 video_transport_info->description.connection_role);
1972 SetLocalDescriptionWithoutError(answer);
1973}
1974
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001976 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001977 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001979 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 SetLocalDescriptionWithoutError(offer);
1981
1982 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001983 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984 SetLocalDescriptionWithoutError(offer2);
1985}
1986
1987TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001988 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001989 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001991 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992 SetRemoteDescriptionWithoutError(offer);
1993
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001994 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995 SetRemoteDescriptionWithoutError(offer2);
1996}
1997
1998TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001999 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002000 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002001 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002003 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002004 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2005 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006}
2007
2008TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002009 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002010 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002011 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002012 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002013 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002014 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002015 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016}
2017
2018TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002019 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002020 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002021 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002022 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023
htaa2a49d92016-03-04 02:51:39 -08002024 JsepSessionDescription* pranswer =
2025 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002026 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002027 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028
deadbeefab9b2d12015-10-14 11:33:11 -07002029 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002030 JsepSessionDescription* pranswer2 =
2031 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002032 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2033
deadbeefd59daf82015-10-14 15:02:44 -07002034 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035
deadbeefab9b2d12015-10-14 11:33:11 -07002036 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002037 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002038 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039}
2040
2041TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002042 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002043 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002044 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002045 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046
2047 JsepSessionDescription* pranswer =
2048 CreateRemoteAnswer(session_->local_description());
2049 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2050
2051 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002052 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053
deadbeefab9b2d12015-10-14 11:33:11 -07002054 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055 JsepSessionDescription* pranswer2 =
2056 CreateRemoteAnswer(session_->local_description());
2057 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2058
2059 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002060 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061
deadbeefab9b2d12015-10-14 11:33:11 -07002062 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063 SessionDescriptionInterface* answer =
2064 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002065 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002066}
2067
2068TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002069 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002070 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002071 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002072
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073 SessionDescriptionInterface* answer =
2074 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002075 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2076 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077}
2078
2079TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002080 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002081 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002082 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002083
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084 SessionDescriptionInterface* answer =
2085 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002086 SetRemoteDescriptionAnswerExpectError(
2087 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088}
2089
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002090// Tests that the remote candidates are added and removed successfully.
2091TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002092 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002093 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002095 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2096 "", "", "host", 0, "");
2097 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2099
deadbeefd59daf82015-10-14 15:02:44 -07002100 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2102
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002103 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002105
2106 // Fail since we have not set a remote description.
2107 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108
2109 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2110 session_->local_description());
2111 SetRemoteDescriptionWithoutError(answer);
2112
deadbeefd59daf82015-10-14 15:02:44 -07002113 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2114 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002115 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002116 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2117 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2118
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119 // Verifying the candidates are copied properly from internal vector.
2120 const SessionDescriptionInterface* remote_desc =
2121 session_->remote_description();
2122 ASSERT_TRUE(remote_desc != NULL);
2123 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2124 const IceCandidateCollection* candidates =
2125 remote_desc->candidates(kMediaContentIndex0);
2126 ASSERT_EQ(2u, candidates->count());
2127 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2128 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2129 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2130 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2131
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002132 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2133 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 candidate.set_component(2);
2135 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2136 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002137 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138
2139 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2140 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002141
2142 // Remove candidate1 and candidate2
2143 std::vector<cricket::Candidate> remote_candidates;
2144 remote_candidates.push_back(ice_candidate1.candidate());
2145 remote_candidates.push_back(ice_candidate2.candidate());
2146 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2147 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148}
2149
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002150// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151// that it is retained if the remote session description is changed.
2152TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002153 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 cricket::Candidate candidate1;
2155 candidate1.set_component(1);
2156 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2157 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002158 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 CreateAndSetRemoteOfferAndLocalAnswer();
2160
2161 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2162 const SessionDescriptionInterface* remote_desc =
2163 session_->remote_description();
2164 ASSERT_TRUE(remote_desc != NULL);
2165 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2166 const IceCandidateCollection* candidates =
2167 remote_desc->candidates(kMediaContentIndex0);
2168 ASSERT_EQ(1u, candidates->count());
2169 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2170
2171 // Update the RemoteSessionDescription with a new session description and
2172 // a candidate and check that the new remote session description contains both
2173 // candidates.
2174 SessionDescriptionInterface* offer = CreateRemoteOffer();
2175 cricket::Candidate candidate2;
2176 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2177 candidate2);
2178 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2179 SetRemoteDescriptionWithoutError(offer);
2180
2181 remote_desc = session_->remote_description();
2182 ASSERT_TRUE(remote_desc != NULL);
2183 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2184 candidates = remote_desc->candidates(kMediaContentIndex0);
2185 ASSERT_EQ(2u, candidates->count());
2186 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2187 // Username and password have be updated with the TransportInfo of the
2188 // SessionDescription, won't be equal to the original one.
2189 candidate2.set_username(candidates->at(0)->candidate().username());
2190 candidate2.set_password(candidates->at(0)->candidate().password());
2191 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2192 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2193 // No need to verify the username and password.
2194 candidate1.set_username(candidates->at(1)->candidate().username());
2195 candidate1.set_password(candidates->at(1)->candidate().password());
2196 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2197
2198 // Test that the candidate is ignored if we can add the same candidate again.
2199 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2200}
2201
2202// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002203// that they are retained if the local session description is changed. And if
2204// continual gathering is enabled, they are removed from the local session
2205// description when the network is down.
2206TEST_F(WebRtcSessionTest,
2207 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002208 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002209 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002210 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211 CreateAndSetRemoteOfferAndLocalAnswer();
2212
2213 const SessionDescriptionInterface* local_desc = session_->local_description();
2214 const IceCandidateCollection* candidates =
2215 local_desc->candidates(kMediaContentIndex0);
2216 ASSERT_TRUE(candidates != NULL);
2217 EXPECT_EQ(0u, candidates->count());
2218
2219 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2220
2221 local_desc = session_->local_description();
2222 candidates = local_desc->candidates(kMediaContentIndex0);
2223 ASSERT_TRUE(candidates != NULL);
2224 EXPECT_LT(0u, candidates->count());
2225 candidates = local_desc->candidates(1);
2226 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002227 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228
2229 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002230 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 CreateAndSetRemoteOfferAndLocalAnswer();
2232
2233 local_desc = session_->local_description();
2234 candidates = local_desc->candidates(kMediaContentIndex0);
2235 ASSERT_TRUE(candidates != NULL);
2236 EXPECT_LT(0u, candidates->count());
2237 candidates = local_desc->candidates(1);
2238 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002239 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002240
2241 candidates = local_desc->candidates(kMediaContentIndex0);
2242 size_t num_local_candidates = candidates->count();
2243 // Enable Continual Gathering
Honghai Zhang5622c5e2016-07-01 13:59:29 -07002244 cricket::IceConfig config;
2245 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2246 session_->SetIceConfig(config);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002247 // Bring down the network interface to trigger candidate removals.
2248 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2249 // Verify that all local candidates are removed.
2250 EXPECT_EQ(0, observer_.num_candidates_removed_);
2251 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2252 kIceCandidatesTimeout);
2253 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2254}
2255
2256// Tests that if continual gathering is disabled, local candidates won't be
2257// removed when the interface is turned down.
2258TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2259 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2260 Init();
2261 SendAudioVideoStream1();
2262 CreateAndSetRemoteOfferAndLocalAnswer();
2263
2264 const SessionDescriptionInterface* local_desc = session_->local_description();
2265 const IceCandidateCollection* candidates =
2266 local_desc->candidates(kMediaContentIndex0);
2267 ASSERT_TRUE(candidates != NULL);
2268 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2269
2270 size_t num_local_candidates = candidates->count();
2271 EXPECT_LT(0u, num_local_candidates);
2272 // By default, Continual Gathering is disabled.
2273 // Bring down the network interface.
2274 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2275 // Verify that the local candidates are not removed.
2276 rtc::Thread::Current()->ProcessMessages(1000);
2277 EXPECT_EQ(0, observer_.num_candidates_removed_);
2278 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002279}
2280
2281// Test that we can set a remote session description with remote candidates.
2282TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002283 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284
2285 cricket::Candidate candidate1;
2286 candidate1.set_component(1);
2287 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2288 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002289 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002290 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291
2292 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2293 SetRemoteDescriptionWithoutError(offer);
2294
2295 const SessionDescriptionInterface* remote_desc =
2296 session_->remote_description();
2297 ASSERT_TRUE(remote_desc != NULL);
2298 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2299 const IceCandidateCollection* candidates =
2300 remote_desc->candidates(kMediaContentIndex0);
2301 ASSERT_EQ(1u, candidates->count());
2302 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2303
htaa2a49d92016-03-04 02:51:39 -08002304 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 SetLocalDescriptionWithoutError(answer);
2306}
2307
2308// Test that offers and answers contains ice candidates when Ice candidates have
2309// been gathered.
2310TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002311 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002312 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002313 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314 // Ice is started but candidates are not provided until SetLocalDescription
2315 // is called.
2316 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2317 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2318 CreateAndSetRemoteOfferAndLocalAnswer();
2319 // Wait until at least one local candidate has been collected.
2320 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2321 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322
kwibergd1fe2812016-04-27 06:47:29 -07002323 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002324
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002325 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2326 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327
2328 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2329 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002330 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2332 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333 SetLocalDescriptionWithoutError(answer);
2334}
2335
2336// Verifies TransportProxy and media channels are created with content names
2337// present in the SessionDescription.
2338TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002339 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002340 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002341 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342
2343 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002344 // "video". Goal is to modify these content names and verify transport
2345 // channels
2346 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347 // present in SDP.
2348 std::string sdp;
2349 EXPECT_TRUE(offer->ToString(&sdp));
2350 const std::string kAudioMid = "a=mid:audio";
2351 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2352 const std::string kVideoMid = "a=mid:video";
2353 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2354
2355 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002356 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357 kAudioMidReplaceStr.c_str(),
2358 kAudioMidReplaceStr.length(),
2359 &sdp);
2360 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002361 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362 kVideoMidReplaceStr.c_str(),
2363 kVideoMidReplaceStr.length(),
2364 &sdp);
2365
2366 SessionDescriptionInterface* modified_offer =
2367 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2368
2369 SetRemoteDescriptionWithoutError(modified_offer);
2370
htaa2a49d92016-03-04 02:51:39 -08002371 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002372 SetLocalDescriptionWithoutError(answer);
2373
deadbeefcbecd352015-09-23 11:50:27 -07002374 cricket::TransportChannel* voice_transport_channel =
2375 session_->voice_rtp_transport_channel();
2376 EXPECT_TRUE(voice_transport_channel != NULL);
2377 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2378 cricket::TransportChannel* video_transport_channel =
2379 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002380 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002381 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2383 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2384}
2385
2386// Test that an offer contains the correct media content descriptions based on
2387// the send streams when no constraints have been set.
2388TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002389 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002390 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002391
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002392 ASSERT_TRUE(offer != NULL);
2393 const cricket::ContentInfo* content =
2394 cricket::GetFirstAudioContent(offer->description());
2395 EXPECT_TRUE(content != NULL);
2396 content = cricket::GetFirstVideoContent(offer->description());
2397 EXPECT_TRUE(content == NULL);
2398}
2399
2400// Test that an offer contains the correct media content descriptions based on
2401// the send streams when no constraints have been set.
2402TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002403 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002405 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002406 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002407
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408 const cricket::ContentInfo* content =
2409 cricket::GetFirstAudioContent(offer->description());
2410 EXPECT_TRUE(content != NULL);
2411 content = cricket::GetFirstVideoContent(offer->description());
2412 EXPECT_TRUE(content == NULL);
2413
2414 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002415 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002416 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002417 content = cricket::GetFirstAudioContent(offer->description());
2418 EXPECT_TRUE(content != NULL);
2419 content = cricket::GetFirstVideoContent(offer->description());
2420 EXPECT_TRUE(content != NULL);
2421}
2422
2423// Test that an offer contains no media content descriptions if
2424// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2425TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002426 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002427 PeerConnectionInterface::RTCOfferAnswerOptions options;
2428 options.offer_to_receive_audio = 0;
2429 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430
kwibergd1fe2812016-04-27 06:47:29 -07002431 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002432
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 ASSERT_TRUE(offer != NULL);
2434 const cricket::ContentInfo* content =
2435 cricket::GetFirstAudioContent(offer->description());
2436 EXPECT_TRUE(content == NULL);
2437 content = cricket::GetFirstVideoContent(offer->description());
2438 EXPECT_TRUE(content == NULL);
2439}
2440
2441// Test that an offer contains only audio media content descriptions if
2442// kOfferToReceiveAudio constraints are set to true.
2443TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002444 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002445 PeerConnectionInterface::RTCOfferAnswerOptions options;
2446 options.offer_to_receive_audio =
2447 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2448
kwibergd1fe2812016-04-27 06:47:29 -07002449 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002450
2451 const cricket::ContentInfo* content =
2452 cricket::GetFirstAudioContent(offer->description());
2453 EXPECT_TRUE(content != NULL);
2454 content = cricket::GetFirstVideoContent(offer->description());
2455 EXPECT_TRUE(content == NULL);
2456}
2457
2458// Test that an offer contains audio and video media content descriptions if
2459// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2460TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002461 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002463 PeerConnectionInterface::RTCOfferAnswerOptions options;
2464 options.offer_to_receive_audio =
2465 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2466 options.offer_to_receive_video =
2467 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2468
kwibergd1fe2812016-04-27 06:47:29 -07002469 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002470
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471 const cricket::ContentInfo* content =
2472 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002473 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002474
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475 content = cricket::GetFirstVideoContent(offer->description());
2476 EXPECT_TRUE(content != NULL);
2477
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002478 // Sets constraints to false and verifies that audio/video contents are
2479 // removed.
2480 options.offer_to_receive_audio = 0;
2481 options.offer_to_receive_video = 0;
2482 offer.reset(CreateOffer(options));
2483
2484 content = cricket::GetFirstAudioContent(offer->description());
2485 EXPECT_TRUE(content == NULL);
2486 content = cricket::GetFirstVideoContent(offer->description());
2487 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002488}
2489
2490// Test that an answer can not be created if the last remote description is not
2491// an offer.
2492TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002493 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002494 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495 SetLocalDescriptionWithoutError(offer);
2496 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2497 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002498 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002499}
2500
2501// Test that an answer contains the correct media content descriptions when no
2502// constraints have been set.
2503TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002504 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002505 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002506 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002507 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002508 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002509 const cricket::ContentInfo* content =
2510 cricket::GetFirstAudioContent(answer->description());
2511 ASSERT_TRUE(content != NULL);
2512 EXPECT_FALSE(content->rejected);
2513
2514 content = cricket::GetFirstVideoContent(answer->description());
2515 ASSERT_TRUE(content != NULL);
2516 EXPECT_FALSE(content->rejected);
2517}
2518
2519// Test that an answer contains the correct media content descriptions when no
2520// constraints have been set and the offer only contain audio.
2521TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002522 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002523 // Create a remote offer with audio only.
2524 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002525
kwibergd1fe2812016-04-27 06:47:29 -07002526 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002527 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2528 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2529
2530 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002531 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532 const cricket::ContentInfo* content =
2533 cricket::GetFirstAudioContent(answer->description());
2534 ASSERT_TRUE(content != NULL);
2535 EXPECT_FALSE(content->rejected);
2536
2537 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2538}
2539
2540// Test that an answer contains the correct media content descriptions when no
2541// constraints have been set.
2542TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002543 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002545 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 SetRemoteDescriptionWithoutError(offer.release());
2547 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002548 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002549 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002550 const cricket::ContentInfo* content =
2551 cricket::GetFirstAudioContent(answer->description());
2552 ASSERT_TRUE(content != NULL);
2553 EXPECT_FALSE(content->rejected);
2554
2555 content = cricket::GetFirstVideoContent(answer->description());
2556 ASSERT_TRUE(content != NULL);
2557 EXPECT_FALSE(content->rejected);
2558}
2559
2560// Test that an answer contains the correct media content descriptions when
2561// constraints have been set but no stream is sent.
2562TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002563 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002564 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002565 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566 SetRemoteDescriptionWithoutError(offer.release());
2567
htaa2a49d92016-03-04 02:51:39 -08002568 cricket::MediaSessionOptions session_options;
2569 session_options.recv_audio = false;
2570 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002571 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002572 CreateAnswer(session_options));
2573
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002574 const cricket::ContentInfo* content =
2575 cricket::GetFirstAudioContent(answer->description());
2576 ASSERT_TRUE(content != NULL);
2577 EXPECT_TRUE(content->rejected);
2578
2579 content = cricket::GetFirstVideoContent(answer->description());
2580 ASSERT_TRUE(content != NULL);
2581 EXPECT_TRUE(content->rejected);
2582}
2583
2584// Test that an answer contains the correct media content descriptions when
2585// constraints have been set and streams are sent.
2586TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002587 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002588 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002589 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002590 SetRemoteDescriptionWithoutError(offer.release());
2591
htaa2a49d92016-03-04 02:51:39 -08002592 cricket::MediaSessionOptions options;
2593 options.recv_audio = false;
2594 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002595
2596 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002597 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002598 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002599
2600 // TODO(perkj): Should the direction be set to SEND_ONLY?
2601 const cricket::ContentInfo* content =
2602 cricket::GetFirstAudioContent(answer->description());
2603 ASSERT_TRUE(content != NULL);
2604 EXPECT_FALSE(content->rejected);
2605
2606 // TODO(perkj): Should the direction be set to SEND_ONLY?
2607 content = cricket::GetFirstVideoContent(answer->description());
2608 ASSERT_TRUE(content != NULL);
2609 EXPECT_FALSE(content->rejected);
2610}
2611
2612TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2613 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002614 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002615 PeerConnectionInterface::RTCOfferAnswerOptions options;
2616 options.offer_to_receive_audio =
2617 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2618 options.voice_activity_detection = false;
2619
kwibergd1fe2812016-04-27 06:47:29 -07002620 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002621
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002622 const cricket::ContentInfo* content =
2623 cricket::GetFirstAudioContent(offer->description());
2624 EXPECT_TRUE(content != NULL);
2625 EXPECT_TRUE(VerifyNoCNCodecs(content));
2626}
2627
2628TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2629 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002630 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002631 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002632 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002633 SetRemoteDescriptionWithoutError(offer.release());
2634
htaa2a49d92016-03-04 02:51:39 -08002635 cricket::MediaSessionOptions options;
2636 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002637 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002638 const cricket::ContentInfo* content =
2639 cricket::GetFirstAudioContent(answer->description());
2640 ASSERT_TRUE(content != NULL);
2641 EXPECT_TRUE(VerifyNoCNCodecs(content));
2642}
2643
2644// This test verifies the call setup when remote answer with audio only and
2645// later updates with video.
2646TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002647 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002648 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2649 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2650
deadbeefab9b2d12015-10-14 11:33:11 -07002651 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002652 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002653
2654 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002655 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2656
2657 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2658 // and answer;
2659 SetLocalDescriptionWithoutError(offer);
2660 SetRemoteDescriptionWithoutError(answer);
2661
2662 video_channel_ = media_engine_->GetVideoChannel(0);
2663 voice_channel_ = media_engine_->GetVoiceChannel(0);
2664
2665 ASSERT_TRUE(video_channel_ == NULL);
2666
2667 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2668 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2669 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2670
2671 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002672 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002673 CreateAndSetRemoteOfferAndLocalAnswer();
2674
2675 video_channel_ = media_engine_->GetVideoChannel(0);
2676 voice_channel_ = media_engine_->GetVoiceChannel(0);
2677
2678 ASSERT_TRUE(video_channel_ != NULL);
2679 ASSERT_TRUE(voice_channel_ != NULL);
2680
2681 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2682 ASSERT_EQ(1u, video_channel_->send_streams().size());
2683 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2684 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2685 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2686 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2687 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2688 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2689
2690 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002691 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002692 CreateAndSetRemoteOfferAndLocalAnswer();
2693
2694 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2695 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2696 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2697 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2698 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2699}
2700
2701// This test verifies the call setup when remote answer with video only and
2702// later updates with audio.
2703TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002704 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002705 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2706 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002707 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002708 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002709
2710 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002711 options.recv_audio = false;
2712 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002713 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2714 offer, options, cricket::SEC_ENABLED);
2715
2716 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2717 // and answer.
2718 SetLocalDescriptionWithoutError(offer);
2719 SetRemoteDescriptionWithoutError(answer);
2720
2721 video_channel_ = media_engine_->GetVideoChannel(0);
2722 voice_channel_ = media_engine_->GetVoiceChannel(0);
2723
2724 ASSERT_TRUE(voice_channel_ == NULL);
2725 ASSERT_TRUE(video_channel_ != NULL);
2726
2727 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2728 ASSERT_EQ(1u, video_channel_->send_streams().size());
2729 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2730
2731 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002732 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002733 CreateAndSetRemoteOfferAndLocalAnswer();
2734
2735 voice_channel_ = media_engine_->GetVoiceChannel(0);
2736 ASSERT_TRUE(voice_channel_ != NULL);
2737
2738 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2739 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2740 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2741 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2742
2743 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002744 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002745 CreateAndSetRemoteOfferAndLocalAnswer();
2746
2747 video_channel_ = media_engine_->GetVideoChannel(0);
2748 voice_channel_ = media_engine_->GetVoiceChannel(0);
2749
2750 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2751 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2752 ASSERT_EQ(1u, video_channel_->send_streams().size());
2753 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2754}
2755
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002756TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002757 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002758 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002759 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002760 VerifyCryptoParams(offer->description());
2761 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002762 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002763 VerifyCryptoParams(answer->description());
2764}
2765
2766TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002767 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002768 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002769 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002770 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002771 VerifyNoCryptoParams(offer->description(), false);
2772}
2773
2774TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002775 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002776 VerifyAnswerFromNonCryptoOffer();
2777}
2778
2779TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002780 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002781 VerifyAnswerFromCryptoOffer();
2782}
2783
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002784// This test verifies that setLocalDescription fails if
2785// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2786TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002787 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002788 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002789 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002790
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002791 std::string sdp;
2792 RemoveIceUfragPwdLines(offer.get(), &sdp);
2793 SessionDescriptionInterface* modified_offer =
2794 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002795 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002796}
2797
2798// This test verifies that setRemoteDescription fails if
2799// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2800TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002801 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002802 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002803 std::string sdp;
2804 RemoveIceUfragPwdLines(offer.get(), &sdp);
2805 SessionDescriptionInterface* modified_offer =
2806 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002807 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002808}
2809
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002810// This test verifies that setLocalDescription fails if local offer has
2811// too short ice ufrag and pwd strings.
2812TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002813 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002814 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002815 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002816 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2817 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002818 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002819 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002820 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002821
2822 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002823 offer.reset(CreateOffer());
2824 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2825 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002826}
2827
2828// This test verifies that setRemoteDescription fails if remote offer has
2829// too short ice ufrag and pwd strings.
2830TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002831 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002832 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002833 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2834 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002835 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002836 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002837 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002838
deadbeef0ed85b22016-02-23 17:24:52 -08002839 offer.reset(CreateRemoteOffer());
2840 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2841 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002842}
2843
Honghai Zhang04e91462015-12-11 14:26:22 -08002844// Test that if the remote offer indicates the peer requested ICE restart (via
2845// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2846TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002847 Init();
honghaiz503726c2015-07-31 12:37:38 -07002848
2849 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002850 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002851 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002852 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2853 0, "", "", "relay", 0, "");
2854 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2855 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002856 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2857 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002858 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2859
2860 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002861 offer.reset(CreateRemoteOffer());
2862 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002863 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2864 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2865 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002866 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2867 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002868 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2869
2870 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002871 offer.reset(CreateRemoteOffer());
2872 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002873 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2874 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2875 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002876 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2877 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002878 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2879
2880 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002881 offer.reset(CreateRemoteOffer());
2882 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2883 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002884 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2885}
2886
Honghai Zhang04e91462015-12-11 14:26:22 -08002887// Test that if the remote answer indicates the peer requested ICE restart (via
2888// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2889TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2890 Init();
2891 SessionDescriptionInterface* offer = CreateOffer();
2892 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002893
2894 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002895 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002896 answer->set_type(JsepSessionDescription::kPrAnswer);
2897 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002898 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2899 0, "", "", "relay", 0, "");
2900 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2901 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002902 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2903 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002904 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2905
2906 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002907 answer.reset(CreateRemoteAnswer(offer));
2908 answer->set_type(JsepSessionDescription::kPrAnswer);
2909 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002910 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(answer->AddCandidate(&ice_candidate2));
2914 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002915 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2916
2917 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002918 answer.reset(CreateRemoteAnswer(offer));
2919 answer->set_type(JsepSessionDescription::kPrAnswer);
2920 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002921 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2922 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2923 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002924 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2925 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002926 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2927
2928 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002929 answer.reset(CreateRemoteAnswer(offer));
2930 answer->set_type(JsepSessionDescription::kPrAnswer);
2931 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2932 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002933 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2934}
2935
Donald Curtisd4f769d2015-05-28 09:48:21 -07002936// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002937// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002938TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2939 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2940
2941 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002942 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002943
2944 PeerConnectionInterface::RTCOfferAnswerOptions options;
2945 options.use_rtp_mux = true;
2946
2947 SessionDescriptionInterface* offer = CreateRemoteOffer();
2948 SetRemoteDescriptionWithoutError(offer);
2949
htaa2a49d92016-03-04 02:51:39 -08002950 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002951 SetLocalDescriptionWithoutError(answer);
2952
deadbeefcbecd352015-09-23 11:50:27 -07002953 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2954 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002955
deadbeefcbecd352015-09-23 11:50:27 -07002956 cricket::BaseChannel* voice_channel = session_->voice_channel();
2957 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002958
2959 // Checks if one of the transport channels contains a connection using a given
2960 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002961 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002962 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002963 session_->GetChannelTransportStats(voice_channel, &stats);
2964 for (auto& kv : stats.transport_stats) {
2965 for (auto& chan_stat : kv.second.channel_stats) {
2966 for (auto& conn_info : chan_stat.connection_infos) {
2967 if (conn_info.remote_candidate.address().port() == port) {
2968 return true;
2969 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002970 }
2971 }
2972 }
2973 return false;
2974 };
2975
2976 EXPECT_FALSE(connection_with_remote_port(5000));
2977 EXPECT_FALSE(connection_with_remote_port(5001));
2978 EXPECT_FALSE(connection_with_remote_port(6000));
2979
2980 // The way the *_WAIT checks work is they only wait if the condition fails,
2981 // which does not help in the case where state is not changing. This is
2982 // problematic in this test since we want to verify that adding a video
2983 // candidate does _not_ change state. So we interleave candidates and assume
2984 // that messages are executed in the order they were posted.
2985
2986 // First audio candidate.
2987 cricket::Candidate candidate0;
2988 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2989 candidate0.set_component(1);
2990 candidate0.set_protocol("udp");
2991 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2992 candidate0);
2993 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2994
2995 // Video candidate.
2996 cricket::Candidate candidate1;
2997 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2998 candidate1.set_component(1);
2999 candidate1.set_protocol("udp");
3000 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3001 candidate1);
3002 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3003
3004 // Second audio candidate.
3005 cricket::Candidate candidate2;
3006 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3007 candidate2.set_component(1);
3008 candidate2.set_protocol("udp");
3009 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3010 candidate2);
3011 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3012
3013 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3014 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3015
3016 // No need here for a _WAIT check since we are checking that state hasn't
3017 // changed: if this is false we would be doing waits for nothing and if this
3018 // is true then there will be no messages processed anyways.
3019 EXPECT_FALSE(connection_with_remote_port(6000));
3020}
3021
deadbeefcbecd352015-09-23 11:50:27 -07003022// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003023TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3024 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003025 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003026
3027 PeerConnectionInterface::RTCOfferAnswerOptions options;
3028 options.use_rtp_mux = true;
3029
3030 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003031 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003032
deadbeefcbecd352015-09-23 11:50:27 -07003033 EXPECT_NE(session_->voice_rtp_transport_channel(),
3034 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003035
deadbeefab9b2d12015-10-14 11:33:11 -07003036 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003037 SessionDescriptionInterface* answer =
3038 CreateRemoteAnswer(session_->local_description());
3039 SetRemoteDescriptionWithoutError(answer);
3040
deadbeefcbecd352015-09-23 11:50:27 -07003041 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3042 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003043}
3044
deadbeefcbecd352015-09-23 11:50:27 -07003045// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003046TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3047 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003048 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003049
Donald Curtis0e209b02015-03-24 09:29:54 -07003050 PeerConnectionInterface::RTCOfferAnswerOptions options;
3051 options.use_rtp_mux = true;
3052
3053 SessionDescriptionInterface* offer = CreateOffer(options);
3054 SetLocalDescriptionWithoutError(offer);
3055
deadbeefcbecd352015-09-23 11:50:27 -07003056 EXPECT_NE(session_->voice_rtp_transport_channel(),
3057 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003058
deadbeefab9b2d12015-10-14 11:33:11 -07003059 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003060
3061 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003062 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003063 CreateRemoteAnswer(session_->local_description()));
3064 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3065 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3066 JsepSessionDescription* modified_answer =
3067 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3068 modified_answer->Initialize(answer_copy, "1", "1");
3069 SetRemoteDescriptionWithoutError(modified_answer); //
3070
deadbeefcbecd352015-09-23 11:50:27 -07003071 EXPECT_NE(session_->voice_rtp_transport_channel(),
3072 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003073}
3074
3075// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3076TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3077 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003078 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003079
3080 PeerConnectionInterface::RTCOfferAnswerOptions options;
3081 options.use_rtp_mux = true;
3082
3083 SessionDescriptionInterface* offer = CreateOffer(options);
3084 SetLocalDescriptionWithoutError(offer);
3085
deadbeefcbecd352015-09-23 11:50:27 -07003086 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3087 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003088
deadbeefab9b2d12015-10-14 11:33:11 -07003089 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003090 SessionDescriptionInterface* answer =
3091 CreateRemoteAnswer(session_->local_description());
3092 SetRemoteDescriptionWithoutError(answer);
3093
deadbeefcbecd352015-09-23 11:50:27 -07003094 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3095 session_->video_rtp_transport_channel());
3096}
3097
3098// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3099// audio content in the answer.
3100TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3101 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003102 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003103
3104 PeerConnectionInterface::RTCOfferAnswerOptions options;
3105 options.use_rtp_mux = true;
3106
3107 SessionDescriptionInterface* offer = CreateOffer(options);
3108 SetLocalDescriptionWithoutError(offer);
3109
3110 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3111 session_->video_rtp_transport_channel());
3112
deadbeefab9b2d12015-10-14 11:33:11 -07003113 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003114 cricket::MediaSessionOptions recv_options;
3115 recv_options.recv_audio = false;
3116 recv_options.recv_video = true;
3117 SessionDescriptionInterface* answer =
3118 CreateRemoteAnswer(session_->local_description(), recv_options);
3119 SetRemoteDescriptionWithoutError(answer);
3120
deadbeefd59daf82015-10-14 15:02:44 -07003121 EXPECT_TRUE(nullptr == session_->voice_channel());
3122 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003123
deadbeefd59daf82015-10-14 15:02:44 -07003124 session_->Close();
3125 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3126 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3127 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3128 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003129}
3130
3131// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3132TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3133 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003134 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003135
Donald Curtis0e209b02015-03-24 09:29:54 -07003136 PeerConnectionInterface::RTCOfferAnswerOptions options;
3137 options.use_rtp_mux = true;
3138
3139 SessionDescriptionInterface* offer = CreateOffer(options);
3140 SetLocalDescriptionWithoutError(offer);
3141
deadbeefcbecd352015-09-23 11:50:27 -07003142 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3143 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003144
deadbeefab9b2d12015-10-14 11:33:11 -07003145 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003146
3147 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003148 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003149 CreateRemoteAnswer(session_->local_description()));
3150 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3151 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3152 JsepSessionDescription* modified_answer =
3153 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3154 modified_answer->Initialize(answer_copy, "1", "1");
3155 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003156
deadbeefcbecd352015-09-23 11:50:27 -07003157 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3158 session_->video_rtp_transport_channel());
3159}
3160
3161// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3162TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3163 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003164 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003165
3166 SessionDescriptionInterface* offer = CreateRemoteOffer();
3167 SetRemoteDescriptionWithoutError(offer);
3168
3169 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3170 session_->video_rtp_transport_channel());
3171
deadbeefab9b2d12015-10-14 11:33:11 -07003172 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003173 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003174 SetLocalDescriptionWithoutError(answer);
3175
3176 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3177 session_->video_rtp_transport_channel());
3178}
3179
3180// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3181TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3182 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003183 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003184
3185 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003186 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003187 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3188 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3189 JsepSessionDescription* modified_offer =
3190 new JsepSessionDescription(JsepSessionDescription::kOffer);
3191 modified_offer->Initialize(offer_copy, "1", "1");
3192
3193 // Expect an error when applying the remote description
3194 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3195 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003196}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003197
Peter Thatcher4eddf182015-04-30 10:55:59 -07003198// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003199TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3200 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003201 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003202
Donald Curtis0e209b02015-03-24 09:29:54 -07003203 PeerConnectionInterface::RTCOfferAnswerOptions options;
3204 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003205
Donald Curtis0e209b02015-03-24 09:29:54 -07003206 SessionDescriptionInterface* offer = CreateOffer(options);
3207 SetLocalDescriptionWithoutError(offer);
3208
deadbeefcbecd352015-09-23 11:50:27 -07003209 EXPECT_NE(session_->voice_rtp_transport_channel(),
3210 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003211
deadbeefab9b2d12015-10-14 11:33:11 -07003212 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003213 SessionDescriptionInterface* answer =
3214 CreateRemoteAnswer(session_->local_description());
3215 SetRemoteDescriptionWithoutError(answer);
3216
3217 // This should lead to an audio-only call but isn't implemented
3218 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003219 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3220 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003221}
3222
deadbeefcbecd352015-09-23 11:50:27 -07003223// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003224TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3225 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003226 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003227 PeerConnectionInterface::RTCOfferAnswerOptions options;
3228 options.use_rtp_mux = true;
3229
3230 SessionDescriptionInterface* offer = CreateOffer(options);
3231 SetLocalDescriptionWithoutError(offer);
3232
deadbeefcbecd352015-09-23 11:50:27 -07003233 EXPECT_NE(session_->voice_rtp_transport_channel(),
3234 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003235
deadbeefab9b2d12015-10-14 11:33:11 -07003236 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003237
3238 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003239 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003240 CreateRemoteAnswer(session_->local_description()));
3241 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3242 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3243 JsepSessionDescription* modified_answer =
3244 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3245 modified_answer->Initialize(answer_copy, "1", "1");
3246 SetRemoteDescriptionWithoutError(modified_answer); //
3247
deadbeefcbecd352015-09-23 11:50:27 -07003248 EXPECT_NE(session_->voice_rtp_transport_channel(),
3249 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003250}
3251
Peter Thatcher4eddf182015-04-30 10:55:59 -07003252// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3253TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3254 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003255 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003256
3257 PeerConnectionInterface::RTCOfferAnswerOptions options;
3258 options.use_rtp_mux = true;
3259
3260 SessionDescriptionInterface* offer = CreateOffer(options);
3261 SetRemoteDescriptionWithoutError(offer);
3262
deadbeefcbecd352015-09-23 11:50:27 -07003263 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3264 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003265}
3266
skvlad6c87a672016-05-17 17:49:52 -07003267// Adding a new channel to a BUNDLE which is already connected should directly
3268// assign the bundle transport to the channel, without first setting a
3269// disconnected non-bundle transport and then replacing it. The application
3270// should not receive any changes in the ICE state.
3271TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3272 LoopbackNetworkConfiguration config;
3273 LoopbackNetworkManager loopback_network_manager(this, config);
3274 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3275 // connected. Disabling either of these two means that we need to wait for the
3276 // answer to find out if more transports are needed.
3277 configuration_.bundle_policy =
3278 PeerConnectionInterface::kBundlePolicyMaxBundle;
3279 configuration_.rtcp_mux_policy =
3280 PeerConnectionInterface::kRtcpMuxPolicyRequire;
3281 options_.disable_encryption = true;
3282 Init();
3283
3284 // Negotiate an audio channel with MAX_BUNDLE enabled.
3285 SendAudioOnlyStream2();
3286 SessionDescriptionInterface* offer = CreateOffer();
3287 SetLocalDescriptionWithoutError(offer);
3288 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3289 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3290 std::string sdp;
3291 offer->ToString(&sdp);
3292 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3293 JsepSessionDescription::kAnswer, sdp, nullptr);
3294 ASSERT_TRUE(answer != NULL);
3295 SetRemoteDescriptionWithoutError(answer);
3296
3297 // Wait for the ICE state to stabilize.
3298 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3299 observer_.ice_connection_state_, kIceCandidatesTimeout);
3300 observer_.ice_connection_state_history_.clear();
3301
3302 // Now add a video channel which should be using the same bundle transport.
3303 SendAudioVideoStream2();
3304 offer = CreateOffer();
3305 offer->ToString(&sdp);
3306 SetLocalDescriptionWithoutError(offer);
3307 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3308 sdp, nullptr);
3309 ASSERT_TRUE(answer != NULL);
3310 SetRemoteDescriptionWithoutError(answer);
3311
3312 // Wait for ICE state to stabilize
3313 rtc::Thread::Current()->ProcessMessages(0);
3314 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3315 observer_.ice_connection_state_, kIceCandidatesTimeout);
3316
3317 // No ICE state changes are expected to happen.
3318 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3319}
3320
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003321TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3322 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003323 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003324
3325 PeerConnectionInterface::RTCOfferAnswerOptions options;
3326 SessionDescriptionInterface* offer = CreateOffer(options);
3327 SetLocalDescriptionWithoutError(offer);
3328
deadbeefcbecd352015-09-23 11:50:27 -07003329 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3330 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003331
deadbeefab9b2d12015-10-14 11:33:11 -07003332 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003333 SessionDescriptionInterface* answer =
3334 CreateRemoteAnswer(session_->local_description());
3335 SetRemoteDescriptionWithoutError(answer);
3336
deadbeefcbecd352015-09-23 11:50:27 -07003337 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3338 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003339}
3340
3341TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3342 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003343 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003344
3345 PeerConnectionInterface::RTCOfferAnswerOptions options;
3346 SessionDescriptionInterface* offer = CreateOffer(options);
3347 SetLocalDescriptionWithoutError(offer);
3348
deadbeefcbecd352015-09-23 11:50:27 -07003349 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3350 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003351
deadbeefab9b2d12015-10-14 11:33:11 -07003352 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003353 SessionDescriptionInterface* answer =
3354 CreateRemoteAnswer(session_->local_description());
3355 SetRemoteDescriptionWithoutError(answer);
3356
deadbeefcbecd352015-09-23 11:50:27 -07003357 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3358 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003359}
3360
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003361// This test verifies that SetLocalDescription and SetRemoteDescription fails
3362// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3363TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003364 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003365 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003366
3367 PeerConnectionInterface::RTCOfferAnswerOptions options;
3368 options.use_rtp_mux = true;
3369
3370 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003371 std::string offer_str;
3372 offer->ToString(&offer_str);
3373 // Disable rtcp-mux
3374 const std::string rtcp_mux = "rtcp-mux";
3375 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003376 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003377 xrtcp_mux.c_str(), xrtcp_mux.length(),
3378 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003379 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003380 new JsepSessionDescription(JsepSessionDescription::kOffer);
3381 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003382 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003383 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003384 new JsepSessionDescription(JsepSessionDescription::kOffer);
3385 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003386 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003387 // Trying unmodified SDP.
3388 SetLocalDescriptionWithoutError(offer);
3389}
3390
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003391TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3392 TestCanInsertDtmf(false);
3393}
3394
3395TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3396 TestCanInsertDtmf(true);
3397}
3398
3399TEST_F(WebRtcSessionTest, InsertDtmf) {
3400 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003401 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003402 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003403 CreateAndSetRemoteOfferAndLocalAnswer();
3404 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3405 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3406
3407 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003408 const int expected_duration = 90;
3409 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3410 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3411 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3412
3413 // Verify
3414 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003415 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003416 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003417 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003418 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003419 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003420 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003421 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003422}
3423
deadbeefd59daf82015-10-14 15:02:44 -07003424// This test verifies the |initial_offerer| flag when session initiates the
3425// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003426TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003427 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003428 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003429 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003430 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3431 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003432 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003433 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003434 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003435}
3436
deadbeefd59daf82015-10-14 15:02:44 -07003437// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003439 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003440 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003441 SessionDescriptionInterface* offer = CreateRemoteOffer();
3442 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003443 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003444
deadbeefd59daf82015-10-14 15:02:44 -07003445 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003446 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003447 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003448}
3449
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003450// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3451TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003452 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003453 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003454 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003455 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003456 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003457 CreateRemoteAnswer(session_->local_description()));
3458
3459 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3460 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003461 JsepSessionDescription* modified_answer =
3462 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003463
3464 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3465 answer->session_id(),
3466 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003467 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003468
wu@webrtc.org4e393072014-04-07 17:04:35 +00003469 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003470 std::string sdp;
3471 EXPECT_TRUE(answer->ToString(&sdp));
3472 const std::string kAudioMid = "a=mid:audio";
3473 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003474 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003475 kAudioMidReplaceStr.c_str(),
3476 kAudioMidReplaceStr.length(),
3477 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003478 SessionDescriptionInterface* modified_answer1 =
3479 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003480 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003481
wu@webrtc.org4e393072014-04-07 17:04:35 +00003482 // Different media types.
3483 EXPECT_TRUE(answer->ToString(&sdp));
3484 const std::string kAudioMline = "m=audio";
3485 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003486 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003487 kAudioMlineReplaceStr.c_str(),
3488 kAudioMlineReplaceStr.length(),
3489 &sdp);
3490 SessionDescriptionInterface* modified_answer2 =
3491 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3492 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3493
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003494 SetRemoteDescriptionWithoutError(answer.release());
3495}
3496
3497// Verifying remote offer and local answer have matching m-lines as per
3498// RFC 3264.
3499TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003500 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003501 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003502 SessionDescriptionInterface* offer = CreateRemoteOffer();
3503 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003504 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003505
3506 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3507 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003508 JsepSessionDescription* modified_answer =
3509 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003510
3511 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3512 answer->session_id(),
3513 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003514 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003515 SetLocalDescriptionWithoutError(answer);
3516}
3517
3518// This test verifies that WebRtcSession does not start candidate allocation
3519// before SetLocalDescription is called.
3520TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003521 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003522 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003523 SessionDescriptionInterface* offer = CreateRemoteOffer();
3524 cricket::Candidate candidate;
3525 candidate.set_component(1);
3526 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3527 candidate);
3528 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3529 cricket::Candidate candidate1;
3530 candidate1.set_component(1);
3531 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3532 candidate1);
3533 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3534 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003535 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3536 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003537
3538 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003539 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003540 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3541 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3542
htaa2a49d92016-03-04 02:51:39 -08003543 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003544 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003545 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3546}
3547
3548// This test verifies that crypto parameter is updated in local session
3549// description as per security policy set in MediaSessionDescriptionFactory.
3550TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003551 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003552 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003553 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003554
3555 // Making sure SetLocalDescription correctly sets crypto value in
3556 // SessionDescription object after de-serialization of sdp string. The value
3557 // will be set as per MediaSessionDescriptionFactory.
3558 std::string offer_str;
3559 offer->ToString(&offer_str);
3560 SessionDescriptionInterface* jsep_offer_str =
3561 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3562 SetLocalDescriptionWithoutError(jsep_offer_str);
3563 EXPECT_TRUE(session_->voice_channel()->secure_required());
3564 EXPECT_TRUE(session_->video_channel()->secure_required());
3565}
3566
3567// This test verifies the crypto parameter when security is disabled.
3568TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003569 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003570 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003571 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003572 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003573
3574 // Making sure SetLocalDescription correctly sets crypto value in
3575 // SessionDescription object after de-serialization of sdp string. The value
3576 // will be set as per MediaSessionDescriptionFactory.
3577 std::string offer_str;
3578 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003579 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3581 SetLocalDescriptionWithoutError(jsep_offer_str);
3582 EXPECT_FALSE(session_->voice_channel()->secure_required());
3583 EXPECT_FALSE(session_->video_channel()->secure_required());
3584}
3585
3586// This test verifies that an answer contains new ufrag and password if an offer
3587// with new ufrag and password is received.
3588TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003589 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003590 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003591 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003592 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003593 SetRemoteDescriptionWithoutError(offer.release());
3594
deadbeefab9b2d12015-10-14 11:33:11 -07003595 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003596 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003597 SetLocalDescriptionWithoutError(answer.release());
3598
3599 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003600 for (const cricket::ContentInfo& content :
3601 session_->local_description()->description()->contents()) {
3602 options.transport_options[content.name].ice_restart = true;
3603 }
kwibergd1fe2812016-04-27 06:47:29 -07003604 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003605 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003606 SetRemoteDescriptionWithoutError(updated_offer1.release());
3607
kwibergd1fe2812016-04-27 06:47:29 -07003608 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003609
deadbeef0ed85b22016-02-23 17:24:52 -08003610 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3611 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003612
deadbeef0ed85b22016-02-23 17:24:52 -08003613 // Even a second answer (created before the description is set) should have
3614 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003615 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003616
3617 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3618 session_->local_description()->description()));
3619
3620 SetLocalDescriptionWithoutError(updated_answer2.release());
3621}
3622
3623// This test verifies that an answer contains new ufrag and password if an offer
3624// that changes either the ufrag or password (but not both) is received.
3625// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3626// a=ice-pwd attributes compared to the previous SDP from the peer, it
3627// indicates that ICE is restarting for this media stream."
3628TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3629 Init();
3630 cricket::MediaSessionOptions options;
3631 options.recv_audio = true;
3632 options.recv_video = true;
3633 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003634 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003635 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3636 SetRemoteDescriptionWithoutError(offer.release());
3637
3638 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003639 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003640 SetLocalDescriptionWithoutError(answer.release());
3641
3642 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003643 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003644 CreateRemoteOffer(options, session_->remote_description()));
3645 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3646 "original_password12345");
3647 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3648
kwibergd1fe2812016-04-27 06:47:29 -07003649 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003650 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3651 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003652 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003653
3654 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003655 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003656 CreateRemoteOffer(options, session_->remote_description()));
3657 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3658 "modified_password12345");
3659 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3660
kwibergd1fe2812016-04-27 06:47:29 -07003661 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003662 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3663 session_->local_description()->description()));
3664 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003665}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003666
wu@webrtc.org91053e72013-08-10 07:18:04 +00003667// This test verifies that an answer contains old ufrag and password if an offer
3668// with old ufrag and password is received.
3669TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003670 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003671 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003672 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003673 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003674 SetRemoteDescriptionWithoutError(offer.release());
3675
deadbeefab9b2d12015-10-14 11:33:11 -07003676 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003677 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003678 SetLocalDescriptionWithoutError(answer.release());
3679
3680 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003681 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003682 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003683 SetRemoteDescriptionWithoutError(updated_offer2.release());
3684
kwibergd1fe2812016-04-27 06:47:29 -07003685 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003686
deadbeef0ed85b22016-02-23 17:24:52 -08003687 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3688 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003689
3690 SetLocalDescriptionWithoutError(updated_answer2.release());
3691}
3692
deadbeef0ed85b22016-02-23 17:24:52 -08003693// This test verifies that if an offer does an ICE restart on some, but not all
3694// media sections, the answer will change the ufrag/password in the correct
3695// media sections.
3696TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3697 Init();
3698 cricket::MediaSessionOptions options;
3699 options.recv_video = true;
3700 options.recv_audio = true;
3701 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003702 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003703
3704 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3705 "aaaaaaaaaaaaaaaaaaaaaa");
3706 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3707 "bbbbbbbbbbbbbbbbbbbbbb");
3708 SetRemoteDescriptionWithoutError(offer.release());
3709
3710 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003711 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003712 SetLocalDescriptionWithoutError(answer.release());
3713
3714 // Receive an offer with new ufrag and password, but only for the video media
3715 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003716 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003717 CreateRemoteOffer(options, session_->remote_description()));
3718 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3719 "cccccccccccccccccccccc");
3720 SetRemoteDescriptionWithoutError(updated_offer.release());
3721
kwibergd1fe2812016-04-27 06:47:29 -07003722 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003723
3724 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3725 session_->local_description()->description(),
3726 cricket::MEDIA_TYPE_AUDIO));
3727
3728 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3729 session_->local_description()->description(),
3730 cricket::MEDIA_TYPE_VIDEO));
3731
3732 SetLocalDescriptionWithoutError(updated_answer.release());
3733}
3734
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003735TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003736 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003737 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003738 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003739 const std::string session_id_orig = offer->session_id();
3740 const std::string session_version_orig = offer->session_version();
3741 SetLocalDescriptionWithoutError(offer);
3742
3743 video_channel_ = media_engine_->GetVideoChannel(0);
3744 video_channel_->set_fail_set_send_codecs(true);
3745
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003746 SessionDescriptionInterface* answer =
3747 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003748 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003749
3750 // Test that after a content error, setting any description will
3751 // result in an error.
3752 video_channel_->set_fail_set_send_codecs(false);
3753 answer = CreateRemoteAnswer(session_->local_description());
3754 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3755 offer = CreateRemoteOffer();
3756 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003757}
3758
3759// Runs the loopback call test with BUNDLE and STUN disabled.
3760TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3761 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003762 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003763 cricket::PORTALLOCATOR_DISABLE_STUN |
3764 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003765 TestLoopbackCall();
3766}
3767
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003768TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003769 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003770 cricket::PORTALLOCATOR_DISABLE_STUN |
3771 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3772 cricket::PORTALLOCATOR_DISABLE_RELAY);
3773
3774 // best connection is IPv6 since it has higher network preference.
3775 LoopbackNetworkConfiguration config;
3776 config.test_ipv6_network_ = true;
3777 config.best_connection_after_initial_ice_converged_ =
3778 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3779
3780 TestLoopbackCall(config);
3781}
3782
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003783// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003784TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003785 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3786 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003787 TestLoopbackCall();
3788}
3789
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003790TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003791 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003792 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003793 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003794 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003795 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3796}
3797
Henrik Boström87713d02015-08-25 09:53:21 +02003798TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003799 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003800
htaa2a49d92016-03-04 02:51:39 -08003801 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003802 options_.disable_sctp_data_channels = false;
3803
Henrik Boström87713d02015-08-25 09:53:21 +02003804 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003805
3806 SetLocalDescriptionWithDataChannel();
3807 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3808}
3809
Henrik Boström87713d02015-08-25 09:53:21 +02003810TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003811 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003812
Henrik Boström87713d02015-08-25 09:53:21 +02003813 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003814
kwibergd1fe2812016-04-27 06:47:29 -07003815 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003816 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003817 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3818}
3819
Henrik Boström87713d02015-08-25 09:53:21 +02003820TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003821 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003822 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003823 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003824
3825 // Create remote offer with SCTP.
3826 cricket::MediaSessionOptions options;
3827 options.data_channel_type = cricket::DCT_SCTP;
3828 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003829 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003830 SetRemoteDescriptionWithoutError(offer);
3831
3832 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003833 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003834 EXPECT_TRUE(answer != NULL);
3835 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3836 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003837}
3838
Henrik Boström87713d02015-08-25 09:53:21 +02003839TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003840 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003841 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003842
3843 SetLocalDescriptionWithDataChannel();
3844 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3845}
3846
Henrik Boström87713d02015-08-25 09:53:21 +02003847TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003848 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003849
Henrik Boström87713d02015-08-25 09:53:21 +02003850 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003851
3852 SetLocalDescriptionWithDataChannel();
3853 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3854}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003855
Henrik Boström87713d02015-08-25 09:53:21 +02003856TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003857 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003858 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003859 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003860
3861 SetLocalDescriptionWithDataChannel();
3862 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3863}
3864
Henrik Boström87713d02015-08-25 09:53:21 +02003865TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003866 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003867 const int new_send_port = 9998;
3868 const int new_recv_port = 7775;
3869
Henrik Boström87713d02015-08-25 09:53:21 +02003870 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003871 SetFactoryDtlsSrtp();
3872
3873 // By default, don't actually add the codecs to desc_factory_; they don't
3874 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3875 // let the session description get parsed. That'll get the proper codecs
3876 // into the stream.
3877 cricket::MediaSessionOptions options;
3878 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3879 "stream1", new_send_port, options);
3880
3881 // SetRemoteDescription will take the ownership of the offer.
3882 SetRemoteDescriptionWithoutError(offer);
3883
htaa2a49d92016-03-04 02:51:39 -08003884 SessionDescriptionInterface* answer =
3885 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003886 ASSERT_TRUE(answer != NULL);
3887
3888 // Now set the local description, which'll take ownership of the answer.
3889 SetLocalDescriptionWithoutError(answer);
3890
3891 // TEST PLAN: Set the port number to something new, set it in the SDP,
3892 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003893 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003894 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003895
3896 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3897 int portnum = -1;
3898 ASSERT_TRUE(ch != NULL);
3899 ASSERT_EQ(1UL, ch->send_codecs().size());
3900 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003901 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003902 ch->send_codecs()[0].name.c_str()));
3903 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3904 &portnum));
3905 EXPECT_EQ(new_send_port, portnum);
3906
3907 ASSERT_EQ(1UL, ch->recv_codecs().size());
3908 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003909 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003910 ch->recv_codecs()[0].name.c_str()));
3911 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3912 &portnum));
3913 EXPECT_EQ(new_recv_port, portnum);
3914}
3915
deadbeefab9b2d12015-10-14 11:33:11 -07003916// Verifies that when a session's DataChannel receives an OPEN message,
3917// WebRtcSession signals the DataChannel creation request with the expected
3918// config.
3919TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3920 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3921
3922 InitWithDtls(GetParam());
3923
3924 SetLocalDescriptionWithDataChannel();
3925 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3926
3927 webrtc::DataChannelInit config;
3928 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07003929 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07003930 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3931 cricket::ReceiveDataParams params;
3932 params.ssrc = config.id;
3933 params.type = cricket::DMT_CONTROL;
3934
3935 cricket::DataChannel* data_channel = session_->data_channel();
3936 data_channel->SignalDataReceived(data_channel, params, payload);
3937
3938 EXPECT_EQ("a", last_data_channel_label_);
3939 EXPECT_EQ(config.id, last_data_channel_config_.id);
3940 EXPECT_FALSE(last_data_channel_config_.negotiated);
3941 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3942 last_data_channel_config_.open_handshake_role);
3943}
3944
3945TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003946 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02003947 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02003948
htaa2a49d92016-03-04 02:51:39 -08003949 configuration_.certificates.push_back(certificate);
3950 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02003951 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3952
3953 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3954}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003955
Henrik Boström87713d02015-08-25 09:53:21 +02003956// Verifies that CreateOffer succeeds when CreateOffer is called before async
3957// identity generation is finished (even if a certificate is provided this is
3958// an async op).
3959TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3960 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3961 InitWithDtls(GetParam());
3962
Henrik Boströmd8281982015-08-27 10:12:24 +02003963 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003964 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003965 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003966
wu@webrtc.org91053e72013-08-10 07:18:04 +00003967 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003968 VerifyNoCryptoParams(offer->description(), true);
3969 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003970}
3971
3972// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003973// identity generation is finished (even if a certificate is provided this is
3974// an async op).
3975TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003976 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003977 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003978 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003979
3980 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003981 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003982 std::unique_ptr<JsepSessionDescription> offer(
3983 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003984 ASSERT_TRUE(offer.get() != NULL);
3985 SetRemoteDescriptionWithoutError(offer.release());
3986
kwibergd1fe2812016-04-27 06:47:29 -07003987 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003988 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003989 VerifyNoCryptoParams(answer->description(), true);
3990 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003991}
3992
3993// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003994// identity generation is finished (even if a certificate is provided this is
3995// an async op).
3996TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003997 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003998 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003999
Henrik Boströmd8281982015-08-27 10:12:24 +02004000 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004001
kwibergd1fe2812016-04-27 06:47:29 -07004002 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004003 EXPECT_TRUE(offer != NULL);
4004}
4005
4006// Verifies that CreateOffer fails when CreateOffer is called after async
4007// identity generation fails.
4008TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004009 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004010 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004011
Henrik Boströmd8281982015-08-27 10:12:24 +02004012 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004013
kwibergd1fe2812016-04-27 06:47:29 -07004014 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004015 EXPECT_TRUE(offer == NULL);
4016}
4017
4018// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4019// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004020TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004021 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004022 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004023 VerifyMultipleAsyncCreateDescription(GetParam(),
4024 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004025}
4026
4027// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4028// before async identity generation fails.
4029TEST_F(WebRtcSessionTest,
4030 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004031 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004032 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4033 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004034}
4035
4036// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4037// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004038TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004039 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004040 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004041 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004042 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004043}
4044
4045// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4046// before async identity generation fails.
4047TEST_F(WebRtcSessionTest,
4048 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004049 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004050 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4051 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004052}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004053
4054// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4055// offer has no SDES crypto but only DTLS fingerprint.
4056TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4057 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004058 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004059 // Create a remote offer with secured transport disabled.
4060 cricket::MediaSessionOptions options;
4061 JsepSessionDescription* offer(CreateRemoteOffer(
4062 options, cricket::SEC_DISABLED));
4063 // Adds a DTLS fingerprint to the remote offer.
4064 cricket::SessionDescription* sdp = offer->description();
4065 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4066 ASSERT_TRUE(audio != NULL);
4067 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4068 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004069 rtc::SSLFingerprint::CreateFromRfc4572(
4070 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004071 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004072 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004073}
4074
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004075TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004076 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004077 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004078 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004079 SessionDescriptionInterface* offer = CreateOffer();
4080
4081 SetLocalDescriptionWithoutError(offer);
4082
4083 voice_channel_ = media_engine_->GetVoiceChannel(0);
4084
4085 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004086 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004087 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004088}
4089
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004090// Tests that we can renegotiate new media content with ICE candidates in the
4091// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004092TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004093 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004094 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004095 SetFactoryDtlsSrtp();
4096
deadbeefab9b2d12015-10-14 11:33:11 -07004097 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004098 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004099 SetLocalDescriptionWithoutError(offer);
4100
4101 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4102 SetRemoteDescriptionWithoutError(answer);
4103
4104 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004105 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004106 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4107
4108 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004109 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004110 candidate1.set_component(1);
4111 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4112 candidate1);
4113 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4114 SetRemoteDescriptionWithoutError(offer);
4115
htaa2a49d92016-03-04 02:51:39 -08004116 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004117 SetLocalDescriptionWithoutError(answer);
4118}
4119
4120// Tests that we can renegotiate new media content with ICE candidates separated
4121// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004122TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004123 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004124 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004125 SetFactoryDtlsSrtp();
4126
deadbeefab9b2d12015-10-14 11:33:11 -07004127 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004128 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004129 SetLocalDescriptionWithoutError(offer);
4130
4131 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4132 SetRemoteDescriptionWithoutError(answer);
4133
4134 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004135 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004136 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4137 SetRemoteDescriptionWithoutError(offer);
4138
4139 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004140 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004141 candidate1.set_component(1);
4142 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4143 candidate1);
4144 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4145
htaa2a49d92016-03-04 02:51:39 -08004146 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004147 SetLocalDescriptionWithoutError(answer);
4148}
honghaiz7f777492016-02-02 21:54:01 -08004149
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004150// Tests that RTX codec is removed from the answer when it isn't supported
4151// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004152TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004153 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004154 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004155 std::string offer_sdp(kSdpWithRtx);
4156
4157 SessionDescriptionInterface* offer =
4158 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4159 EXPECT_TRUE(offer->ToString(&offer_sdp));
4160
4161 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004162 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004163 SetRemoteDescriptionWithoutError(offer);
4164
htaa2a49d92016-03-04 02:51:39 -08004165 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004166 // Answer SDP does not contain the RTX codec.
4167 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004168 SetLocalDescriptionWithoutError(answer);
4169}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004170
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004171// This verifies that the voice channel after bundle has both options from video
4172// and voice channels.
4173TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4174 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004175 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004176
4177 PeerConnectionInterface::RTCOfferAnswerOptions options;
4178 options.use_rtp_mux = true;
4179
4180 SessionDescriptionInterface* offer = CreateOffer(options);
4181 SetLocalDescriptionWithoutError(offer);
4182
4183 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4184 rtc::Socket::Option::OPT_SNDBUF, 4000);
4185
4186 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4187 rtc::Socket::Option::OPT_RCVBUF, 8000);
4188
4189 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004190 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004191 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4192 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004193 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004194 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4195
deadbeefcbecd352015-09-23 11:50:27 -07004196 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004197 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4198 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004199 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004200 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4201
deadbeefcbecd352015-09-23 11:50:27 -07004202 EXPECT_NE(session_->voice_rtp_transport_channel(),
4203 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004204
deadbeefab9b2d12015-10-14 11:33:11 -07004205 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004206 SessionDescriptionInterface* answer =
4207 CreateRemoteAnswer(session_->local_description());
4208 SetRemoteDescriptionWithoutError(answer);
4209
deadbeefcbecd352015-09-23 11:50:27 -07004210 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004211 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4212 EXPECT_EQ(4000, option_val);
4213
deadbeefcbecd352015-09-23 11:50:27 -07004214 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004215 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4216 EXPECT_EQ(8000, option_val);
4217}
4218
tommi0f620f42015-07-09 03:25:02 -07004219// Test creating a session, request multiple offers, destroy the session
4220// and make sure we got success/failure callbacks for all of the requests.
4221// Background: crbug.com/507307
4222TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4223 Init();
4224
4225 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4226 PeerConnectionInterface::RTCOfferAnswerOptions options;
4227 options.offer_to_receive_audio =
4228 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004229 cricket::MediaSessionOptions session_options;
4230 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004231
4232 for (auto& o : observers) {
4233 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004234 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004235 }
4236
4237 session_.reset();
4238
tommi0f620f42015-07-09 03:25:02 -07004239 for (auto& o : observers) {
4240 // We expect to have received a notification now even if the session was
4241 // terminated. The offer creation may or may not have succeeded, but we
4242 // must have received a notification which, so the only invalid state
4243 // is kInit.
4244 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4245 }
4246}
4247
stefanc1aeaf02015-10-15 07:26:07 -07004248TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4249 TestPacketOptions();
4250}
4251
deadbeef057ecf02016-01-20 14:30:43 -08004252// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4253// is destroyed.
4254TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4255 Init();
4256 session_.reset();
4257 EXPECT_TRUE(session_destroyed_);
4258}
4259
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004260// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4261// currently fails because upon disconnection and reconnection OnIceComplete is
4262// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004263
deadbeefcbecd352015-09-23 11:50:27 -07004264INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4265 WebRtcSessionTest,
4266 testing::Values(ALREADY_GENERATED,
4267 DTLS_IDENTITY_STORE));