blob: 6c0170e70414e9dc501d730802a509c02f683dc8 [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:
zhihuang29ff8442016-07-27 11:07:25 -0700214 WebRtcSessionForTest(
215 webrtc::MediaControllerInterface* media_controller,
216 rtc::Thread* network_thread,
217 rtc::Thread* worker_thread,
218 rtc::Thread* signaling_thread,
219 cricket::PortAllocator* port_allocator,
220 webrtc::IceObserver* ice_observer,
221 std::unique_ptr<cricket::TransportController> transport_controller)
stefanc1aeaf02015-10-15 07:26:07 -0700222 : WebRtcSession(media_controller,
danilchape9021a32016-05-17 01:52:02 -0700223 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700224 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700225 signaling_thread,
zhihuang29ff8442016-07-27 11:07:25 -0700226 port_allocator,
227 std::move(transport_controller)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228 RegisterIceObserver(ice_observer);
229 }
230 virtual ~WebRtcSessionForTest() {}
231
deadbeefcbecd352015-09-23 11:50:27 -0700232 // Note that these methods are only safe to use if the signaling thread
233 // is the same as the worker thread
234 cricket::TransportChannel* voice_rtp_transport_channel() {
235 return rtp_transport_channel(voice_channel());
236 }
237
238 cricket::TransportChannel* voice_rtcp_transport_channel() {
239 return rtcp_transport_channel(voice_channel());
240 }
241
242 cricket::TransportChannel* video_rtp_transport_channel() {
243 return rtp_transport_channel(video_channel());
244 }
245
246 cricket::TransportChannel* video_rtcp_transport_channel() {
247 return rtcp_transport_channel(video_channel());
248 }
249
250 cricket::TransportChannel* data_rtp_transport_channel() {
251 return rtp_transport_channel(data_channel());
252 }
253
254 cricket::TransportChannel* data_rtcp_transport_channel() {
255 return rtcp_transport_channel(data_channel());
256 }
257
deadbeefcbecd352015-09-23 11:50:27 -0700258 private:
259 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
260 if (!ch) {
261 return nullptr;
262 }
263 return ch->transport_channel();
264 }
265
266 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
267 if (!ch) {
268 return nullptr;
269 }
270 return ch->rtcp_transport_channel();
271 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272};
273
wu@webrtc.org91053e72013-08-10 07:18:04 +0000274class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000275 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000276 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000277 enum State {
278 kInit,
279 kFailed,
280 kSucceeded,
281 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000282 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000283
284 // CreateSessionDescriptionObserver implementation.
285 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000286 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000287 state_ = kSucceeded;
288 }
289 virtual void OnFailure(const std::string& error) {
290 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000291 }
292
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000293 SessionDescriptionInterface* description() { return description_.get(); }
294
295 SessionDescriptionInterface* ReleaseDescription() {
296 return description_.release();
297 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298
wu@webrtc.org91053e72013-08-10 07:18:04 +0000299 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300
wu@webrtc.org91053e72013-08-10 07:18:04 +0000301 protected:
302 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303
304 private:
kwibergd1fe2812016-04-27 06:47:29 -0700305 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000306 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307};
308
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800309class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000310 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800311 FakeAudioSource() : sink_(NULL) {}
312 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000313 if (sink_)
314 sink_->OnClose();
315 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000316
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000317 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000318
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800319 const cricket::AudioSource::Sink* sink() const { return sink_; }
320
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000321 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800322 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000323};
324
Henrik Boström87713d02015-08-25 09:53:21 +0200325class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700326 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
327 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328 protected:
329 // TODO Investigate why ChannelManager crashes, if it's created
330 // after stun_server.
331 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700332 : media_engine_(new cricket::FakeMediaEngine()),
333 data_engine_(new cricket::FakeDataEngine()),
334 channel_manager_(
335 new cricket::ChannelManager(media_engine_,
336 data_engine_,
stefanc1aeaf02015-10-15 07:26:07 -0700337 rtc::Thread::Current())),
338 fake_call_(webrtc::Call::Config()),
339 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800340 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
341 rtc::Thread::Current(),
stefanc1aeaf02015-10-15 07:26:07 -0700342 channel_manager_.get())),
343 tdesc_factory_(new cricket::TransportDescriptionFactory()),
344 desc_factory_(
345 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
346 tdesc_factory_.get())),
347 pss_(new rtc::PhysicalSocketServer),
348 vss_(new rtc::VirtualSocketServer(pss_.get())),
349 fss_(new rtc::FirewallSocketServer(vss_.get())),
350 ss_scope_(fss_.get()),
351 stun_socket_addr_(
352 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
353 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
354 stun_socket_addr_)),
355 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
356 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000357 cricket::ServerAddresses stun_servers;
358 stun_servers.insert(stun_socket_addr_);
359 allocator_.reset(new cricket::BasicPortAllocator(
360 &network_manager_,
361 stun_servers,
362 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000363 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700364 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000365 EXPECT_TRUE(channel_manager_->Init());
366 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000367 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 }
369
370 void AddInterface(const SocketAddress& addr) {
371 network_manager_.AddInterface(addr);
372 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700373 void RemoveInterface(const SocketAddress& addr) {
374 network_manager_.RemoveInterface(addr);
375 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376
Henrik Boströmd79599d2016-06-01 13:58:50 +0200377 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
378 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
379 // options. When DTLS is enabled a certificate will be used if provided,
380 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000381 void Init(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200382 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383 ASSERT_TRUE(session_.get() == NULL);
384 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700385 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
zhihuang29ff8442016-07-27 11:07:25 -0700386 rtc::Thread::Current(), allocator_.get(), &observer_,
387 std::unique_ptr<cricket::TransportController>(
388 new cricket::TransportController(rtc::Thread::Current(),
389 rtc::Thread::Current(),
390 allocator_.get()))));
deadbeefab9b2d12015-10-14 11:33:11 -0700391 session_->SignalDataChannelOpenMessage.connect(
392 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800393 session_->GetOnDestroyedSignal()->connect(
394 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000395
396 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
397 observer_.ice_connection_state_);
398 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
399 observer_.ice_gathering_state_);
400
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200401 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800402 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700403 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404 }
405
deadbeefab9b2d12015-10-14 11:33:11 -0700406 void OnDataChannelOpenMessage(const std::string& label,
407 const InternalDataChannelInit& config) {
408 last_data_channel_label_ = label;
409 last_data_channel_config_ = config;
410 }
411
deadbeef057ecf02016-01-20 14:30:43 -0800412 void OnSessionDestroyed() { session_destroyed_ = true; }
413
htaa2a49d92016-03-04 02:51:39 -0800414 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000415
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000416 void InitWithBundlePolicy(
417 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800418 configuration_.bundle_policy = bundle_policy;
419 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700420 }
421
422 void InitWithRtcpMuxPolicy(
423 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
424 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800425 configuration_.rtcp_mux_policy = rtcp_mux_policy;
426 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000427 }
428
Henrik Boström87713d02015-08-25 09:53:21 +0200429 // Successfully init with DTLS; with a certificate generated and supplied or
430 // with a store that generates it for us.
431 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200432 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200433 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800434 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200435 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200436 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200437 cert_generator.reset(new FakeRTCCertificateGenerator());
438 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200439 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700440 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200441 }
Henrik Boströmd79599d2016-06-01 13:58:50 +0200442 Init(std::move(cert_generator));
Henrik Boström87713d02015-08-25 09:53:21 +0200443 }
444
445 // Init with DTLS with a store that will fail to generate a certificate.
446 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200447 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
448 new FakeRTCCertificateGenerator());
449 cert_generator->set_should_fail(true);
450 Init(std::move(cert_generator));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000451 }
452
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453 void InitWithDtmfCodec() {
454 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700455 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
456 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457 std::vector<cricket::AudioCodec> codecs;
458 codecs.push_back(kTelephoneEventCodec);
459 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -0700460 desc_factory_->set_audio_codecs(codecs, codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000461 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 }
463
jbauchcb560652016-08-04 05:20:32 -0700464 void InitWithGcm() {
465 rtc::CryptoOptions crypto_options;
466 crypto_options.enable_gcm_crypto_suites = true;
467 channel_manager_->SetCryptoOptions(crypto_options);
468 with_gcm_ = true;
469 Init();
470 }
471
deadbeefab9b2d12015-10-14 11:33:11 -0700472 void SendAudioVideoStream1() {
473 send_stream_1_ = true;
474 send_stream_2_ = false;
475 send_audio_ = true;
476 send_video_ = true;
477 }
478
479 void SendAudioVideoStream2() {
480 send_stream_1_ = false;
481 send_stream_2_ = true;
482 send_audio_ = true;
483 send_video_ = true;
484 }
485
486 void SendAudioVideoStream1And2() {
487 send_stream_1_ = true;
488 send_stream_2_ = true;
489 send_audio_ = true;
490 send_video_ = true;
491 }
492
493 void SendNothing() {
494 send_stream_1_ = false;
495 send_stream_2_ = false;
496 send_audio_ = false;
497 send_video_ = false;
498 }
499
500 void SendAudioOnlyStream2() {
501 send_stream_1_ = false;
502 send_stream_2_ = true;
503 send_audio_ = true;
504 send_video_ = false;
505 }
506
507 void SendVideoOnlyStream2() {
508 send_stream_1_ = false;
509 send_stream_2_ = true;
510 send_audio_ = false;
511 send_video_ = true;
512 }
513
514 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
515 if (send_stream_1_ && send_audio_) {
516 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
517 kStream1);
518 }
519 if (send_stream_1_ && send_video_) {
520 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
521 kStream1);
522 }
523 if (send_stream_2_ && send_audio_) {
524 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
525 kStream2);
526 }
527 if (send_stream_2_ && send_video_) {
528 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
529 kStream2);
530 }
531 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
532 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
533 data_channel_->label(),
534 data_channel_->label());
535 }
536 }
537
538 void GetOptionsForOffer(
539 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
540 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800541 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700542
deadbeefc80741f2015-10-22 13:14:45 -0700543 AddStreamsToOptions(session_options);
544 if (rtc_options.offer_to_receive_audio ==
545 RTCOfferAnswerOptions::kUndefined) {
546 session_options->recv_audio =
547 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
548 }
549 if (rtc_options.offer_to_receive_video ==
550 RTCOfferAnswerOptions::kUndefined) {
551 session_options->recv_video =
552 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
553 }
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 && data_channel_) {
560 session_options->data_channel_type = cricket::DCT_SCTP;
zhihuang9763d562016-08-05 11:14:50 -0700561 } else if (session_->data_channel_type() == cricket::DCT_QUIC) {
562 session_options->data_channel_type = cricket::DCT_QUIC;
deadbeefab9b2d12015-10-14 11:33:11 -0700563 }
jbauchcb560652016-08-04 05:20:32 -0700564
565 if (with_gcm_) {
566 session_options->crypto_options.enable_gcm_crypto_suites = true;
567 }
deadbeefab9b2d12015-10-14 11:33:11 -0700568 }
569
htaa2a49d92016-03-04 02:51:39 -0800570 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
571 // ParseConstraintsForAnswer is used to set some defaults.
572 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700573
deadbeefc80741f2015-10-22 13:14:45 -0700574 AddStreamsToOptions(session_options);
575 session_options->bundle_enabled =
576 session_options->bundle_enabled &&
577 (session_options->has_audio() || session_options->has_video() ||
578 session_options->has_data());
579
zhihuang9763d562016-08-05 11:14:50 -0700580 if (session_->data_channel_type() != cricket::DCT_RTP) {
581 session_options->data_channel_type = session_->data_channel_type();
deadbeef907abe42016-08-04 12:22:18 -0700582 }
jbauchcb560652016-08-04 05:20:32 -0700583
584 if (with_gcm_) {
585 session_options->crypto_options.enable_gcm_crypto_suites = true;
586 }
deadbeefab9b2d12015-10-14 11:33:11 -0700587 }
588
589 // Creates a local offer and applies it. Starts ICE.
590 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 // to decide which streams to create.
592 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000593 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594 SetLocalDescriptionWithoutError(offer);
595 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
596 observer_.ice_gathering_state_,
597 kIceCandidatesTimeout);
598 }
599
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000600 SessionDescriptionInterface* CreateOffer() {
601 PeerConnectionInterface::RTCOfferAnswerOptions options;
602 options.offer_to_receive_audio =
603 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
604
605 return CreateOffer(options);
606 }
607
wu@webrtc.org91053e72013-08-10 07:18:04 +0000608 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800609 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000610 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000611 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700612 cricket::MediaSessionOptions session_options;
613 GetOptionsForOffer(options, &session_options);
614 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000615 EXPECT_TRUE_WAIT(
616 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000617 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000618 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000619 }
620
621 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800622 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000623 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000624 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800625 cricket::MediaSessionOptions session_options = options;
626 GetOptionsForAnswer(&session_options);
627 // Overwrite recv_audio and recv_video with passed-in values.
628 session_options.recv_video = options.recv_video;
629 session_options.recv_audio = options.recv_audio;
630 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000631 EXPECT_TRUE_WAIT(
632 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000633 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000634 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000635 }
636
htaa2a49d92016-03-04 02:51:39 -0800637 SessionDescriptionInterface* CreateAnswer() {
638 cricket::MediaSessionOptions options;
639 options.recv_video = true;
640 options.recv_audio = true;
641 return CreateAnswer(options);
642 }
643
wu@webrtc.org364f2042013-11-20 21:49:41 +0000644 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000645 return (session_->voice_channel() != NULL &&
646 session_->video_channel() != NULL);
647 }
648
jbauchcb560652016-08-04 05:20:32 -0700649 void VerifyCryptoParams(const cricket::SessionDescription* sdp,
650 bool gcm_enabled = false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000651 ASSERT_TRUE(session_.get() != NULL);
652 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
653 ASSERT_TRUE(content != NULL);
654 const cricket::AudioContentDescription* audio_content =
655 static_cast<const cricket::AudioContentDescription*>(
656 content->description);
657 ASSERT_TRUE(audio_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700658 if (!gcm_enabled) {
659 ASSERT_EQ(1U, audio_content->cryptos().size());
660 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
661 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
662 audio_content->cryptos()[0].cipher_suite);
663 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
664 audio_content->protocol());
665 } else {
666 // The offer contains 3 possible crypto suites, the answer 1.
667 EXPECT_LE(1U, audio_content->cryptos().size());
668 EXPECT_NE(2U, audio_content->cryptos().size());
669 EXPECT_GE(3U, audio_content->cryptos().size());
670 ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size());
671 ASSERT_EQ("AEAD_AES_256_GCM",
672 audio_content->cryptos()[0].cipher_suite);
673 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
674 audio_content->protocol());
675 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000676
677 content = cricket::GetFirstVideoContent(sdp);
678 ASSERT_TRUE(content != NULL);
679 const cricket::VideoContentDescription* video_content =
680 static_cast<const cricket::VideoContentDescription*>(
681 content->description);
682 ASSERT_TRUE(video_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700683 if (!gcm_enabled) {
684 ASSERT_EQ(1U, video_content->cryptos().size());
685 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
686 video_content->cryptos()[0].cipher_suite);
687 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
688 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
689 video_content->protocol());
690 } else {
691 // The offer contains 3 possible crypto suites, the answer 1.
692 EXPECT_LE(1U, video_content->cryptos().size());
693 EXPECT_NE(2U, video_content->cryptos().size());
694 EXPECT_GE(3U, video_content->cryptos().size());
695 ASSERT_EQ("AEAD_AES_256_GCM",
696 video_content->cryptos()[0].cipher_suite);
697 ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size());
698 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
699 video_content->protocol());
700 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 }
702
703 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
704 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
705 ASSERT_TRUE(content != NULL);
706 const cricket::AudioContentDescription* audio_content =
707 static_cast<const cricket::AudioContentDescription*>(
708 content->description);
709 ASSERT_TRUE(audio_content != NULL);
710 ASSERT_EQ(0U, audio_content->cryptos().size());
711
712 content = cricket::GetFirstVideoContent(sdp);
713 ASSERT_TRUE(content != NULL);
714 const cricket::VideoContentDescription* video_content =
715 static_cast<const cricket::VideoContentDescription*>(
716 content->description);
717 ASSERT_TRUE(video_content != NULL);
718 ASSERT_EQ(0U, video_content->cryptos().size());
719
720 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700721 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700723 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 video_content->protocol());
725 } else {
726 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
727 audio_content->protocol());
728 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
729 video_content->protocol());
730 }
731 }
732
733 // Set the internal fake description factories to do DTLS-SRTP.
734 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000735 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000737 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200738 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800739 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700740 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800741 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
743 }
744
745 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
746 bool expected) {
747 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
748 ASSERT_TRUE(audio != NULL);
749 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000750 const TransportInfo* video = sdp->GetTransportInfoByName("video");
751 ASSERT_TRUE(video != NULL);
752 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753 }
754
755 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000756 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000758 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000759 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000761 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000763 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
764 offer);
htaa2a49d92016-03-04 02:51:39 -0800765 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766 // Answer should be NULL as no crypto params in offer.
767 ASSERT_TRUE(answer == NULL);
768 }
769
770 void VerifyAnswerFromCryptoOffer() {
771 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000772 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700774 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
776 ASSERT_TRUE(offer.get() != NULL);
777 VerifyCryptoParams(offer->description());
778 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700779 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780 ASSERT_TRUE(answer.get() != NULL);
781 VerifyCryptoParams(answer->description());
782 }
783
deadbeef0ed85b22016-02-23 17:24:52 -0800784 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
785 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800787 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 }
789
790 const cricket::ContentInfos& contents = desc1->contents();
791 cricket::ContentInfos::const_iterator it = contents.begin();
792
793 for (; it != contents.end(); ++it) {
794 const cricket::TransportDescription* transport_desc1 =
795 desc1->GetTransportDescriptionByName(it->name);
796 const cricket::TransportDescription* transport_desc2 =
797 desc2->GetTransportDescriptionByName(it->name);
798 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800799 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 }
801 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
802 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800803 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 }
805 }
deadbeef0ed85b22016-02-23 17:24:52 -0800806 return true;
807 }
808
809 // Compares ufrag/password only for the specified |media_type|.
810 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
811 const cricket::SessionDescription* desc2,
812 cricket::MediaType media_type) {
813 if (desc1->contents().size() != desc2->contents().size()) {
814 return false;
815 }
816
817 const cricket::ContentInfo* cinfo =
818 cricket::GetFirstMediaContent(desc1->contents(), media_type);
819 const cricket::TransportDescription* transport_desc1 =
820 desc1->GetTransportDescriptionByName(cinfo->name);
821 const cricket::TransportDescription* transport_desc2 =
822 desc2->GetTransportDescriptionByName(cinfo->name);
823 if (!transport_desc1 || !transport_desc2) {
824 return false;
825 }
826 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
827 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
828 return false;
829 }
830 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000832
833 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
834 std::string *sdp) {
835 const cricket::SessionDescription* desc = current_desc->description();
836 EXPECT_TRUE(current_desc->ToString(sdp));
837
838 const cricket::ContentInfos& contents = desc->contents();
839 cricket::ContentInfos::const_iterator it = contents.begin();
840 // Replace ufrag and pwd lines with empty strings.
841 for (; it != contents.end(); ++it) {
842 const cricket::TransportDescription* transport_desc =
843 desc->GetTransportDescriptionByName(it->name);
844 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
845 + "\r\n";
846 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
847 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000848 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000849 "", 0,
850 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000851 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000852 "", 0,
853 sdp);
854 }
855 }
856
deadbeef0ed85b22016-02-23 17:24:52 -0800857 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
858 const std::string& ufrag,
859 const std::string& pwd) {
860 cricket::SessionDescription* desc = current_desc->description();
861 for (TransportInfo& transport_info : desc->transport_infos()) {
862 cricket::TransportDescription& transport_desc =
863 transport_info.description;
864 transport_desc.ice_ufrag = ufrag;
865 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000866 }
867 }
868
deadbeef0ed85b22016-02-23 17:24:52 -0800869 // Sets ufrag/pwd for specified |media_type|.
870 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
871 cricket::MediaType media_type,
872 const std::string& ufrag,
873 const std::string& pwd) {
874 cricket::SessionDescription* desc = current_desc->description();
875 const cricket::ContentInfo* cinfo =
876 cricket::GetFirstMediaContent(desc->contents(), media_type);
877 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
878 cricket::TransportDescription* transport_desc =
879 &transport_info->description;
880 transport_desc->ice_ufrag = ufrag;
881 transport_desc->ice_pwd = pwd;
882 }
883
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 // Creates a remote offer and and applies it as a remote description,
885 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700886 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 // to decide which local and remote streams to create.
888 void CreateAndSetRemoteOfferAndLocalAnswer() {
889 SessionDescriptionInterface* offer = CreateRemoteOffer();
890 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800891 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 SetLocalDescriptionWithoutError(answer);
893 }
894 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
895 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700896 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 }
898 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700899 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 SetLocalDescriptionWithoutError(desc);
901 EXPECT_EQ(expected_state, session_->state());
902 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000903 void SetLocalDescriptionExpectError(const std::string& action,
904 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 SessionDescriptionInterface* desc) {
906 std::string error;
907 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000908 std::string sdp_type = "local ";
909 sdp_type.append(action);
910 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911 EXPECT_NE(std::string::npos, error.find(expected_error));
912 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000913 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
914 SessionDescriptionInterface* desc) {
915 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
916 expected_error, desc);
917 }
918 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
919 SessionDescriptionInterface* desc) {
920 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
921 expected_error, desc);
922 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
924 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
925 }
926 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700927 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 SetRemoteDescriptionWithoutError(desc);
929 EXPECT_EQ(expected_state, session_->state());
930 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000931 void SetRemoteDescriptionExpectError(const std::string& action,
932 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 SessionDescriptionInterface* desc) {
934 std::string error;
935 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000936 std::string sdp_type = "remote ";
937 sdp_type.append(action);
938 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939 EXPECT_NE(std::string::npos, error.find(expected_error));
940 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000941 void SetRemoteDescriptionOfferExpectError(
942 const std::string& expected_error, SessionDescriptionInterface* desc) {
943 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
944 expected_error, desc);
945 }
946 void SetRemoteDescriptionPranswerExpectError(
947 const std::string& expected_error, SessionDescriptionInterface* desc) {
948 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
949 expected_error, desc);
950 }
951 void SetRemoteDescriptionAnswerExpectError(
952 const std::string& expected_error, SessionDescriptionInterface* desc) {
953 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
954 expected_error, desc);
955 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956
957 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
958 SessionDescriptionInterface** nocrypto_answer) {
959 // Create a SDP without Crypto.
960 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000961 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 options.bundle_enabled = true;
963 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
964 ASSERT_TRUE(*offer != NULL);
965 VerifyCryptoParams((*offer)->description());
966
967 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
968 cricket::SEC_DISABLED);
969 EXPECT_TRUE(*nocrypto_answer != NULL);
970 }
971
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000972 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
973 SessionDescriptionInterface** nodtls_answer) {
974 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000975 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000976 options.bundle_enabled = true;
977
kwibergd1fe2812016-04-27 06:47:29 -0700978 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000979 CreateRemoteOffer(options, cricket::SEC_ENABLED));
980
981 *nodtls_answer =
982 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
983 EXPECT_TRUE(*nodtls_answer != NULL);
984 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
985 VerifyCryptoParams((*nodtls_answer)->description());
986
987 SetFactoryDtlsSrtp();
988 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
989 ASSERT_TRUE(*offer != NULL);
990 VerifyFingerprintStatus((*offer)->description(), true);
991 VerifyCryptoParams((*offer)->description());
992 }
993
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994 JsepSessionDescription* CreateRemoteOfferWithVersion(
995 cricket::MediaSessionOptions options,
996 cricket::SecurePolicy secure_policy,
997 const std::string& session_version,
998 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000999 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000 const cricket::SessionDescription* cricket_desc = NULL;
1001 if (current_desc) {
1002 cricket_desc = current_desc->description();
1003 session_id = current_desc->session_id();
1004 }
1005
1006 desc_factory_->set_secure(secure_policy);
1007 JsepSessionDescription* offer(
1008 new JsepSessionDescription(JsepSessionDescription::kOffer));
1009 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1010 session_id, session_version)) {
1011 delete offer;
1012 offer = NULL;
1013 }
1014 return offer;
1015 }
1016 JsepSessionDescription* CreateRemoteOffer(
1017 cricket::MediaSessionOptions options) {
1018 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1019 kSessionVersion, NULL);
1020 }
1021 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001022 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1023 return CreateRemoteOfferWithVersion(
1024 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001025 }
1026 JsepSessionDescription* CreateRemoteOffer(
1027 cricket::MediaSessionOptions options,
1028 const SessionDescriptionInterface* current_desc) {
1029 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1030 kSessionVersion, current_desc);
1031 }
1032
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001033 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1034 const char* sctp_stream_name, int new_port,
1035 cricket::MediaSessionOptions options) {
1036 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001037 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1038 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001039 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1040 }
1041
1042 // Takes ownership of offer_basis (and deletes it).
1043 JsepSessionDescription* ChangeSDPSctpPort(
1044 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1045 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1046 // SessionDescription from the mutated string.
1047 const char* default_port_str = "5000";
1048 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001049 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001050 std::string offer_str;
1051 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001052 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001053 new_port_str, strlen(new_port_str),
1054 &offer_str);
1055 JsepSessionDescription* offer = new JsepSessionDescription(
1056 offer_basis->type());
1057 delete offer_basis;
1058 offer->Initialize(offer_str, NULL);
1059 return offer;
1060 }
1061
deadbeefab9b2d12015-10-14 11:33:11 -07001062 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 // before this function to decide which streams to create.
1064 JsepSessionDescription* CreateRemoteOffer() {
1065 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001066 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001067 return CreateRemoteOffer(options, session_->remote_description());
1068 }
1069
1070 JsepSessionDescription* CreateRemoteAnswer(
1071 const SessionDescriptionInterface* offer,
1072 cricket::MediaSessionOptions options,
1073 cricket::SecurePolicy policy) {
1074 desc_factory_->set_secure(policy);
1075 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001076 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001077 JsepSessionDescription* answer(
1078 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1079 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1080 options, NULL),
1081 session_id, kSessionVersion)) {
1082 delete answer;
1083 answer = NULL;
1084 }
1085 return answer;
1086 }
1087
1088 JsepSessionDescription* CreateRemoteAnswer(
1089 const SessionDescriptionInterface* offer,
1090 cricket::MediaSessionOptions options) {
1091 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1092 }
1093
deadbeefab9b2d12015-10-14 11:33:11 -07001094 // Creates an answer session description.
1095 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096 // to decide which streams to create.
1097 JsepSessionDescription* CreateRemoteAnswer(
1098 const SessionDescriptionInterface* offer) {
1099 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001100 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1102 }
1103
1104 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001105 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001106 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001107 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001108
1109 PeerConnectionInterface::RTCOfferAnswerOptions options;
1110 options.use_rtp_mux = bundle;
1111
1112 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001113 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1114 // and answer.
1115 SetLocalDescriptionWithoutError(offer);
1116
kwibergd1fe2812016-04-27 06:47:29 -07001117 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001118 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001119 std::string sdp;
1120 EXPECT_TRUE(answer->ToString(&sdp));
1121
1122 size_t expected_candidate_num = 2;
1123 if (!rtcp_mux) {
1124 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1125 // for rtp and rtcp.
1126 expected_candidate_num = 4;
1127 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001128 const std::string kRtcpMux = "a=rtcp-mux";
1129 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001130 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131 kXRtcpMux.c_str(), kXRtcpMux.length(),
1132 &sdp);
1133 }
1134
1135 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1136 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001137
1138 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001139 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001140 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1141 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001142 if (bundle) {
1143 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1144 } else {
1145 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001146 }
1147 }
1148 // Tests that we can only send DTMF when the dtmf codec is supported.
1149 void TestCanInsertDtmf(bool can) {
1150 if (can) {
1151 InitWithDtmfCodec();
1152 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001153 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001154 }
deadbeefab9b2d12015-10-14 11:33:11 -07001155 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001156 CreateAndSetRemoteOfferAndLocalAnswer();
1157 EXPECT_FALSE(session_->CanInsertDtmf(""));
1158 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1159 }
1160
zhihuang3a334652016-05-05 18:37:49 -07001161 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1162 const std::string& codec_name) {
1163 for (const auto& content : desc->description()->contents()) {
1164 if (static_cast<cricket::MediaContentDescription*>(content.description)
1165 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1166 const auto* mdesc =
1167 static_cast<cricket::VideoContentDescription*>(content.description);
1168 for (const auto& codec : mdesc->codecs()) {
1169 if (codec.name == codec_name) {
1170 return true;
1171 }
1172 }
1173 }
1174 }
1175 return false;
1176 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001177 // Helper class to configure loopback network and verify Best
1178 // Connection using right IP protocol for TestLoopbackCall
1179 // method. LoopbackNetworkManager applies firewall rules to block
1180 // all ping traffic once ICE completed, and remove them to observe
1181 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1182 // verifies the best connection is using the right IP protocol after
1183 // initial ICE convergences.
1184
1185 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001186 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001187 LoopbackNetworkConfiguration()
1188 : test_ipv6_network_(false),
1189 test_extra_ipv4_network_(false),
1190 best_connection_after_initial_ice_converged_(1, 0) {}
1191
1192 // Used to track the expected best connection count in each IP protocol.
1193 struct ExpectedBestConnection {
1194 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1195 : ipv4_count_(ipv4_count),
1196 ipv6_count_(ipv6_count) {}
1197
1198 int ipv4_count_;
1199 int ipv6_count_;
1200 };
1201
1202 bool test_ipv6_network_;
1203 bool test_extra_ipv4_network_;
1204 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1205
1206 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001207 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001208 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1209 }
1210
1211 private:
jbauchac8869e2015-07-03 01:36:14 -07001212 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001213 const ExpectedBestConnection& expected) const {
1214 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001215 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1216 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001217 expected.ipv4_count_);
1218 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001219 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1220 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001221 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001222 // This is used in the loopback call so there is only single host to host
1223 // candidate pair.
1224 EXPECT_EQ(metrics_observer->GetEnumCounter(
1225 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1226 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001227 0);
1228 EXPECT_EQ(metrics_observer->GetEnumCounter(
1229 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1230 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001231 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001232 }
1233 };
1234
1235 class LoopbackNetworkManager {
1236 public:
1237 LoopbackNetworkManager(WebRtcSessionTest* session,
1238 const LoopbackNetworkConfiguration& config)
1239 : config_(config) {
1240 session->AddInterface(
1241 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1242 if (config_.test_extra_ipv4_network_) {
1243 session->AddInterface(
1244 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1245 }
1246 if (config_.test_ipv6_network_) {
1247 session->AddInterface(
1248 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1249 }
1250 }
1251
1252 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1253 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1254 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1255 if (config_.test_extra_ipv4_network_) {
1256 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1257 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1258 }
1259 if (config_.test_ipv6_network_) {
1260 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1261 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1262 }
1263 }
1264
1265 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1266
1267 private:
1268 LoopbackNetworkConfiguration config_;
1269 };
1270
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001271 // The method sets up a call from the session to itself, in a loopback
1272 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001273 // disconnection, and then a permanent disconnection.
1274 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1276 // While running the call, this method also checks if the session goes through
1277 // the correct sequence of ICE states when a connection is established,
1278 // broken, and re-established.
1279 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001280 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1281 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001282 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001283
stefanc1aeaf02015-10-15 07:26:07 -07001284 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001285 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001286 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001287 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288
1289 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1290 observer_.ice_gathering_state_);
1291 SetLocalDescriptionWithoutError(offer);
1292 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1293 observer_.ice_connection_state_);
1294 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001295 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1297 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001298 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299
1300 std::string sdp;
1301 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001302 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1303 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304 ASSERT_TRUE(desc != NULL);
1305 SetRemoteDescriptionWithoutError(desc);
1306
1307 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001308 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001309
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001310 // The ice connection state is "Connected" too briefly to catch in a test.
1311 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001312 observer_.ice_connection_state_, kIceCandidatesTimeout);
1313 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314
stefanc1aeaf02015-10-15 07:26:07 -07001315 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1316 LoopbackNetworkManager loopback_network_manager(this, config);
1317 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001318 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001319 // Adding firewall rule to block ping requests, which should cause
1320 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001321
1322 loopback_network_manager.ApplyFirewallRules(fss_.get());
1323
1324 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001325 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1326 observer_.ice_connection_state_,
1327 kIceCandidatesTimeout);
1328
jbauchac8869e2015-07-03 01:36:14 -07001329 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001330
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001332 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001333
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001334 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001335 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001336 observer_.ice_connection_state_,
1337 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001338
1339 // Now we block ping requests and wait until the ICE connection transitions
1340 // to the Failed state. This will take at least 30 seconds because it must
1341 // wait for the Port to timeout.
1342 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001343
1344 loopback_network_manager.ApplyFirewallRules(fss_.get());
1345 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001346 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001347 observer_.ice_connection_state_,
1348 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001349 }
1350
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001351 void TestLoopbackCall() {
1352 LoopbackNetworkConfiguration config;
1353 TestLoopbackCall(config);
1354 }
1355
stefanc1aeaf02015-10-15 07:26:07 -07001356 void TestPacketOptions() {
1357 media_controller_.reset(
1358 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1359 LoopbackNetworkConfiguration config;
1360 LoopbackNetworkManager loopback_network_manager(this, config);
1361
1362 SetupLoopbackCall();
1363
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001364 // Wait for channel to be ready for sending.
1365 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001366 uint8_t test_packet[15] = {0};
1367 rtc::PacketOptions options;
1368 options.packet_id = 10;
1369 media_engine_->GetVideoChannel(0)
1370 ->SendRtp(test_packet, sizeof(test_packet), options);
1371
1372 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001373 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1374 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001375 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1376 }
1377
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001378 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1379 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001380 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1381 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001382
1383 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001384 std::vector<cricket::AudioCodec> codecs =
1385 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001386 codecs.push_back(kCNCodec1);
1387 codecs.push_back(kCNCodec2);
1388 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001389 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001390 }
1391
1392 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1393 const cricket::ContentDescription* description = content->description;
1394 ASSERT(description != NULL);
1395 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001396 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397 ASSERT(audio_content_desc != NULL);
1398 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1399 if (audio_content_desc->codecs()[i].name == "CN")
1400 return false;
1401 }
1402 return true;
1403 }
1404
deadbeefab9b2d12015-10-14 11:33:11 -07001405 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001406 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001407 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001408 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1409 data_channel_ = DataChannel::Create(
1410 session_.get(), session_->data_channel_type(), "datachannel", dci);
1411 }
1412
1413 void SetLocalDescriptionWithDataChannel() {
1414 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001415 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001416 SetLocalDescriptionWithoutError(offer);
1417 }
1418
wu@webrtc.org91053e72013-08-10 07:18:04 +00001419 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001420 RTCCertificateGenerationMethod cert_gen_method,
1421 CreateSessionDescriptionRequest::Type type) {
1422 InitWithDtls(cert_gen_method);
1423 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1424 }
1425
1426 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1427 CreateSessionDescriptionRequest::Type type) {
1428 InitWithDtlsIdentityGenFail();
1429 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1430 }
1431
1432 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001433 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001434 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001435 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001436 if (type == CreateSessionDescriptionRequest::kAnswer) {
1437 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001438 std::unique_ptr<JsepSessionDescription> offer(
1439 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001440 ASSERT_TRUE(offer.get() != NULL);
1441 SetRemoteDescriptionWithoutError(offer.release());
1442 }
1443
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001444 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001445 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001446 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001447 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001448 observers[kNumber];
1449 for (int i = 0; i < kNumber; ++i) {
1450 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1451 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001452 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001453 } else {
htaa2a49d92016-03-04 02:51:39 -08001454 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001455 }
1456 }
1457
1458 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1459 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1460 WebRtcSessionCreateSDPObserverForTest::kFailed;
1461
1462 for (int i = 0; i < kNumber; ++i) {
1463 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1464 if (success) {
1465 EXPECT_TRUE(observers[i]->description() != NULL);
1466 } else {
1467 EXPECT_TRUE(observers[i]->description() == NULL);
1468 }
1469 }
1470 }
1471
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001472 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001473 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001474 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001475 turn_server.credentials = credentials;
1476 turn_server.ports.push_back(
1477 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1478 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001479 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001480 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001481 }
1482
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 cricket::FakeMediaEngine* media_engine_;
1484 cricket::FakeDataEngine* data_engine_;
kwibergd1fe2812016-04-27 06:47:29 -07001485 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001486 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001487 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1488 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1489 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1490 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1491 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1492 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001493 rtc::SocketServerScope ss_scope_;
1494 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001495 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001496 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001497 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001498 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001499 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001500 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001501 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001502 MockIceObserver observer_;
1503 cricket::FakeVideoMediaChannel* video_channel_;
1504 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001505 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001506 // The following flags affect options created for CreateOffer/CreateAnswer.
1507 bool send_stream_1_ = false;
1508 bool send_stream_2_ = false;
1509 bool send_audio_ = false;
1510 bool send_video_ = false;
1511 rtc::scoped_refptr<DataChannel> data_channel_;
1512 // Last values received from data channel creation signal.
1513 std::string last_data_channel_label_;
1514 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001515 bool session_destroyed_ = false;
jbauchcb560652016-08-04 05:20:32 -07001516 bool with_gcm_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517};
1518
Henrik Boström87713d02015-08-25 09:53:21 +02001519TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1520 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001521 // SDES is disabled when DTLS is on.
1522 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523}
1524
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001525TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001526 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001527 // SDES is required if DTLS is off.
1528 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001529}
1530
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1532 TestSessionCandidatesWithBundleRtcpMux(false, false);
1533}
1534
1535// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1536// with rtcp-mux and/or bundle.
1537TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1538 TestSessionCandidatesWithBundleRtcpMux(false, true);
1539}
1540
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001541TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1542 TestSessionCandidatesWithBundleRtcpMux(true, true);
1543}
1544
1545TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001546 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1547 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001548 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001549 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001550 InitiateCall();
1551 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1552 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1553 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1554}
1555
deadbeeff5f03e82016-06-06 11:16:06 -07001556TEST_F(WebRtcSessionTest, TestStunError) {
1557 rtc::ScopedFakeClock clock;
1558
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001559 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1560 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001561 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001562 rtc::FP_UDP,
1563 rtc::FD_ANY,
1564 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001565 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001566 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001567 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001568 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
deadbeeff5f03e82016-06-06 11:16:06 -07001569 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_, kStunTimeout, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1571 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001572 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1573 // warning.
1574 session_->Close();
1575 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576}
1577
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001578TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001579 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001580 SessionDescriptionInterface* offer = NULL;
1581 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1582 std::string unknown_action;
1583 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1584 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1585}
1586
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587// Test creating offers and receive answers and make sure the
1588// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001589TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001590 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001591 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001592 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593 const std::string session_id_orig = offer->session_id();
1594 const std::string session_version_orig = offer->session_version();
1595 SetLocalDescriptionWithoutError(offer);
1596
deadbeefab9b2d12015-10-14 11:33:11 -07001597 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 SessionDescriptionInterface* answer =
1599 CreateRemoteAnswer(session_->local_description());
1600 SetRemoteDescriptionWithoutError(answer);
1601
1602 video_channel_ = media_engine_->GetVideoChannel(0);
1603 voice_channel_ = media_engine_->GetVoiceChannel(0);
1604
1605 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1606 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1607
1608 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1609 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1610
1611 ASSERT_EQ(1u, video_channel_->send_streams().size());
1612 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1613 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1614 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1615
1616 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001617 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001618 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619
1620 // Verify the session id is the same and the session version is
1621 // increased.
1622 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001623 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1624 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625
1626 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001627 EXPECT_EQ(0u, video_channel_->send_streams().size());
1628 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629
deadbeefab9b2d12015-10-14 11:33:11 -07001630 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 answer = CreateRemoteAnswer(session_->local_description());
1632 SetRemoteDescriptionWithoutError(answer);
1633
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634 // Make sure the receive streams have not changed.
1635 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1636 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1637 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1638 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1639}
1640
1641// Test receiving offers and creating answers and make sure the
1642// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001643TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001644 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001645 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001646 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001647 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648 SetRemoteDescriptionWithoutError(offer);
1649
deadbeefab9b2d12015-10-14 11:33:11 -07001650 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001651 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001652 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001653 SetLocalDescriptionWithoutError(answer);
1654
1655 const std::string session_id_orig = answer->session_id();
1656 const std::string session_version_orig = answer->session_version();
1657
1658 video_channel_ = media_engine_->GetVideoChannel(0);
1659 voice_channel_ = media_engine_->GetVoiceChannel(0);
1660
htaa2a49d92016-03-04 02:51:39 -08001661 ASSERT_TRUE(video_channel_);
1662 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001663 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1664 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1665
1666 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1667 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1668
1669 ASSERT_EQ(1u, video_channel_->send_streams().size());
1670 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1671 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1672 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1673
deadbeefab9b2d12015-10-14 11:33:11 -07001674 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001675 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676 SetRemoteDescriptionWithoutError(offer);
1677
1678 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001679 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001680 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681
1682 // Verify the session id is the same and the session version is
1683 // increased.
1684 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001685 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1686 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687 SetLocalDescriptionWithoutError(answer);
1688
1689 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1690 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1691 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1692 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1693 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1694 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1695
1696 // Make sure we have no send streams.
1697 EXPECT_EQ(0u, video_channel_->send_streams().size());
1698 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1699}
1700
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001701TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001702 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001703 media_engine_->set_fail_create_channel(true);
1704
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001705 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001706 ASSERT_TRUE(offer != NULL);
1707 // SetRemoteDescription and SetLocalDescription will take the ownership of
1708 // the offer.
1709 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001710 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001711 ASSERT_TRUE(offer != NULL);
1712 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1713}
1714
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001715//
1716// Tests for creating/setting SDP under different SDES/DTLS polices:
1717//
1718// --DTLS off and SDES on
1719// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1720// set local/remote offer/answer with crypto --> success
1721// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1722// failure
1723// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1724// failure
1725// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1726// failure
1727//
1728// --DTLS on and SDES off
1729// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1730// set local/remote offer/answer with DTLS fingerprint --> success
1731// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1732// fingerprint --> failure
1733// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1734// --> failure
1735// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1736// --> failure
1737//
1738// --Encryption disabled: DTLS off and SDES off
1739// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1740// answer without SDES or DTLS --> success
1741// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1742// answer without SDES or DTLS --> success
1743//
1744
1745// Test that we return a failure when applying a remote/local offer that doesn't
1746// have cryptos enabled when DTLS is off.
1747TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001748 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001750 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 JsepSessionDescription* offer = CreateRemoteOffer(
1752 options, cricket::SEC_DISABLED);
1753 ASSERT_TRUE(offer != NULL);
1754 VerifyNoCryptoParams(offer->description(), false);
1755 // SetRemoteDescription and SetLocalDescription will take the ownership of
1756 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001757 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1759 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001760 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761}
1762
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001763// Test that we return a failure when applying a local answer that doesn't have
1764// cryptos enabled when DTLS is off.
1765TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001766 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 SessionDescriptionInterface* offer = NULL;
1768 SessionDescriptionInterface* answer = NULL;
1769 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1770 // SetRemoteDescription and SetLocalDescription will take the ownership of
1771 // the offer.
1772 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001773 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774}
1775
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001776// Test we will return fail when apply an remote answer that doesn't have
1777// crypto enabled when DTLS is off.
1778TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001779 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780 SessionDescriptionInterface* offer = NULL;
1781 SessionDescriptionInterface* answer = NULL;
1782 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1783 // SetRemoteDescription and SetLocalDescription will take the ownership of
1784 // the offer.
1785 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001786 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787}
1788
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001789// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1790// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001791TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001792 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001793 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001794 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 SetFactoryDtlsSrtp();
1796 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001797 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001798 JsepSessionDescription* offer =
1799 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800 ASSERT_TRUE(offer != NULL);
1801 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001802 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803
1804 // SetRemoteDescription will take the ownership of the offer.
1805 SetRemoteDescriptionWithoutError(offer);
1806
1807 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001808 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 ASSERT_TRUE(answer != NULL);
1810 VerifyFingerprintStatus(answer->description(), true);
1811 // Check that we don't have an a=crypto line in the answer.
1812 VerifyNoCryptoParams(answer->description(), true);
1813
1814 // Now set the local description, which should work, even without a=crypto.
1815 SetLocalDescriptionWithoutError(answer);
1816}
1817
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001818// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1819// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001820TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001821 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001822 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001823 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001824 SetFactoryDtlsSrtp();
1825
1826 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001827 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001828 ASSERT_TRUE(offer != NULL);
1829 VerifyFingerprintStatus(offer->description(), true);
1830 // Check that we don't have an a=crypto line in the offer.
1831 VerifyNoCryptoParams(offer->description(), true);
1832
1833 // Now set the local description, which should work, even without a=crypto.
1834 SetLocalDescriptionWithoutError(offer);
1835
1836 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001837 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001838 JsepSessionDescription* answer =
1839 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1840 ASSERT_TRUE(answer != NULL);
1841 VerifyFingerprintStatus(answer->description(), true);
1842 VerifyNoCryptoParams(answer->description(), true);
1843
1844 // SetRemoteDescription will take the ownership of the answer.
1845 SetRemoteDescriptionWithoutError(answer);
1846}
1847
1848// Test that if we support DTLS and the other side didn't offer a fingerprint,
1849// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001850TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001851 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001852 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001854 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001855 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856 JsepSessionDescription* offer = CreateRemoteOffer(
1857 options, cricket::SEC_REQUIRED);
1858 ASSERT_TRUE(offer != NULL);
1859 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001860 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001862 // SetRemoteDescription will take the ownership of the offer.
1863 SetRemoteDescriptionOfferExpectError(
1864 kSdpWithoutDtlsFingerprint, offer);
1865
1866 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1867 // SetLocalDescription will take the ownership of the offer.
1868 SetLocalDescriptionOfferExpectError(
1869 kSdpWithoutDtlsFingerprint, offer);
1870}
1871
1872// Test that we return a failure when applying a local answer that doesn't have
1873// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001874TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001875 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001876 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001877 SessionDescriptionInterface* offer = NULL;
1878 SessionDescriptionInterface* answer = NULL;
1879 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1880
1881 // SetRemoteDescription and SetLocalDescription will take the ownership of
1882 // the offer and answer.
1883 SetRemoteDescriptionWithoutError(offer);
1884 SetLocalDescriptionAnswerExpectError(
1885 kSdpWithoutDtlsFingerprint, answer);
1886}
1887
1888// Test that we return a failure when applying a remote answer that doesn't have
1889// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001890TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001891 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001892 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001893 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001894 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001895 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001896 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001897 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001898 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001899 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001900
1901 // SetRemoteDescription and SetLocalDescription will take the ownership of
1902 // the offer and answer.
1903 SetLocalDescriptionWithoutError(offer);
1904 SetRemoteDescriptionAnswerExpectError(
1905 kSdpWithoutDtlsFingerprint, answer);
1906}
1907
1908// Test that we create a local offer without SDES or DTLS and accept a remote
1909// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001910TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001911 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001912 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001913 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001914
1915 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001916 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001917 ASSERT_TRUE(offer != NULL);
1918 VerifyFingerprintStatus(offer->description(), false);
1919 // Check that we don't have an a=crypto line in the offer.
1920 VerifyNoCryptoParams(offer->description(), false);
1921
1922 // Now set the local description, which should work, even without a=crypto.
1923 SetLocalDescriptionWithoutError(offer);
1924
1925 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001926 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001927 JsepSessionDescription* answer =
1928 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1929 ASSERT_TRUE(answer != NULL);
1930 VerifyFingerprintStatus(answer->description(), false);
1931 VerifyNoCryptoParams(answer->description(), false);
1932
1933 // SetRemoteDescription will take the ownership of the answer.
1934 SetRemoteDescriptionWithoutError(answer);
1935}
1936
1937// Test that we create a local answer without SDES or DTLS and accept a remote
1938// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001939TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001940 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001941 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001942
1943 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001944 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001945 JsepSessionDescription* offer =
1946 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1947 ASSERT_TRUE(offer != NULL);
1948 VerifyFingerprintStatus(offer->description(), false);
1949 VerifyNoCryptoParams(offer->description(), false);
1950
1951 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001952 SetRemoteDescriptionWithoutError(offer);
1953
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001954 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001955 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956 ASSERT_TRUE(answer != NULL);
1957 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001958 // Check that we don't have an a=crypto line in the answer.
1959 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001961 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001962 SetLocalDescriptionWithoutError(answer);
1963}
1964
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001965// Test that we can create and set an answer correctly when different
1966// SSL roles have been negotiated for different transports.
1967// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1968TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1969 SendAudioVideoStream1();
1970 InitWithDtls(GetParam());
1971 SetFactoryDtlsSrtp();
1972
1973 SessionDescriptionInterface* offer = CreateOffer();
1974 SetLocalDescriptionWithoutError(offer);
1975
1976 cricket::MediaSessionOptions options;
1977 options.recv_video = true;
1978
1979 // First, negotiate different SSL roles.
1980 SessionDescriptionInterface* answer =
1981 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1982 TransportInfo* audio_transport_info =
1983 answer->description()->GetTransportInfoByName("audio");
1984 audio_transport_info->description.connection_role =
1985 cricket::CONNECTIONROLE_ACTIVE;
1986 TransportInfo* video_transport_info =
1987 answer->description()->GetTransportInfoByName("video");
1988 video_transport_info->description.connection_role =
1989 cricket::CONNECTIONROLE_PASSIVE;
1990 SetRemoteDescriptionWithoutError(answer);
1991
1992 // Now create an offer in the reverse direction, and ensure the initial
1993 // offerer responds with an answer with correct SSL roles.
1994 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1995 kSessionVersion,
1996 session_->remote_description());
1997 SetRemoteDescriptionWithoutError(offer);
1998
htaa2a49d92016-03-04 02:51:39 -08001999 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002000 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2001 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2002 audio_transport_info->description.connection_role);
2003 video_transport_info = answer->description()->GetTransportInfoByName("video");
2004 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2005 video_transport_info->description.connection_role);
2006 SetLocalDescriptionWithoutError(answer);
2007
2008 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2009 // audio is transferred over to video in the answer that completes the BUNDLE
2010 // negotiation.
2011 options.bundle_enabled = true;
2012 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2013 kSessionVersion,
2014 session_->remote_description());
2015 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002016 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002017 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2018 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2019 audio_transport_info->description.connection_role);
2020 video_transport_info = answer->description()->GetTransportInfoByName("video");
2021 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2022 video_transport_info->description.connection_role);
2023 SetLocalDescriptionWithoutError(answer);
2024}
2025
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002026TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002027 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002028 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002029 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002030 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 SetLocalDescriptionWithoutError(offer);
2032
2033 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002034 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035 SetLocalDescriptionWithoutError(offer2);
2036}
2037
2038TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002039 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002040 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002042 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043 SetRemoteDescriptionWithoutError(offer);
2044
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002045 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046 SetRemoteDescriptionWithoutError(offer2);
2047}
2048
2049TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002050 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002051 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002052 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002054 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002055 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2056 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057}
2058
2059TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002060 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002061 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002062 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002064 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002065 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002066 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067}
2068
2069TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002070 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002071 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002073 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074
htaa2a49d92016-03-04 02:51:39 -08002075 JsepSessionDescription* pranswer =
2076 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002078 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079
deadbeefab9b2d12015-10-14 11:33:11 -07002080 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002081 JsepSessionDescription* pranswer2 =
2082 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2084
deadbeefd59daf82015-10-14 15:02:44 -07002085 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002086
deadbeefab9b2d12015-10-14 11:33:11 -07002087 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002088 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002089 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090}
2091
2092TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002093 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002094 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002095 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002096 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097
2098 JsepSessionDescription* pranswer =
2099 CreateRemoteAnswer(session_->local_description());
2100 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2101
2102 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002103 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104
deadbeefab9b2d12015-10-14 11:33:11 -07002105 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106 JsepSessionDescription* pranswer2 =
2107 CreateRemoteAnswer(session_->local_description());
2108 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2109
2110 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002111 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112
deadbeefab9b2d12015-10-14 11:33:11 -07002113 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114 SessionDescriptionInterface* answer =
2115 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002116 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117}
2118
2119TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002120 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002121 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002122 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002123
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 SessionDescriptionInterface* answer =
2125 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002126 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2127 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128}
2129
2130TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002131 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002132 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002133 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002134
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 SessionDescriptionInterface* answer =
2136 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002137 SetRemoteDescriptionAnswerExpectError(
2138 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139}
2140
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002141// Tests that the remote candidates are added and removed successfully.
2142TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002143 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002144 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002146 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2147 "", "", "host", 0, "");
2148 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2150
deadbeefd59daf82015-10-14 15:02:44 -07002151 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2153
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002154 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002156
2157 // Fail since we have not set a remote description.
2158 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159
2160 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2161 session_->local_description());
2162 SetRemoteDescriptionWithoutError(answer);
2163
deadbeefd59daf82015-10-14 15:02:44 -07002164 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2165 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002166 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002167 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2168 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2169
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 // Verifying the candidates are copied properly from internal vector.
2171 const SessionDescriptionInterface* remote_desc =
2172 session_->remote_description();
2173 ASSERT_TRUE(remote_desc != NULL);
2174 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2175 const IceCandidateCollection* candidates =
2176 remote_desc->candidates(kMediaContentIndex0);
2177 ASSERT_EQ(2u, candidates->count());
2178 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2179 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2180 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2181 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2182
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002183 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2184 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185 candidate.set_component(2);
2186 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2187 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002188 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189
2190 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2191 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002192
2193 // Remove candidate1 and candidate2
2194 std::vector<cricket::Candidate> remote_candidates;
2195 remote_candidates.push_back(ice_candidate1.candidate());
2196 remote_candidates.push_back(ice_candidate2.candidate());
2197 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2198 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199}
2200
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002201// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002202// that it is retained if the remote session description is changed.
2203TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002204 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002205 cricket::Candidate candidate1;
2206 candidate1.set_component(1);
2207 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2208 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002209 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210 CreateAndSetRemoteOfferAndLocalAnswer();
2211
2212 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2213 const SessionDescriptionInterface* remote_desc =
2214 session_->remote_description();
2215 ASSERT_TRUE(remote_desc != NULL);
2216 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2217 const IceCandidateCollection* candidates =
2218 remote_desc->candidates(kMediaContentIndex0);
2219 ASSERT_EQ(1u, candidates->count());
2220 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2221
2222 // Update the RemoteSessionDescription with a new session description and
2223 // a candidate and check that the new remote session description contains both
2224 // candidates.
2225 SessionDescriptionInterface* offer = CreateRemoteOffer();
2226 cricket::Candidate candidate2;
2227 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2228 candidate2);
2229 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2230 SetRemoteDescriptionWithoutError(offer);
2231
2232 remote_desc = session_->remote_description();
2233 ASSERT_TRUE(remote_desc != NULL);
2234 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2235 candidates = remote_desc->candidates(kMediaContentIndex0);
2236 ASSERT_EQ(2u, candidates->count());
2237 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2238 // Username and password have be updated with the TransportInfo of the
2239 // SessionDescription, won't be equal to the original one.
2240 candidate2.set_username(candidates->at(0)->candidate().username());
2241 candidate2.set_password(candidates->at(0)->candidate().password());
2242 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2243 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2244 // No need to verify the username and password.
2245 candidate1.set_username(candidates->at(1)->candidate().username());
2246 candidate1.set_password(candidates->at(1)->candidate().password());
2247 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2248
2249 // Test that the candidate is ignored if we can add the same candidate again.
2250 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2251}
2252
2253// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002254// that they are retained if the local session description is changed. And if
2255// continual gathering is enabled, they are removed from the local session
2256// description when the network is down.
2257TEST_F(WebRtcSessionTest,
2258 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002259 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002260 Init();
deadbeefb60a8192016-08-24 15:15:00 -07002261 // Enable Continual Gathering.
2262 cricket::IceConfig config;
2263 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2264 session_->SetIceConfig(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002265 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 CreateAndSetRemoteOfferAndLocalAnswer();
2267
2268 const SessionDescriptionInterface* local_desc = session_->local_description();
2269 const IceCandidateCollection* candidates =
2270 local_desc->candidates(kMediaContentIndex0);
2271 ASSERT_TRUE(candidates != NULL);
2272 EXPECT_EQ(0u, candidates->count());
2273
deadbeefb60a8192016-08-24 15:15:00 -07002274 // Since we're using continual gathering, we won't get "gathering done".
2275 EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276
2277 local_desc = session_->local_description();
2278 candidates = local_desc->candidates(kMediaContentIndex0);
2279 ASSERT_TRUE(candidates != NULL);
2280 EXPECT_LT(0u, candidates->count());
2281 candidates = local_desc->candidates(1);
2282 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002283 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284
2285 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002286 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287 CreateAndSetRemoteOfferAndLocalAnswer();
2288
2289 local_desc = session_->local_description();
2290 candidates = local_desc->candidates(kMediaContentIndex0);
2291 ASSERT_TRUE(candidates != NULL);
2292 EXPECT_LT(0u, candidates->count());
2293 candidates = local_desc->candidates(1);
2294 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002295 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002296
2297 candidates = local_desc->candidates(kMediaContentIndex0);
2298 size_t num_local_candidates = candidates->count();
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002299 // Bring down the network interface to trigger candidate removals.
2300 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2301 // Verify that all local candidates are removed.
2302 EXPECT_EQ(0, observer_.num_candidates_removed_);
2303 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2304 kIceCandidatesTimeout);
2305 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2306}
2307
2308// Tests that if continual gathering is disabled, local candidates won't be
2309// removed when the interface is turned down.
2310TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2311 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2312 Init();
2313 SendAudioVideoStream1();
2314 CreateAndSetRemoteOfferAndLocalAnswer();
2315
2316 const SessionDescriptionInterface* local_desc = session_->local_description();
2317 const IceCandidateCollection* candidates =
2318 local_desc->candidates(kMediaContentIndex0);
2319 ASSERT_TRUE(candidates != NULL);
2320 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2321
2322 size_t num_local_candidates = candidates->count();
2323 EXPECT_LT(0u, num_local_candidates);
2324 // By default, Continual Gathering is disabled.
2325 // Bring down the network interface.
2326 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2327 // Verify that the local candidates are not removed.
2328 rtc::Thread::Current()->ProcessMessages(1000);
2329 EXPECT_EQ(0, observer_.num_candidates_removed_);
2330 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331}
2332
2333// Test that we can set a remote session description with remote candidates.
2334TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002335 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336
2337 cricket::Candidate candidate1;
2338 candidate1.set_component(1);
2339 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2340 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002341 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002342 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343
2344 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2345 SetRemoteDescriptionWithoutError(offer);
2346
2347 const SessionDescriptionInterface* remote_desc =
2348 session_->remote_description();
2349 ASSERT_TRUE(remote_desc != NULL);
2350 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2351 const IceCandidateCollection* candidates =
2352 remote_desc->candidates(kMediaContentIndex0);
2353 ASSERT_EQ(1u, candidates->count());
2354 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2355
htaa2a49d92016-03-04 02:51:39 -08002356 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357 SetLocalDescriptionWithoutError(answer);
2358}
2359
2360// Test that offers and answers contains ice candidates when Ice candidates have
2361// been gathered.
2362TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002363 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002364 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002365 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002366 // Ice is started but candidates are not provided until SetLocalDescription
2367 // is called.
2368 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2369 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2370 CreateAndSetRemoteOfferAndLocalAnswer();
2371 // Wait until at least one local candidate has been collected.
2372 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2373 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374
kwibergd1fe2812016-04-27 06:47:29 -07002375 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002376
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2378 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379
2380 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2381 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002382 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002383 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2384 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002385 SetLocalDescriptionWithoutError(answer);
2386}
2387
2388// Verifies TransportProxy and media channels are created with content names
2389// present in the SessionDescription.
2390TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002391 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002392 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002393 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394
2395 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002396 // "video". Goal is to modify these content names and verify transport
2397 // channels
2398 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399 // present in SDP.
2400 std::string sdp;
2401 EXPECT_TRUE(offer->ToString(&sdp));
2402 const std::string kAudioMid = "a=mid:audio";
2403 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2404 const std::string kVideoMid = "a=mid:video";
2405 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2406
2407 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002408 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 kAudioMidReplaceStr.c_str(),
2410 kAudioMidReplaceStr.length(),
2411 &sdp);
2412 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002413 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002414 kVideoMidReplaceStr.c_str(),
2415 kVideoMidReplaceStr.length(),
2416 &sdp);
2417
2418 SessionDescriptionInterface* modified_offer =
2419 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2420
2421 SetRemoteDescriptionWithoutError(modified_offer);
2422
htaa2a49d92016-03-04 02:51:39 -08002423 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424 SetLocalDescriptionWithoutError(answer);
2425
deadbeefcbecd352015-09-23 11:50:27 -07002426 cricket::TransportChannel* voice_transport_channel =
2427 session_->voice_rtp_transport_channel();
2428 EXPECT_TRUE(voice_transport_channel != NULL);
2429 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2430 cricket::TransportChannel* video_transport_channel =
2431 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002432 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002433 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2435 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2436}
2437
2438// Test that an offer contains the correct media content descriptions based on
2439// the send streams when no constraints have been set.
2440TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002441 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002442 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002443
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444 ASSERT_TRUE(offer != NULL);
2445 const cricket::ContentInfo* content =
2446 cricket::GetFirstAudioContent(offer->description());
2447 EXPECT_TRUE(content != NULL);
2448 content = cricket::GetFirstVideoContent(offer->description());
2449 EXPECT_TRUE(content == NULL);
2450}
2451
2452// Test that an offer contains the correct media content descriptions based on
2453// the send streams when no constraints have been set.
2454TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002455 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002457 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002458 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002459
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460 const cricket::ContentInfo* content =
2461 cricket::GetFirstAudioContent(offer->description());
2462 EXPECT_TRUE(content != NULL);
2463 content = cricket::GetFirstVideoContent(offer->description());
2464 EXPECT_TRUE(content == NULL);
2465
2466 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002467 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002468 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 content = cricket::GetFirstAudioContent(offer->description());
2470 EXPECT_TRUE(content != NULL);
2471 content = cricket::GetFirstVideoContent(offer->description());
2472 EXPECT_TRUE(content != NULL);
2473}
2474
2475// Test that an offer contains no media content descriptions if
2476// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2477TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002478 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002479 PeerConnectionInterface::RTCOfferAnswerOptions options;
2480 options.offer_to_receive_audio = 0;
2481 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002482
kwibergd1fe2812016-04-27 06:47:29 -07002483 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002484
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485 ASSERT_TRUE(offer != NULL);
2486 const cricket::ContentInfo* content =
2487 cricket::GetFirstAudioContent(offer->description());
2488 EXPECT_TRUE(content == NULL);
2489 content = cricket::GetFirstVideoContent(offer->description());
2490 EXPECT_TRUE(content == NULL);
2491}
2492
2493// Test that an offer contains only audio media content descriptions if
2494// kOfferToReceiveAudio constraints are set to true.
2495TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002496 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002497 PeerConnectionInterface::RTCOfferAnswerOptions options;
2498 options.offer_to_receive_audio =
2499 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2500
kwibergd1fe2812016-04-27 06:47:29 -07002501 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502
2503 const cricket::ContentInfo* content =
2504 cricket::GetFirstAudioContent(offer->description());
2505 EXPECT_TRUE(content != NULL);
2506 content = cricket::GetFirstVideoContent(offer->description());
2507 EXPECT_TRUE(content == NULL);
2508}
2509
2510// Test that an offer contains audio and video media content descriptions if
2511// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2512TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002513 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002514 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002515 PeerConnectionInterface::RTCOfferAnswerOptions options;
2516 options.offer_to_receive_audio =
2517 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2518 options.offer_to_receive_video =
2519 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2520
kwibergd1fe2812016-04-27 06:47:29 -07002521 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002522
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002523 const cricket::ContentInfo* content =
2524 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002525 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002526
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002527 content = cricket::GetFirstVideoContent(offer->description());
2528 EXPECT_TRUE(content != NULL);
2529
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002530 // Sets constraints to false and verifies that audio/video contents are
2531 // removed.
2532 options.offer_to_receive_audio = 0;
2533 options.offer_to_receive_video = 0;
2534 offer.reset(CreateOffer(options));
2535
2536 content = cricket::GetFirstAudioContent(offer->description());
2537 EXPECT_TRUE(content == NULL);
2538 content = cricket::GetFirstVideoContent(offer->description());
2539 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002540}
2541
2542// Test that an answer can not be created if the last remote description is not
2543// an offer.
2544TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002545 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002546 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547 SetLocalDescriptionWithoutError(offer);
2548 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2549 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002550 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551}
2552
2553// Test that an answer contains the correct media content descriptions when no
2554// constraints have been set.
2555TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002556 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002557 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002558 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002560 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002561 const cricket::ContentInfo* content =
2562 cricket::GetFirstAudioContent(answer->description());
2563 ASSERT_TRUE(content != NULL);
2564 EXPECT_FALSE(content->rejected);
2565
2566 content = cricket::GetFirstVideoContent(answer->description());
2567 ASSERT_TRUE(content != NULL);
2568 EXPECT_FALSE(content->rejected);
2569}
2570
2571// Test that an answer contains the correct media content descriptions when no
2572// constraints have been set and the offer only contain audio.
2573TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002574 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002575 // Create a remote offer with audio only.
2576 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002577
kwibergd1fe2812016-04-27 06:47:29 -07002578 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2580 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2581
2582 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002583 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002584 const cricket::ContentInfo* content =
2585 cricket::GetFirstAudioContent(answer->description());
2586 ASSERT_TRUE(content != NULL);
2587 EXPECT_FALSE(content->rejected);
2588
2589 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2590}
2591
2592// Test that an answer contains the correct media content descriptions when no
2593// constraints have been set.
2594TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002595 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002596 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002597 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002598 SetRemoteDescriptionWithoutError(offer.release());
2599 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002600 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002601 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002602 const cricket::ContentInfo* content =
2603 cricket::GetFirstAudioContent(answer->description());
2604 ASSERT_TRUE(content != NULL);
2605 EXPECT_FALSE(content->rejected);
2606
2607 content = cricket::GetFirstVideoContent(answer->description());
2608 ASSERT_TRUE(content != NULL);
2609 EXPECT_FALSE(content->rejected);
2610}
2611
2612// Test that an answer contains the correct media content descriptions when
2613// constraints have been set but no stream is sent.
2614TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002615 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002617 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002618 SetRemoteDescriptionWithoutError(offer.release());
2619
htaa2a49d92016-03-04 02:51:39 -08002620 cricket::MediaSessionOptions session_options;
2621 session_options.recv_audio = false;
2622 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002623 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002624 CreateAnswer(session_options));
2625
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626 const cricket::ContentInfo* content =
2627 cricket::GetFirstAudioContent(answer->description());
2628 ASSERT_TRUE(content != NULL);
2629 EXPECT_TRUE(content->rejected);
2630
2631 content = cricket::GetFirstVideoContent(answer->description());
2632 ASSERT_TRUE(content != NULL);
2633 EXPECT_TRUE(content->rejected);
2634}
2635
2636// Test that an answer contains the correct media content descriptions when
2637// constraints have been set and streams are sent.
2638TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002639 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002640 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002641 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002642 SetRemoteDescriptionWithoutError(offer.release());
2643
htaa2a49d92016-03-04 02:51:39 -08002644 cricket::MediaSessionOptions options;
2645 options.recv_audio = false;
2646 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002647
2648 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002649 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002650 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002651
2652 // TODO(perkj): Should the direction be set to SEND_ONLY?
2653 const cricket::ContentInfo* content =
2654 cricket::GetFirstAudioContent(answer->description());
2655 ASSERT_TRUE(content != NULL);
2656 EXPECT_FALSE(content->rejected);
2657
2658 // TODO(perkj): Should the direction be set to SEND_ONLY?
2659 content = cricket::GetFirstVideoContent(answer->description());
2660 ASSERT_TRUE(content != NULL);
2661 EXPECT_FALSE(content->rejected);
2662}
2663
2664TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2665 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002666 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002667 PeerConnectionInterface::RTCOfferAnswerOptions options;
2668 options.offer_to_receive_audio =
2669 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2670 options.voice_activity_detection = false;
2671
kwibergd1fe2812016-04-27 06:47:29 -07002672 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002673
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002674 const cricket::ContentInfo* content =
2675 cricket::GetFirstAudioContent(offer->description());
2676 EXPECT_TRUE(content != NULL);
2677 EXPECT_TRUE(VerifyNoCNCodecs(content));
2678}
2679
2680TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2681 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002682 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002683 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002684 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002685 SetRemoteDescriptionWithoutError(offer.release());
2686
htaa2a49d92016-03-04 02:51:39 -08002687 cricket::MediaSessionOptions options;
2688 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002689 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002690 const cricket::ContentInfo* content =
2691 cricket::GetFirstAudioContent(answer->description());
2692 ASSERT_TRUE(content != NULL);
2693 EXPECT_TRUE(VerifyNoCNCodecs(content));
2694}
2695
2696// This test verifies the call setup when remote answer with audio only and
2697// later updates with video.
2698TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002699 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002700 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2701 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2702
deadbeefab9b2d12015-10-14 11:33:11 -07002703 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002704 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002705
2706 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002707 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2708
2709 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2710 // and answer;
2711 SetLocalDescriptionWithoutError(offer);
2712 SetRemoteDescriptionWithoutError(answer);
2713
2714 video_channel_ = media_engine_->GetVideoChannel(0);
2715 voice_channel_ = media_engine_->GetVoiceChannel(0);
2716
2717 ASSERT_TRUE(video_channel_ == NULL);
2718
2719 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2720 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2721 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2722
2723 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002724 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725 CreateAndSetRemoteOfferAndLocalAnswer();
2726
2727 video_channel_ = media_engine_->GetVideoChannel(0);
2728 voice_channel_ = media_engine_->GetVoiceChannel(0);
2729
2730 ASSERT_TRUE(video_channel_ != NULL);
2731 ASSERT_TRUE(voice_channel_ != NULL);
2732
2733 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2734 ASSERT_EQ(1u, video_channel_->send_streams().size());
2735 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2736 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2737 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2738 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2739 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2740 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2741
2742 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002743 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002744 CreateAndSetRemoteOfferAndLocalAnswer();
2745
2746 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2747 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2748 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2749 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2750 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2751}
2752
2753// This test verifies the call setup when remote answer with video only and
2754// later updates with audio.
2755TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002756 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002757 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2758 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002759 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002760 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002761
2762 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002763 options.recv_audio = false;
2764 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002765 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2766 offer, options, cricket::SEC_ENABLED);
2767
2768 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2769 // and answer.
2770 SetLocalDescriptionWithoutError(offer);
2771 SetRemoteDescriptionWithoutError(answer);
2772
2773 video_channel_ = media_engine_->GetVideoChannel(0);
2774 voice_channel_ = media_engine_->GetVoiceChannel(0);
2775
2776 ASSERT_TRUE(voice_channel_ == NULL);
2777 ASSERT_TRUE(video_channel_ != NULL);
2778
2779 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2780 ASSERT_EQ(1u, video_channel_->send_streams().size());
2781 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2782
2783 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002784 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002785 CreateAndSetRemoteOfferAndLocalAnswer();
2786
2787 voice_channel_ = media_engine_->GetVoiceChannel(0);
2788 ASSERT_TRUE(voice_channel_ != NULL);
2789
2790 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2791 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2792 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2793 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2794
2795 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002796 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002797 CreateAndSetRemoteOfferAndLocalAnswer();
2798
2799 video_channel_ = media_engine_->GetVideoChannel(0);
2800 voice_channel_ = media_engine_->GetVoiceChannel(0);
2801
2802 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2803 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2804 ASSERT_EQ(1u, video_channel_->send_streams().size());
2805 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2806}
2807
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002808TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002809 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002810 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002811 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002812 VerifyCryptoParams(offer->description());
2813 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002814 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002815 VerifyCryptoParams(answer->description());
2816}
2817
jbauchcb560652016-08-04 05:20:32 -07002818TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) {
2819 InitWithGcm();
2820 SendAudioVideoStream1();
2821 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2822 VerifyCryptoParams(offer->description(), true);
2823 SetRemoteDescriptionWithoutError(offer.release());
2824 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
2825 VerifyCryptoParams(answer->description(), true);
2826}
2827
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002828TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002829 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002830 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002831 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002832 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002833 VerifyNoCryptoParams(offer->description(), false);
2834}
2835
2836TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002837 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002838 VerifyAnswerFromNonCryptoOffer();
2839}
2840
2841TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002842 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002843 VerifyAnswerFromCryptoOffer();
2844}
2845
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002846// This test verifies that setLocalDescription fails if
2847// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2848TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002849 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002850 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002851 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002852
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002853 std::string sdp;
2854 RemoveIceUfragPwdLines(offer.get(), &sdp);
2855 SessionDescriptionInterface* modified_offer =
2856 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002857 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002858}
2859
2860// This test verifies that setRemoteDescription fails if
2861// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2862TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002863 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002864 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002865 std::string sdp;
2866 RemoveIceUfragPwdLines(offer.get(), &sdp);
2867 SessionDescriptionInterface* modified_offer =
2868 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002869 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002870}
2871
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002872// This test verifies that setLocalDescription fails if local offer has
2873// too short ice ufrag and pwd strings.
2874TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002875 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002876 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002877 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002878 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2879 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002880 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002881 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002882 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002883
2884 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002885 offer.reset(CreateOffer());
2886 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2887 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002888}
2889
2890// This test verifies that setRemoteDescription fails if remote offer has
2891// too short ice ufrag and pwd strings.
2892TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002893 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002894 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002895 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2896 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002897 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002898 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002899 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002900
deadbeef0ed85b22016-02-23 17:24:52 -08002901 offer.reset(CreateRemoteOffer());
2902 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2903 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002904}
2905
Honghai Zhang04e91462015-12-11 14:26:22 -08002906// Test that if the remote offer indicates the peer requested ICE restart (via
2907// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2908TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002909 Init();
honghaiz503726c2015-07-31 12:37:38 -07002910
2911 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002912 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002913 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002914 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2915 0, "", "", "relay", 0, "");
2916 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2917 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002918 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2919 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002920 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2921
2922 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002923 offer.reset(CreateRemoteOffer());
2924 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002925 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2926 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2927 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002928 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2929 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002930 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2931
2932 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002933 offer.reset(CreateRemoteOffer());
2934 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002935 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2936 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2937 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002938 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2939 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002940 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2941
2942 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002943 offer.reset(CreateRemoteOffer());
2944 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2945 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002946 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2947}
2948
Honghai Zhang04e91462015-12-11 14:26:22 -08002949// Test that if the remote answer indicates the peer requested ICE restart (via
2950// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2951TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2952 Init();
2953 SessionDescriptionInterface* offer = CreateOffer();
2954 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002955
2956 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002957 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002958 answer->set_type(JsepSessionDescription::kPrAnswer);
2959 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002960 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2961 0, "", "", "relay", 0, "");
2962 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2963 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002964 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2965 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002966 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2967
2968 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002969 answer.reset(CreateRemoteAnswer(offer));
2970 answer->set_type(JsepSessionDescription::kPrAnswer);
2971 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002972 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2973 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2974 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002975 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2976 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002977 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2978
2979 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002980 answer.reset(CreateRemoteAnswer(offer));
2981 answer->set_type(JsepSessionDescription::kPrAnswer);
2982 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002983 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2984 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2985 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002986 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2987 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002988 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2989
2990 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002991 answer.reset(CreateRemoteAnswer(offer));
2992 answer->set_type(JsepSessionDescription::kPrAnswer);
2993 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2994 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002995 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2996}
2997
Donald Curtisd4f769d2015-05-28 09:48:21 -07002998// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002999// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07003000TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3001 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3002
3003 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003004 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003005
3006 PeerConnectionInterface::RTCOfferAnswerOptions options;
3007 options.use_rtp_mux = true;
3008
3009 SessionDescriptionInterface* offer = CreateRemoteOffer();
3010 SetRemoteDescriptionWithoutError(offer);
3011
htaa2a49d92016-03-04 02:51:39 -08003012 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003013 SetLocalDescriptionWithoutError(answer);
3014
deadbeefcbecd352015-09-23 11:50:27 -07003015 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3016 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003017
deadbeefcbecd352015-09-23 11:50:27 -07003018 cricket::BaseChannel* voice_channel = session_->voice_channel();
3019 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003020
3021 // Checks if one of the transport channels contains a connection using a given
3022 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003023 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07003024 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07003025 session_->GetChannelTransportStats(voice_channel, &stats);
3026 for (auto& kv : stats.transport_stats) {
3027 for (auto& chan_stat : kv.second.channel_stats) {
3028 for (auto& conn_info : chan_stat.connection_infos) {
3029 if (conn_info.remote_candidate.address().port() == port) {
3030 return true;
3031 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003032 }
3033 }
3034 }
3035 return false;
3036 };
3037
3038 EXPECT_FALSE(connection_with_remote_port(5000));
3039 EXPECT_FALSE(connection_with_remote_port(5001));
3040 EXPECT_FALSE(connection_with_remote_port(6000));
3041
3042 // The way the *_WAIT checks work is they only wait if the condition fails,
3043 // which does not help in the case where state is not changing. This is
3044 // problematic in this test since we want to verify that adding a video
3045 // candidate does _not_ change state. So we interleave candidates and assume
3046 // that messages are executed in the order they were posted.
3047
3048 // First audio candidate.
3049 cricket::Candidate candidate0;
3050 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3051 candidate0.set_component(1);
3052 candidate0.set_protocol("udp");
3053 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3054 candidate0);
3055 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3056
3057 // Video candidate.
3058 cricket::Candidate candidate1;
3059 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3060 candidate1.set_component(1);
3061 candidate1.set_protocol("udp");
3062 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3063 candidate1);
3064 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3065
3066 // Second audio candidate.
3067 cricket::Candidate candidate2;
3068 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3069 candidate2.set_component(1);
3070 candidate2.set_protocol("udp");
3071 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3072 candidate2);
3073 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3074
3075 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3076 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3077
3078 // No need here for a _WAIT check since we are checking that state hasn't
3079 // changed: if this is false we would be doing waits for nothing and if this
3080 // is true then there will be no messages processed anyways.
3081 EXPECT_FALSE(connection_with_remote_port(6000));
3082}
3083
deadbeefcbecd352015-09-23 11:50:27 -07003084// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003085TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3086 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003087 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003088
3089 PeerConnectionInterface::RTCOfferAnswerOptions options;
3090 options.use_rtp_mux = true;
3091
3092 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003093 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003094
deadbeefcbecd352015-09-23 11:50:27 -07003095 EXPECT_NE(session_->voice_rtp_transport_channel(),
3096 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003097
deadbeefab9b2d12015-10-14 11:33:11 -07003098 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003099 SessionDescriptionInterface* answer =
3100 CreateRemoteAnswer(session_->local_description());
3101 SetRemoteDescriptionWithoutError(answer);
3102
deadbeefcbecd352015-09-23 11:50:27 -07003103 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3104 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003105}
3106
deadbeefcbecd352015-09-23 11:50:27 -07003107// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003108TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3109 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003110 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003111
Donald Curtis0e209b02015-03-24 09:29:54 -07003112 PeerConnectionInterface::RTCOfferAnswerOptions options;
3113 options.use_rtp_mux = true;
3114
3115 SessionDescriptionInterface* offer = CreateOffer(options);
3116 SetLocalDescriptionWithoutError(offer);
3117
deadbeefcbecd352015-09-23 11:50:27 -07003118 EXPECT_NE(session_->voice_rtp_transport_channel(),
3119 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003120
deadbeefab9b2d12015-10-14 11:33:11 -07003121 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003122
3123 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003124 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003125 CreateRemoteAnswer(session_->local_description()));
3126 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3127 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3128 JsepSessionDescription* modified_answer =
3129 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3130 modified_answer->Initialize(answer_copy, "1", "1");
3131 SetRemoteDescriptionWithoutError(modified_answer); //
3132
deadbeefcbecd352015-09-23 11:50:27 -07003133 EXPECT_NE(session_->voice_rtp_transport_channel(),
3134 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003135}
3136
3137// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3138TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3139 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003140 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003141
3142 PeerConnectionInterface::RTCOfferAnswerOptions options;
3143 options.use_rtp_mux = true;
3144
3145 SessionDescriptionInterface* offer = CreateOffer(options);
3146 SetLocalDescriptionWithoutError(offer);
3147
deadbeefcbecd352015-09-23 11:50:27 -07003148 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3149 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003150
deadbeefab9b2d12015-10-14 11:33:11 -07003151 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003152 SessionDescriptionInterface* answer =
3153 CreateRemoteAnswer(session_->local_description());
3154 SetRemoteDescriptionWithoutError(answer);
3155
deadbeefcbecd352015-09-23 11:50:27 -07003156 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3157 session_->video_rtp_transport_channel());
3158}
3159
3160// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3161// audio content in the answer.
3162TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3163 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003164 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003165
3166 PeerConnectionInterface::RTCOfferAnswerOptions options;
3167 options.use_rtp_mux = true;
3168
3169 SessionDescriptionInterface* offer = CreateOffer(options);
3170 SetLocalDescriptionWithoutError(offer);
3171
3172 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3173 session_->video_rtp_transport_channel());
3174
deadbeefab9b2d12015-10-14 11:33:11 -07003175 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003176 cricket::MediaSessionOptions recv_options;
3177 recv_options.recv_audio = false;
3178 recv_options.recv_video = true;
3179 SessionDescriptionInterface* answer =
3180 CreateRemoteAnswer(session_->local_description(), recv_options);
3181 SetRemoteDescriptionWithoutError(answer);
3182
deadbeefd59daf82015-10-14 15:02:44 -07003183 EXPECT_TRUE(nullptr == session_->voice_channel());
3184 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003185
deadbeefd59daf82015-10-14 15:02:44 -07003186 session_->Close();
3187 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3188 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3189 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3190 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003191}
3192
3193// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3194TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3195 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003196 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003197
Donald Curtis0e209b02015-03-24 09:29:54 -07003198 PeerConnectionInterface::RTCOfferAnswerOptions options;
3199 options.use_rtp_mux = true;
3200
3201 SessionDescriptionInterface* offer = CreateOffer(options);
3202 SetLocalDescriptionWithoutError(offer);
3203
deadbeefcbecd352015-09-23 11:50:27 -07003204 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3205 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003206
deadbeefab9b2d12015-10-14 11:33:11 -07003207 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003208
3209 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003210 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003211 CreateRemoteAnswer(session_->local_description()));
3212 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3213 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3214 JsepSessionDescription* modified_answer =
3215 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3216 modified_answer->Initialize(answer_copy, "1", "1");
3217 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003218
deadbeefcbecd352015-09-23 11:50:27 -07003219 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3220 session_->video_rtp_transport_channel());
3221}
3222
3223// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3224TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3225 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003226 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003227
3228 SessionDescriptionInterface* offer = CreateRemoteOffer();
3229 SetRemoteDescriptionWithoutError(offer);
3230
3231 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3232 session_->video_rtp_transport_channel());
3233
deadbeefab9b2d12015-10-14 11:33:11 -07003234 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003235 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003236 SetLocalDescriptionWithoutError(answer);
3237
3238 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3239 session_->video_rtp_transport_channel());
3240}
3241
3242// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3243TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3244 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003245 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003246
3247 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003248 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003249 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3250 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3251 JsepSessionDescription* modified_offer =
3252 new JsepSessionDescription(JsepSessionDescription::kOffer);
3253 modified_offer->Initialize(offer_copy, "1", "1");
3254
3255 // Expect an error when applying the remote description
3256 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3257 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003258}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003259
Peter Thatcher4eddf182015-04-30 10:55:59 -07003260// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003261TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3262 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003263 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003264
Donald Curtis0e209b02015-03-24 09:29:54 -07003265 PeerConnectionInterface::RTCOfferAnswerOptions options;
3266 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003267
Donald Curtis0e209b02015-03-24 09:29:54 -07003268 SessionDescriptionInterface* offer = CreateOffer(options);
3269 SetLocalDescriptionWithoutError(offer);
3270
deadbeefcbecd352015-09-23 11:50:27 -07003271 EXPECT_NE(session_->voice_rtp_transport_channel(),
3272 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003273
deadbeefab9b2d12015-10-14 11:33:11 -07003274 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003275 SessionDescriptionInterface* answer =
3276 CreateRemoteAnswer(session_->local_description());
3277 SetRemoteDescriptionWithoutError(answer);
3278
3279 // This should lead to an audio-only call but isn't implemented
3280 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003281 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3282 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003283}
3284
deadbeefcbecd352015-09-23 11:50:27 -07003285// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003286TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3287 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003288 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003289 PeerConnectionInterface::RTCOfferAnswerOptions options;
3290 options.use_rtp_mux = true;
3291
3292 SessionDescriptionInterface* offer = CreateOffer(options);
3293 SetLocalDescriptionWithoutError(offer);
3294
deadbeefcbecd352015-09-23 11:50:27 -07003295 EXPECT_NE(session_->voice_rtp_transport_channel(),
3296 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003297
deadbeefab9b2d12015-10-14 11:33:11 -07003298 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003299
3300 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003301 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003302 CreateRemoteAnswer(session_->local_description()));
3303 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3304 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3305 JsepSessionDescription* modified_answer =
3306 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3307 modified_answer->Initialize(answer_copy, "1", "1");
3308 SetRemoteDescriptionWithoutError(modified_answer); //
3309
deadbeefcbecd352015-09-23 11:50:27 -07003310 EXPECT_NE(session_->voice_rtp_transport_channel(),
3311 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003312}
3313
Peter Thatcher4eddf182015-04-30 10:55:59 -07003314// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3315TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3316 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003317 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003318
3319 PeerConnectionInterface::RTCOfferAnswerOptions options;
3320 options.use_rtp_mux = true;
3321
3322 SessionDescriptionInterface* offer = CreateOffer(options);
3323 SetRemoteDescriptionWithoutError(offer);
3324
deadbeefcbecd352015-09-23 11:50:27 -07003325 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3326 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003327}
3328
skvlad6c87a672016-05-17 17:49:52 -07003329// Adding a new channel to a BUNDLE which is already connected should directly
3330// assign the bundle transport to the channel, without first setting a
3331// disconnected non-bundle transport and then replacing it. The application
3332// should not receive any changes in the ICE state.
3333TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3334 LoopbackNetworkConfiguration config;
3335 LoopbackNetworkManager loopback_network_manager(this, config);
3336 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3337 // connected. Disabling either of these two means that we need to wait for the
3338 // answer to find out if more transports are needed.
3339 configuration_.bundle_policy =
3340 PeerConnectionInterface::kBundlePolicyMaxBundle;
3341 configuration_.rtcp_mux_policy =
3342 PeerConnectionInterface::kRtcpMuxPolicyRequire;
3343 options_.disable_encryption = true;
3344 Init();
3345
3346 // Negotiate an audio channel with MAX_BUNDLE enabled.
3347 SendAudioOnlyStream2();
3348 SessionDescriptionInterface* offer = CreateOffer();
3349 SetLocalDescriptionWithoutError(offer);
3350 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3351 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3352 std::string sdp;
3353 offer->ToString(&sdp);
3354 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3355 JsepSessionDescription::kAnswer, sdp, nullptr);
3356 ASSERT_TRUE(answer != NULL);
3357 SetRemoteDescriptionWithoutError(answer);
3358
3359 // Wait for the ICE state to stabilize.
3360 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3361 observer_.ice_connection_state_, kIceCandidatesTimeout);
3362 observer_.ice_connection_state_history_.clear();
3363
3364 // Now add a video channel which should be using the same bundle transport.
3365 SendAudioVideoStream2();
3366 offer = CreateOffer();
3367 offer->ToString(&sdp);
3368 SetLocalDescriptionWithoutError(offer);
3369 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3370 sdp, nullptr);
3371 ASSERT_TRUE(answer != NULL);
3372 SetRemoteDescriptionWithoutError(answer);
3373
3374 // Wait for ICE state to stabilize
3375 rtc::Thread::Current()->ProcessMessages(0);
3376 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3377 observer_.ice_connection_state_, kIceCandidatesTimeout);
3378
3379 // No ICE state changes are expected to happen.
3380 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3381}
3382
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003383TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3384 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003385 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003386
3387 PeerConnectionInterface::RTCOfferAnswerOptions options;
3388 SessionDescriptionInterface* offer = CreateOffer(options);
3389 SetLocalDescriptionWithoutError(offer);
3390
deadbeefcbecd352015-09-23 11:50:27 -07003391 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3392 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003393
deadbeefab9b2d12015-10-14 11:33:11 -07003394 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003395 SessionDescriptionInterface* answer =
3396 CreateRemoteAnswer(session_->local_description());
3397 SetRemoteDescriptionWithoutError(answer);
3398
deadbeefcbecd352015-09-23 11:50:27 -07003399 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3400 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003401}
3402
3403TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3404 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003405 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003406
3407 PeerConnectionInterface::RTCOfferAnswerOptions options;
3408 SessionDescriptionInterface* offer = CreateOffer(options);
3409 SetLocalDescriptionWithoutError(offer);
3410
deadbeefcbecd352015-09-23 11:50:27 -07003411 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3412 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003413
deadbeefab9b2d12015-10-14 11:33:11 -07003414 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003415 SessionDescriptionInterface* answer =
3416 CreateRemoteAnswer(session_->local_description());
3417 SetRemoteDescriptionWithoutError(answer);
3418
deadbeefcbecd352015-09-23 11:50:27 -07003419 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3420 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003421}
3422
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003423// This test verifies that SetLocalDescription and SetRemoteDescription fails
3424// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3425TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003426 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003427 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003428
3429 PeerConnectionInterface::RTCOfferAnswerOptions options;
3430 options.use_rtp_mux = true;
3431
3432 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003433 std::string offer_str;
3434 offer->ToString(&offer_str);
3435 // Disable rtcp-mux
3436 const std::string rtcp_mux = "rtcp-mux";
3437 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003438 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003439 xrtcp_mux.c_str(), xrtcp_mux.length(),
3440 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003441 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003442 new JsepSessionDescription(JsepSessionDescription::kOffer);
3443 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003444 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003445 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003446 new JsepSessionDescription(JsepSessionDescription::kOffer);
3447 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003448 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003449 // Trying unmodified SDP.
3450 SetLocalDescriptionWithoutError(offer);
3451}
3452
jbauchcb560652016-08-04 05:20:32 -07003453TEST_F(WebRtcSessionTest, SetSetupGcm) {
3454 InitWithGcm();
3455 SendAudioVideoStream1();
3456 CreateAndSetRemoteOfferAndLocalAnswer();
3457}
3458
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3460 TestCanInsertDtmf(false);
3461}
3462
3463TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3464 TestCanInsertDtmf(true);
3465}
3466
3467TEST_F(WebRtcSessionTest, InsertDtmf) {
3468 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003469 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003470 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003471 CreateAndSetRemoteOfferAndLocalAnswer();
3472 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3473 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3474
3475 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476 const int expected_duration = 90;
3477 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3478 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3479 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3480
3481 // Verify
3482 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003483 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003484 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003485 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003486 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003487 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003488 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003489 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490}
3491
deadbeefd59daf82015-10-14 15:02:44 -07003492// This test verifies the |initial_offerer| flag when session initiates the
3493// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003494TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003495 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003496 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003497 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003498 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3499 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003500 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003502 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003503}
3504
deadbeefd59daf82015-10-14 15:02:44 -07003505// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003506TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003507 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003508 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003509 SessionDescriptionInterface* offer = CreateRemoteOffer();
3510 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003511 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003512
deadbeefd59daf82015-10-14 15:02:44 -07003513 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003514 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003515 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003516}
3517
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003518// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3519TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003520 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003521 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003522 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003523 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003524 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003525 CreateRemoteAnswer(session_->local_description()));
3526
3527 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3528 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003529 JsepSessionDescription* modified_answer =
3530 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003531
3532 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3533 answer->session_id(),
3534 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003535 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003536
wu@webrtc.org4e393072014-04-07 17:04:35 +00003537 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003538 std::string sdp;
3539 EXPECT_TRUE(answer->ToString(&sdp));
3540 const std::string kAudioMid = "a=mid:audio";
3541 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003542 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003543 kAudioMidReplaceStr.c_str(),
3544 kAudioMidReplaceStr.length(),
3545 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003546 SessionDescriptionInterface* modified_answer1 =
3547 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003548 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003549
wu@webrtc.org4e393072014-04-07 17:04:35 +00003550 // Different media types.
3551 EXPECT_TRUE(answer->ToString(&sdp));
3552 const std::string kAudioMline = "m=audio";
3553 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003554 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003555 kAudioMlineReplaceStr.c_str(),
3556 kAudioMlineReplaceStr.length(),
3557 &sdp);
3558 SessionDescriptionInterface* modified_answer2 =
3559 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3560 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3561
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003562 SetRemoteDescriptionWithoutError(answer.release());
3563}
3564
3565// Verifying remote offer and local answer have matching m-lines as per
3566// RFC 3264.
3567TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003568 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003569 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003570 SessionDescriptionInterface* offer = CreateRemoteOffer();
3571 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003572 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003573
3574 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3575 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003576 JsepSessionDescription* modified_answer =
3577 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003578
3579 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3580 answer->session_id(),
3581 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003582 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003583 SetLocalDescriptionWithoutError(answer);
3584}
3585
3586// This test verifies that WebRtcSession does not start candidate allocation
3587// before SetLocalDescription is called.
3588TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003589 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003590 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003591 SessionDescriptionInterface* offer = CreateRemoteOffer();
3592 cricket::Candidate candidate;
3593 candidate.set_component(1);
3594 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3595 candidate);
3596 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3597 cricket::Candidate candidate1;
3598 candidate1.set_component(1);
3599 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3600 candidate1);
3601 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3602 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003603 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3604 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003605
3606 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003607 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003608 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3609 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3610
htaa2a49d92016-03-04 02:51:39 -08003611 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003612 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003613 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3614}
3615
3616// This test verifies that crypto parameter is updated in local session
3617// description as per security policy set in MediaSessionDescriptionFactory.
3618TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003619 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003620 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003621 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003622
3623 // Making sure SetLocalDescription correctly sets crypto value in
3624 // SessionDescription object after de-serialization of sdp string. The value
3625 // will be set as per MediaSessionDescriptionFactory.
3626 std::string offer_str;
3627 offer->ToString(&offer_str);
3628 SessionDescriptionInterface* jsep_offer_str =
3629 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3630 SetLocalDescriptionWithoutError(jsep_offer_str);
3631 EXPECT_TRUE(session_->voice_channel()->secure_required());
3632 EXPECT_TRUE(session_->video_channel()->secure_required());
3633}
3634
3635// This test verifies the crypto parameter when security is disabled.
3636TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003637 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003638 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003639 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003640 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003641
3642 // Making sure SetLocalDescription correctly sets crypto value in
3643 // SessionDescription object after de-serialization of sdp string. The value
3644 // will be set as per MediaSessionDescriptionFactory.
3645 std::string offer_str;
3646 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003647 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003648 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3649 SetLocalDescriptionWithoutError(jsep_offer_str);
3650 EXPECT_FALSE(session_->voice_channel()->secure_required());
3651 EXPECT_FALSE(session_->video_channel()->secure_required());
3652}
3653
3654// This test verifies that an answer contains new ufrag and password if an offer
3655// with new ufrag and password is received.
3656TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003657 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003658 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003659 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003660 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003661 SetRemoteDescriptionWithoutError(offer.release());
3662
deadbeefab9b2d12015-10-14 11:33:11 -07003663 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003664 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003665 SetLocalDescriptionWithoutError(answer.release());
3666
3667 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003668 for (const cricket::ContentInfo& content :
3669 session_->local_description()->description()->contents()) {
3670 options.transport_options[content.name].ice_restart = true;
3671 }
kwibergd1fe2812016-04-27 06:47:29 -07003672 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003673 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003674 SetRemoteDescriptionWithoutError(updated_offer1.release());
3675
kwibergd1fe2812016-04-27 06:47:29 -07003676 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003677
deadbeef0ed85b22016-02-23 17:24:52 -08003678 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3679 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003680
deadbeef0ed85b22016-02-23 17:24:52 -08003681 // Even a second answer (created before the description is set) should have
3682 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003683 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003684
3685 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3686 session_->local_description()->description()));
3687
3688 SetLocalDescriptionWithoutError(updated_answer2.release());
3689}
3690
3691// This test verifies that an answer contains new ufrag and password if an offer
3692// that changes either the ufrag or password (but not both) is received.
3693// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3694// a=ice-pwd attributes compared to the previous SDP from the peer, it
3695// indicates that ICE is restarting for this media stream."
3696TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3697 Init();
3698 cricket::MediaSessionOptions options;
3699 options.recv_audio = true;
3700 options.recv_video = true;
3701 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003702 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003703 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3704 SetRemoteDescriptionWithoutError(offer.release());
3705
3706 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003707 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003708 SetLocalDescriptionWithoutError(answer.release());
3709
3710 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003711 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003712 CreateRemoteOffer(options, session_->remote_description()));
3713 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3714 "original_password12345");
3715 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3716
kwibergd1fe2812016-04-27 06:47:29 -07003717 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003718 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3719 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003720 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003721
3722 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003723 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003724 CreateRemoteOffer(options, session_->remote_description()));
3725 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3726 "modified_password12345");
3727 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3728
kwibergd1fe2812016-04-27 06:47:29 -07003729 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003730 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3731 session_->local_description()->description()));
3732 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003733}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003734
wu@webrtc.org91053e72013-08-10 07:18:04 +00003735// This test verifies that an answer contains old ufrag and password if an offer
3736// with old ufrag and password is received.
3737TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003738 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003739 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003740 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003741 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003742 SetRemoteDescriptionWithoutError(offer.release());
3743
deadbeefab9b2d12015-10-14 11:33:11 -07003744 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003745 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003746 SetLocalDescriptionWithoutError(answer.release());
3747
3748 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003749 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003750 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003751 SetRemoteDescriptionWithoutError(updated_offer2.release());
3752
kwibergd1fe2812016-04-27 06:47:29 -07003753 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003754
deadbeef0ed85b22016-02-23 17:24:52 -08003755 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3756 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003757
3758 SetLocalDescriptionWithoutError(updated_answer2.release());
3759}
3760
deadbeef0ed85b22016-02-23 17:24:52 -08003761// This test verifies that if an offer does an ICE restart on some, but not all
3762// media sections, the answer will change the ufrag/password in the correct
3763// media sections.
3764TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3765 Init();
3766 cricket::MediaSessionOptions options;
3767 options.recv_video = true;
3768 options.recv_audio = true;
3769 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003770 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003771
3772 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3773 "aaaaaaaaaaaaaaaaaaaaaa");
3774 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3775 "bbbbbbbbbbbbbbbbbbbbbb");
3776 SetRemoteDescriptionWithoutError(offer.release());
3777
3778 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003779 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003780 SetLocalDescriptionWithoutError(answer.release());
3781
3782 // Receive an offer with new ufrag and password, but only for the video media
3783 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003784 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003785 CreateRemoteOffer(options, session_->remote_description()));
3786 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3787 "cccccccccccccccccccccc");
3788 SetRemoteDescriptionWithoutError(updated_offer.release());
3789
kwibergd1fe2812016-04-27 06:47:29 -07003790 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003791
3792 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3793 session_->local_description()->description(),
3794 cricket::MEDIA_TYPE_AUDIO));
3795
3796 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3797 session_->local_description()->description(),
3798 cricket::MEDIA_TYPE_VIDEO));
3799
3800 SetLocalDescriptionWithoutError(updated_answer.release());
3801}
3802
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003803TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003804 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003805 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003806 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003807 const std::string session_id_orig = offer->session_id();
3808 const std::string session_version_orig = offer->session_version();
3809 SetLocalDescriptionWithoutError(offer);
3810
3811 video_channel_ = media_engine_->GetVideoChannel(0);
3812 video_channel_->set_fail_set_send_codecs(true);
3813
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003814 SessionDescriptionInterface* answer =
3815 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003816 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003817
3818 // Test that after a content error, setting any description will
3819 // result in an error.
3820 video_channel_->set_fail_set_send_codecs(false);
3821 answer = CreateRemoteAnswer(session_->local_description());
3822 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3823 offer = CreateRemoteOffer();
3824 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003825}
3826
3827// Runs the loopback call test with BUNDLE and STUN disabled.
3828TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3829 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003830 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003831 cricket::PORTALLOCATOR_DISABLE_STUN |
3832 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003833 TestLoopbackCall();
3834}
3835
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003836TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003837 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003838 cricket::PORTALLOCATOR_DISABLE_STUN |
3839 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3840 cricket::PORTALLOCATOR_DISABLE_RELAY);
3841
3842 // best connection is IPv6 since it has higher network preference.
3843 LoopbackNetworkConfiguration config;
3844 config.test_ipv6_network_ = true;
3845 config.best_connection_after_initial_ice_converged_ =
3846 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3847
3848 TestLoopbackCall(config);
3849}
3850
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003851// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003852TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003853 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3854 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003855 TestLoopbackCall();
3856}
3857
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003858TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003859 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003860 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003861 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003862 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003863 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3864}
3865
Henrik Boström87713d02015-08-25 09:53:21 +02003866TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003867 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003868
htaa2a49d92016-03-04 02:51:39 -08003869 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003870 options_.disable_sctp_data_channels = false;
3871
Henrik Boström87713d02015-08-25 09:53:21 +02003872 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003873
3874 SetLocalDescriptionWithDataChannel();
3875 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3876}
3877
Henrik Boström87713d02015-08-25 09:53:21 +02003878TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003879 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003880
Henrik Boström87713d02015-08-25 09:53:21 +02003881 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003882
kwibergd1fe2812016-04-27 06:47:29 -07003883 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003884 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003885 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3886}
3887
Henrik Boström87713d02015-08-25 09:53:21 +02003888TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003889 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003890 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003891 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003892
3893 // Create remote offer with SCTP.
3894 cricket::MediaSessionOptions options;
3895 options.data_channel_type = cricket::DCT_SCTP;
3896 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003897 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003898 SetRemoteDescriptionWithoutError(offer);
3899
3900 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003901 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003902 EXPECT_TRUE(answer != NULL);
3903 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3904 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003905}
3906
Henrik Boström87713d02015-08-25 09:53:21 +02003907TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003908 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003909 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003910
3911 SetLocalDescriptionWithDataChannel();
3912 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3913}
3914
Henrik Boström87713d02015-08-25 09:53:21 +02003915TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003916 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003917
Henrik Boström87713d02015-08-25 09:53:21 +02003918 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003919
3920 SetLocalDescriptionWithDataChannel();
3921 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3922}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003923
Henrik Boström87713d02015-08-25 09:53:21 +02003924TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003925 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003926 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003927 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003928
3929 SetLocalDescriptionWithDataChannel();
3930 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3931}
3932
Henrik Boström87713d02015-08-25 09:53:21 +02003933TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003934 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003935 const int new_send_port = 9998;
3936 const int new_recv_port = 7775;
3937
Henrik Boström87713d02015-08-25 09:53:21 +02003938 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003939 SetFactoryDtlsSrtp();
3940
3941 // By default, don't actually add the codecs to desc_factory_; they don't
3942 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3943 // let the session description get parsed. That'll get the proper codecs
3944 // into the stream.
3945 cricket::MediaSessionOptions options;
3946 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3947 "stream1", new_send_port, options);
3948
3949 // SetRemoteDescription will take the ownership of the offer.
3950 SetRemoteDescriptionWithoutError(offer);
3951
htaa2a49d92016-03-04 02:51:39 -08003952 SessionDescriptionInterface* answer =
3953 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003954 ASSERT_TRUE(answer != NULL);
3955
3956 // Now set the local description, which'll take ownership of the answer.
3957 SetLocalDescriptionWithoutError(answer);
3958
3959 // TEST PLAN: Set the port number to something new, set it in the SDP,
3960 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003961 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003962 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003963
3964 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3965 int portnum = -1;
3966 ASSERT_TRUE(ch != NULL);
3967 ASSERT_EQ(1UL, ch->send_codecs().size());
3968 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003969 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003970 ch->send_codecs()[0].name.c_str()));
3971 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3972 &portnum));
3973 EXPECT_EQ(new_send_port, portnum);
3974
3975 ASSERT_EQ(1UL, ch->recv_codecs().size());
3976 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003977 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003978 ch->recv_codecs()[0].name.c_str()));
3979 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3980 &portnum));
3981 EXPECT_EQ(new_recv_port, portnum);
3982}
3983
deadbeefab9b2d12015-10-14 11:33:11 -07003984// Verifies that when a session's DataChannel receives an OPEN message,
3985// WebRtcSession signals the DataChannel creation request with the expected
3986// config.
3987TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3988 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3989
3990 InitWithDtls(GetParam());
3991
3992 SetLocalDescriptionWithDataChannel();
3993 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3994
3995 webrtc::DataChannelInit config;
3996 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07003997 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07003998 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3999 cricket::ReceiveDataParams params;
4000 params.ssrc = config.id;
4001 params.type = cricket::DMT_CONTROL;
4002
4003 cricket::DataChannel* data_channel = session_->data_channel();
4004 data_channel->SignalDataReceived(data_channel, params, payload);
4005
4006 EXPECT_EQ("a", last_data_channel_label_);
4007 EXPECT_EQ(config.id, last_data_channel_config_.id);
4008 EXPECT_FALSE(last_data_channel_config_.negotiated);
4009 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4010 last_data_channel_config_.open_handshake_role);
4011}
4012
4013TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004014 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004015 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004016
htaa2a49d92016-03-04 02:51:39 -08004017 configuration_.certificates.push_back(certificate);
4018 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004019 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4020
4021 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4022}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004023
Henrik Boström87713d02015-08-25 09:53:21 +02004024// Verifies that CreateOffer succeeds when CreateOffer is called before async
4025// identity generation is finished (even if a certificate is provided this is
4026// an async op).
4027TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4028 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4029 InitWithDtls(GetParam());
4030
Henrik Boströmd8281982015-08-27 10:12:24 +02004031 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004032 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004033 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004034
wu@webrtc.org91053e72013-08-10 07:18:04 +00004035 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004036 VerifyNoCryptoParams(offer->description(), true);
4037 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004038}
4039
4040// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004041// identity generation is finished (even if a certificate is provided this is
4042// an async op).
4043TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004044 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004045 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004046 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004047
4048 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004049 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004050 std::unique_ptr<JsepSessionDescription> offer(
4051 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004052 ASSERT_TRUE(offer.get() != NULL);
4053 SetRemoteDescriptionWithoutError(offer.release());
4054
kwibergd1fe2812016-04-27 06:47:29 -07004055 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004056 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004057 VerifyNoCryptoParams(answer->description(), true);
4058 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004059}
4060
4061// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004062// identity generation is finished (even if a certificate is provided this is
4063// an async op).
4064TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004065 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004066 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004067
Henrik Boströmd8281982015-08-27 10:12:24 +02004068 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004069
kwibergd1fe2812016-04-27 06:47:29 -07004070 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004071 EXPECT_TRUE(offer != NULL);
4072}
4073
4074// Verifies that CreateOffer fails when CreateOffer is called after async
4075// identity generation fails.
4076TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004077 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004078 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004079
Henrik Boströmd8281982015-08-27 10:12:24 +02004080 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004081
kwibergd1fe2812016-04-27 06:47:29 -07004082 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004083 EXPECT_TRUE(offer == NULL);
4084}
4085
4086// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4087// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004088TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004089 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004090 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004091 VerifyMultipleAsyncCreateDescription(GetParam(),
4092 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004093}
4094
4095// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4096// before async identity generation fails.
4097TEST_F(WebRtcSessionTest,
4098 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004099 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004100 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4101 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004102}
4103
4104// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4105// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004106TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004107 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004108 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004109 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004110 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004111}
4112
4113// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4114// before async identity generation fails.
4115TEST_F(WebRtcSessionTest,
4116 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004117 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004118 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4119 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004120}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004121
4122// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4123// offer has no SDES crypto but only DTLS fingerprint.
4124TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4125 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004126 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004127 // Create a remote offer with secured transport disabled.
4128 cricket::MediaSessionOptions options;
4129 JsepSessionDescription* offer(CreateRemoteOffer(
4130 options, cricket::SEC_DISABLED));
4131 // Adds a DTLS fingerprint to the remote offer.
4132 cricket::SessionDescription* sdp = offer->description();
4133 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4134 ASSERT_TRUE(audio != NULL);
4135 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4136 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004137 rtc::SSLFingerprint::CreateFromRfc4572(
4138 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004139 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004140 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004141}
4142
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004143TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004144 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004145 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004146 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004147 SessionDescriptionInterface* offer = CreateOffer();
4148
4149 SetLocalDescriptionWithoutError(offer);
4150
4151 voice_channel_ = media_engine_->GetVoiceChannel(0);
4152
4153 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004154 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004155 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004156}
4157
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004158// Tests that we can renegotiate new media content with ICE candidates in the
4159// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004160TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004161 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004162 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004163 SetFactoryDtlsSrtp();
4164
deadbeefab9b2d12015-10-14 11:33:11 -07004165 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004166 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004167 SetLocalDescriptionWithoutError(offer);
4168
4169 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4170 SetRemoteDescriptionWithoutError(answer);
4171
4172 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004173 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004174 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4175
4176 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004177 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004178 candidate1.set_component(1);
4179 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4180 candidate1);
4181 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4182 SetRemoteDescriptionWithoutError(offer);
4183
htaa2a49d92016-03-04 02:51:39 -08004184 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004185 SetLocalDescriptionWithoutError(answer);
4186}
4187
4188// Tests that we can renegotiate new media content with ICE candidates separated
4189// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004190TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004191 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004192 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004193 SetFactoryDtlsSrtp();
4194
deadbeefab9b2d12015-10-14 11:33:11 -07004195 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004196 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004197 SetLocalDescriptionWithoutError(offer);
4198
4199 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4200 SetRemoteDescriptionWithoutError(answer);
4201
4202 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004203 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004204 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4205 SetRemoteDescriptionWithoutError(offer);
4206
4207 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004208 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004209 candidate1.set_component(1);
4210 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4211 candidate1);
4212 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4213
htaa2a49d92016-03-04 02:51:39 -08004214 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004215 SetLocalDescriptionWithoutError(answer);
4216}
honghaiz7f777492016-02-02 21:54:01 -08004217
zhihuang9763d562016-08-05 11:14:50 -07004218#ifdef HAVE_QUIC
4219TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4220 configuration_.enable_quic = true;
4221 InitWithDtls(GetParam());
4222 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4223 SessionDescriptionInterface* offer = CreateOffer();
4224 ASSERT_TRUE(offer);
4225 ASSERT_TRUE(offer->description());
4226 SetLocalDescriptionWithoutError(offer);
4227 cricket::MediaSessionOptions options;
4228 options.recv_audio = true;
4229 options.recv_video = true;
4230 SessionDescriptionInterface* answer =
4231 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4232 ASSERT_TRUE(answer);
4233 ASSERT_TRUE(answer->description());
4234 SetRemoteDescriptionWithoutError(answer);
4235}
4236#endif // HAVE_QUIC
4237
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004238// Tests that RTX codec is removed from the answer when it isn't supported
4239// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004240TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004241 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004242 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004243 std::string offer_sdp(kSdpWithRtx);
4244
4245 SessionDescriptionInterface* offer =
4246 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4247 EXPECT_TRUE(offer->ToString(&offer_sdp));
4248
4249 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004250 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004251 SetRemoteDescriptionWithoutError(offer);
4252
htaa2a49d92016-03-04 02:51:39 -08004253 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004254 // Answer SDP does not contain the RTX codec.
4255 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004256 SetLocalDescriptionWithoutError(answer);
4257}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004258
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004259// This verifies that the voice channel after bundle has both options from video
4260// and voice channels.
4261TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4262 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004263 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004264
4265 PeerConnectionInterface::RTCOfferAnswerOptions options;
4266 options.use_rtp_mux = true;
4267
4268 SessionDescriptionInterface* offer = CreateOffer(options);
4269 SetLocalDescriptionWithoutError(offer);
4270
4271 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4272 rtc::Socket::Option::OPT_SNDBUF, 4000);
4273
4274 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4275 rtc::Socket::Option::OPT_RCVBUF, 8000);
4276
4277 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004278 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004279 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4280 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004281 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004282 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4283
deadbeefcbecd352015-09-23 11:50:27 -07004284 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004285 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4286 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004287 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004288 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4289
deadbeefcbecd352015-09-23 11:50:27 -07004290 EXPECT_NE(session_->voice_rtp_transport_channel(),
4291 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004292
deadbeefab9b2d12015-10-14 11:33:11 -07004293 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004294 SessionDescriptionInterface* answer =
4295 CreateRemoteAnswer(session_->local_description());
4296 SetRemoteDescriptionWithoutError(answer);
4297
deadbeefcbecd352015-09-23 11:50:27 -07004298 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004299 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4300 EXPECT_EQ(4000, option_val);
4301
deadbeefcbecd352015-09-23 11:50:27 -07004302 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004303 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4304 EXPECT_EQ(8000, option_val);
4305}
4306
tommi0f620f42015-07-09 03:25:02 -07004307// Test creating a session, request multiple offers, destroy the session
4308// and make sure we got success/failure callbacks for all of the requests.
4309// Background: crbug.com/507307
4310TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4311 Init();
4312
4313 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4314 PeerConnectionInterface::RTCOfferAnswerOptions options;
4315 options.offer_to_receive_audio =
4316 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004317 cricket::MediaSessionOptions session_options;
4318 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004319
4320 for (auto& o : observers) {
4321 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004322 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004323 }
4324
4325 session_.reset();
4326
tommi0f620f42015-07-09 03:25:02 -07004327 for (auto& o : observers) {
4328 // We expect to have received a notification now even if the session was
4329 // terminated. The offer creation may or may not have succeeded, but we
4330 // must have received a notification which, so the only invalid state
4331 // is kInit.
4332 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4333 }
4334}
4335
stefanc1aeaf02015-10-15 07:26:07 -07004336TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4337 TestPacketOptions();
4338}
4339
deadbeef057ecf02016-01-20 14:30:43 -08004340// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4341// is destroyed.
4342TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4343 Init();
4344 session_.reset();
4345 EXPECT_TRUE(session_destroyed_);
4346}
4347
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004348// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4349// currently fails because upon disconnection and reconnection OnIceComplete is
4350// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004351
deadbeefcbecd352015-09-23 11:50:27 -07004352INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4353 WebRtcSessionTest,
4354 testing::Values(ALREADY_GENERATED,
4355 DTLS_IDENTITY_STORE));